logging out & fix state (?)
This commit is contained in:
parent
96320c3cc4
commit
b906736af8
2 changed files with 61 additions and 21 deletions
|
@ -1,18 +1,18 @@
|
|||
/*
|
||||
Copyright (C) 2025 hexlocation (hex@iwakura.rip) & grngxd (grng@iwakura.rip)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package routes
|
||||
|
@ -20,6 +20,7 @@ package routes
|
|||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -179,8 +180,38 @@ func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
|||
claims := c.MustGet("claims").(jwt.MapClaims)
|
||||
user := claims["user"].(auth.User)
|
||||
|
||||
if c.Query("page") == "" || c.Query("size") == "" {
|
||||
var files []types.File
|
||||
if err := cfg.Database.Where("owner = ?", user.ID).Find(&files).Error; err != nil {
|
||||
types.ErrorDatabase.Throw(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, files)
|
||||
return
|
||||
}
|
||||
|
||||
page := c.Query("page")
|
||||
size := c.Query("size")
|
||||
|
||||
pageNum, err := strconv.Atoi(page)
|
||||
if err != nil || pageNum < 0 {
|
||||
types.ErrorInvalidParams.Throw(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
sizeNum, err := strconv.Atoi(size)
|
||||
if err != nil || sizeNum <= 0 {
|
||||
types.ErrorInvalidParams.Throw(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
var files []types.File
|
||||
if err := cfg.Database.Where("owner = ?", user.ID).Find(&files).Error; err != nil {
|
||||
offset := (pageNum - 1) * sizeNum
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
if err := cfg.Database.Where("owner = ?", user.ID).Offset(offset).Limit(sizeNum).Find(&files).Error; err != nil {
|
||||
types.ErrorDatabase.Throw(c, err)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue