package models import "time" // UploadCategory groups file types for the admin UI. const ( CategoryImage = "image" CategoryDocument = "document" CategoryArchive = "archive" CategoryVideo = "video" CategoryOther = "other" ) // DefaultUploadMaxSize is the default per-file size limit (10 MiB), in bytes. const DefaultUploadMaxSize int64 = 10 * 1024 * 1024 // UploadConfig holds the singleton (id=1) global attachment upload policy. type UploadConfig struct { ID uint `gorm:"primarykey" json:"id"` Enabled bool `gorm:"default:true" json:"enabled"` // master switch for attachment uploads DefaultMaxSize int64 `gorm:"default:10485760" json:"default_max_size"` // bytes; overridden per type by UploadFileType.MaxSize StorageDir string `gorm:"size:255;default:attachments" json:"storage_dir"` // sub-dir under cfg.Path UpdatedBy uint `gorm:"index" json:"updated_by"` UpdatedAt time.Time `json:"updated_at"` } // TableName overrides the default GORM table name. func (UploadConfig) TableName() string { return "upload_configs" } // UploadFileType describes one permitted attachment extension. Multiple rows. type UploadFileType struct { ID uint `gorm:"primarykey" json:"id"` Extension string `gorm:"size:32;uniqueIndex" json:"extension"` // with leading dot, e.g. ".pdf" MimeType string `gorm:"size:128" json:"mime_type"` // associated MIME for validation Category string `gorm:"size:32;index" json:"category"` // image/document/archive/video/other MaxSize int64 `gorm:"default:0" json:"max_size"` // bytes; 0 means use UploadConfig.DefaultMaxSize Enabled bool `gorm:"default:true" json:"enabled"` Sort int `gorm:"default:0" json:"sort"` } // TableName overrides the default GORM table name. func (UploadFileType) TableName() string { return "upload_file_types" } // EffectiveMaxSize returns the per-file size limit for this type, falling back // to the provided default when MaxSize is 0. func (t *UploadFileType) EffectiveMaxSize(def int64) int64 { if t.MaxSize > 0 { return t.MaxSize } return def } // DownloadBaseURL is one source base URL used to build attachment download // links. Multiple rows; the row marked IsDefault (or the highest-priority // enabled one) is used for generated links. type DownloadBaseURL struct { ID uint `gorm:"primarykey" json:"id"` Name string `gorm:"size:64" json:"name"` // label, e.g. "主站" / "CDN" BaseURL string `gorm:"size:512" json:"base_url"` // e.g. https://cdn.example.com/uploads Priority int `gorm:"default:0" json:"priority"` // lower = higher priority IsDefault bool `gorm:"default:false" json:"is_default"` Enabled bool `gorm:"default:true" json:"enabled"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } // TableName overrides the default GORM table name. func (DownloadBaseURL) TableName() string { return "download_baseurls" }