revert commit & add meta/:id route
This commit is contained in:
parent
b48a610e90
commit
698f3b1a02
3 changed files with 31 additions and 8 deletions
1
api.md
1
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 |
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -38,8 +38,6 @@ type User struct {
|
|||
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"`
|
||||
}
|
||||
|
||||
type AvatarDecorationData struct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue