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 |
|
| POST | /api/upload | Upload file | Upload key |
|
||||||
| DELETE | /api/:id | Delete file | Upload key |
|
| DELETE | /api/:id | Delete file | Upload key |
|
||||||
| GET | /api/:id | Get 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 |
|
| 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)
|
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) {
|
api.GET("/list", session.SessionMiddleware(cfg.JWTSecret), func(c *gin.Context) {
|
||||||
claims := c.MustGet("claims").(jwt.MapClaims)
|
claims := c.MustGet("claims").(jwt.MapClaims)
|
||||||
user := claims["user"].(auth.User)
|
user := claims["user"].(auth.User)
|
||||||
|
|
|
@ -32,14 +32,12 @@ type TokenResponse struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ID string `json:"id" gorm:"primaryKey"`
|
ID string `json:"id" gorm:"primaryKey"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Blacklisted bool `json:"blacklisted"`
|
Blacklisted bool `json:"blacklisted"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
HashedApiKey string `json:"hashed_api_key"`
|
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 {
|
type AvatarDecorationData struct {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue