Files
nl-pms-api/internal/model/file.go
2026-08-15 07:41:11 +08:00

26 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package model
// File 是一条已上传文件的元数据,对应 code_count 库的 pms_files 表;
// 文件内容落盘在 storage_dir本表只存相对路径与摘要。
// 每条记录独占一个磁盘文件name 唯一),删除记录时一并删文件;
// 归属按 (user_id, team_id) 记录,素材库据此做"本人/团队管理员/超管"的可见与管理范围。
// created_at 沿用 code_count 库的惯例存 RFC3339 字符串。
type File struct {
ID int64 `gorm:"primaryKey" json:"id"`
// Name 是存储相对路径(也是访问路径),如 2026/08/13/<128位随机hex>.jpg。
Name string `gorm:"size:191;uniqueIndex;not null" json:"name"`
Original string `gorm:"size:255;not null;default:''" json:"original"`
Mime string `gorm:"size:64;not null;default:''" json:"mime"`
Size int64 `gorm:"not null;default:0" json:"size"`
// SHA256 用于秒传去重同一归属user_id+team_id重复上传直接复用已有记录。
SHA256 string `gorm:"column:sha256;type:char(64);index;not null;default:''" json:"sha256"`
// UserID 是上传者在 code_count 库 users 表的 id0 表示未知。
UserID int64 `gorm:"not null;default:0;index" json:"userId"`
// TeamID 是上传时客户端的当前团队code_count 库 teams 表 id0 表示个人。
TeamID int64 `gorm:"not null;default:0;index" json:"teamId"`
Kind string `gorm:"size:16;not null;default:''" json:"kind"` // avatar | content
CreatedAt string `gorm:"size:32;not null;default:''" json:"createdAt"`
}
func (File) TableName() string { return "pms_files" }