add name to file struct
This commit is contained in:
parent
3a6b24cb57
commit
09d8ffa82c
2 changed files with 3 additions and 2 deletions
|
@ -20,7 +20,6 @@ func intoReader(buf []byte) io.Reader {
|
||||||
return io.NopCloser(bytes.NewBuffer(buf))
|
return io.NopCloser(bytes.NewBuffer(buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
||||||
api.POST("/upload", auth.JwtMiddleware(cfg.JWTSecret), func(c *gin.Context) {
|
api.POST("/upload", auth.JwtMiddleware(cfg.JWTSecret), func(c *gin.Context) {
|
||||||
claims := c.MustGet("claims").(jwt.MapClaims)
|
claims := c.MustGet("claims").(jwt.MapClaims)
|
||||||
|
@ -67,6 +66,7 @@ func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
||||||
|
|
||||||
fileMeta := types.File{
|
fileMeta := types.File{
|
||||||
Owner: uid,
|
Owner: uid,
|
||||||
|
Name: file.Filename,
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
Size: int64(len(buf)),
|
Size: int64(len(buf)),
|
||||||
Mime: fileType.MIME.Value,
|
Mime: fileType.MIME.Value,
|
||||||
|
@ -85,7 +85,7 @@ func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(200, gin.H{"message": "file uploaded successfully", "name": fileMeta.ID.String()})
|
c.JSON(200, gin.H{"message": "file uploaded successfully", "id": fileMeta.ID.String()})
|
||||||
})
|
})
|
||||||
|
|
||||||
api.DELETE("/:id", auth.JwtMiddleware(cfg.JWTSecret), func(c *gin.Context) {
|
api.DELETE("/:id", auth.JwtMiddleware(cfg.JWTSecret), func(c *gin.Context) {
|
||||||
|
|
|
@ -32,6 +32,7 @@ type StereoConfig struct {
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
ID uuid.UUID `gorm:"type:uuid;primaryKey"`
|
ID uuid.UUID `gorm:"type:uuid;primaryKey"`
|
||||||
|
Name string `gorm:"not null;index"`
|
||||||
Owner string `gorm:"not null;index"`
|
Owner string `gorm:"not null;index"`
|
||||||
Size int64 `gorm:"not null;type:bigint"`
|
Size int64 `gorm:"not null;type:bigint"`
|
||||||
CreatedAt time.Time `gorm:"autoCreateTime"`
|
CreatedAt time.Time `gorm:"autoCreateTime"`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue