From 698f3b1a02ba6b291af67c6df702dd999f7d3acf Mon Sep 17 00:00:00 2001 From: grngxd <36968271+grngxd@users.noreply.github.com> Date: Thu, 31 Jul 2025 22:46:34 +0100 Subject: [PATCH] revert commit & add meta/:id route --- api.md | 1 + internal/api/routes/files.go | 24 ++++++++++++++++++++++++ internal/auth/types.go | 14 ++++++-------- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/api.md b/api.md index 73114d7..a2a865e 100644 --- a/api.md +++ b/api.md @@ -9,4 +9,5 @@ | POST | /api/upload | Upload file | Upload key | | DELETE | /api/:id | Delete file | Upload key | | GET | /api/:id | Get file | Upload key | +| GET | /api/:id/meta | Get file metadata | None | | GET | /api/list | Get a list of uploaded files | Session key | diff --git a/internal/api/routes/files.go b/internal/api/routes/files.go index 3007193..a295936 100644 --- a/internal/api/routes/files.go +++ b/internal/api/routes/files.go @@ -176,6 +176,30 @@ func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) { c.DataFromReader(200, file.Size, file.Mime, object, nil) }) + api.GET("/meta/:id", func(c *gin.Context) { + fileID := c.Param("id") + fileID = strings.TrimSpace(fileID) + + var file *types.File + id, err := uuid.FromString(fileID) + if err != nil { + types.ErrorInvalidFile.Throw(c, err) + return + } + + if err := cfg.Database.First(&file, id).Error; err != nil { + types.ErrorFileNotFound.Throw(c, err) + return + } + + if file == nil { + types.ErrorFileNotFound.Throw(c, nil) + return + } + + c.JSON(200, file) + }) + api.GET("/list", session.SessionMiddleware(cfg.JWTSecret), func(c *gin.Context) { claims := c.MustGet("claims").(jwt.MapClaims) user := claims["user"].(auth.User) diff --git a/internal/auth/types.go b/internal/auth/types.go index ce06067..a36ac90 100644 --- a/internal/auth/types.go +++ b/internal/auth/types.go @@ -32,14 +32,12 @@ type TokenResponse struct { } type User struct { - ID string `json:"id" gorm:"primaryKey"` - Username string `json:"username"` - Blacklisted bool `json:"blacklisted"` - Email string `json:"email"` - CreatedAt time.Time `json:"created_at"` - HashedApiKey string `json:"hashed_api_key"` - Role string `json:"role" gorm:"default:'free'"` // free, pro, pro+, admin - SubscriptionExpiresAt time.Time `json:"subscription_expires_at"` + ID string `json:"id" gorm:"primaryKey"` + Username string `json:"username"` + Blacklisted bool `json:"blacklisted"` + Email string `json:"email"` + CreatedAt time.Time `json:"created_at"` + HashedApiKey string `json:"hashed_api_key"` } type AvatarDecorationData struct {