Files
nysoure/server/model/file.go
2025-07-05 20:40:48 +08:00

42 lines
911 B
Go

package model
import (
"gorm.io/gorm"
)
type File struct {
gorm.Model
UUID string `gorm:"uniqueIndex;not null"`
Filename string
Description string
StorageKey string
StorageID *uint `gorm:"default:null"`
Storage Storage
ResourceID uint
RedirectUrl string
Resource Resource `gorm:"foreignKey:ResourceID"`
UserID uint
User User `gorm:"foreignKey:UserID"`
Size int64
}
type FileView struct {
ID string `json:"id"`
Filename string `json:"filename"`
Description string `json:"description"`
Size int64 `json:"size"`
IsRedirect bool `json:"is_redirect"`
User UserView `json:"user"`
}
func (f *File) ToView() *FileView {
return &FileView{
ID: f.UUID,
Filename: f.Filename,
Description: f.Description,
Size: f.Size,
IsRedirect: f.RedirectUrl != "",
User: f.User.ToView(),
}
}