2025-11-28 23:30:49 +08:00
|
|
|
|
package model
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"time"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// TextureType 材质类型
|
2025-12-26 01:15:17 +08:00
|
|
|
|
// @Description 材质类型枚举:SKIN(皮肤)或CAPE(披风)
|
2025-11-28 23:30:49 +08:00
|
|
|
|
type TextureType string
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
|
TextureTypeSkin TextureType = "SKIN"
|
|
|
|
|
|
TextureTypeCape TextureType = "CAPE"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Texture 材质模型
|
2025-12-26 01:15:17 +08:00
|
|
|
|
// @Description Minecraft材质数据模型
|
2025-11-28 23:30:49 +08:00
|
|
|
|
type Texture struct {
|
|
|
|
|
|
ID int64 `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
2025-12-02 10:33:19 +08:00
|
|
|
|
UploaderID int64 `gorm:"column:uploader_id;not null;index:idx_textures_uploader_status,priority:1;index:idx_textures_uploader_created,priority:1" json:"uploader_id"`
|
2025-11-28 23:30:49 +08:00
|
|
|
|
Name string `gorm:"column:name;type:varchar(100);not null;default:''" json:"name"`
|
|
|
|
|
|
Description string `gorm:"column:description;type:text" json:"description,omitempty"`
|
2025-12-02 10:33:19 +08:00
|
|
|
|
Type TextureType `gorm:"column:type;type:varchar(50);not null;index:idx_textures_public_type_status,priority:2" json:"type"` // SKIN, CAPE
|
2025-11-28 23:30:49 +08:00
|
|
|
|
URL string `gorm:"column:url;type:varchar(255);not null" json:"url"`
|
2025-12-04 20:07:30 +08:00
|
|
|
|
Hash string `gorm:"column:hash;type:varchar(64);not null;index:idx_textures_hash" json:"hash"` // SHA-256
|
2025-11-28 23:30:49 +08:00
|
|
|
|
Size int `gorm:"column:size;type:integer;not null;default:0" json:"size"`
|
2025-12-02 10:33:19 +08:00
|
|
|
|
IsPublic bool `gorm:"column:is_public;not null;default:false;index:idx_textures_public_type_status,priority:1" json:"is_public"`
|
2025-11-28 23:30:49 +08:00
|
|
|
|
DownloadCount int `gorm:"column:download_count;type:integer;not null;default:0;index:idx_textures_download_count,sort:desc" json:"download_count"`
|
|
|
|
|
|
FavoriteCount int `gorm:"column:favorite_count;type:integer;not null;default:0;index:idx_textures_favorite_count,sort:desc" json:"favorite_count"`
|
2025-12-04 20:07:30 +08:00
|
|
|
|
IsSlim bool `gorm:"column:is_slim;not null;default:false" json:"is_slim"` // Alex(细) or Steve(粗)
|
2025-12-02 10:33:19 +08:00
|
|
|
|
Status int16 `gorm:"column:status;type:smallint;not null;default:1;index:idx_textures_public_type_status,priority:3;index:idx_textures_uploader_status,priority:2" json:"status"` // 1:正常, 0:审核中, -1:已删除
|
|
|
|
|
|
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;not null;default:CURRENT_TIMESTAMP;index:idx_textures_uploader_created,priority:2,sort:desc;index:idx_textures_created_at,sort:desc" json:"created_at"`
|
2025-11-28 23:30:49 +08:00
|
|
|
|
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;not null;default:CURRENT_TIMESTAMP" json:"updated_at"`
|
2025-12-02 10:33:19 +08:00
|
|
|
|
|
2025-11-28 23:30:49 +08:00
|
|
|
|
// 关联
|
2025-12-02 10:33:19 +08:00
|
|
|
|
Uploader *User `gorm:"foreignKey:UploaderID;constraint:OnDelete:CASCADE" json:"uploader,omitempty"`
|
2025-11-28 23:30:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TableName 指定表名
|
|
|
|
|
|
func (Texture) TableName() string {
|
|
|
|
|
|
return "textures"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// UserTextureFavorite 用户材质收藏
|
2025-12-26 01:15:17 +08:00
|
|
|
|
// @Description 用户收藏材质关联表
|
2025-11-28 23:30:49 +08:00
|
|
|
|
type UserTextureFavorite struct {
|
|
|
|
|
|
ID int64 `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
2025-12-02 10:33:19 +08:00
|
|
|
|
UserID int64 `gorm:"column:user_id;not null;uniqueIndex:uk_user_texture,priority:1;index:idx_favorites_user_created,priority:1" json:"user_id"`
|
|
|
|
|
|
TextureID int64 `gorm:"column:texture_id;not null;uniqueIndex:uk_user_texture,priority:2;index:idx_favorites_texture_id" json:"texture_id"`
|
|
|
|
|
|
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;not null;default:CURRENT_TIMESTAMP;index:idx_favorites_user_created,priority:2,sort:desc;index:idx_favorites_created_at,sort:desc" json:"created_at"`
|
|
|
|
|
|
|
2025-11-28 23:30:49 +08:00
|
|
|
|
// 关联
|
2025-12-02 10:33:19 +08:00
|
|
|
|
User *User `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE" json:"user,omitempty"`
|
|
|
|
|
|
Texture *Texture `gorm:"foreignKey:TextureID;constraint:OnDelete:CASCADE" json:"texture,omitempty"`
|
2025-11-28 23:30:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TableName 指定表名
|
|
|
|
|
|
func (UserTextureFavorite) TableName() string {
|
|
|
|
|
|
return "user_texture_favorites"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TextureDownloadLog 材质下载记录
|
2025-12-26 01:15:17 +08:00
|
|
|
|
// @Description 材质下载日志记录
|
2025-11-28 23:30:49 +08:00
|
|
|
|
type TextureDownloadLog struct {
|
|
|
|
|
|
ID int64 `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
2025-12-02 10:33:19 +08:00
|
|
|
|
TextureID int64 `gorm:"column:texture_id;not null;index:idx_download_logs_texture_created,priority:1" json:"texture_id"`
|
|
|
|
|
|
UserID *int64 `gorm:"column:user_id;type:bigint;index:idx_download_logs_user_id" json:"user_id,omitempty"`
|
|
|
|
|
|
IPAddress string `gorm:"column:ip_address;type:inet;not null;index:idx_download_logs_ip" json:"ip_address"`
|
2025-11-28 23:30:49 +08:00
|
|
|
|
UserAgent string `gorm:"column:user_agent;type:text" json:"user_agent,omitempty"`
|
2025-12-02 10:33:19 +08:00
|
|
|
|
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;not null;default:CURRENT_TIMESTAMP;index:idx_download_logs_texture_created,priority:2,sort:desc;index:idx_download_logs_created_at,sort:desc" json:"created_at"`
|
|
|
|
|
|
|
2025-11-28 23:30:49 +08:00
|
|
|
|
// 关联
|
2025-12-02 10:33:19 +08:00
|
|
|
|
Texture *Texture `gorm:"foreignKey:TextureID;constraint:OnDelete:CASCADE" json:"texture,omitempty"`
|
|
|
|
|
|
User *User `gorm:"foreignKey:UserID;constraint:OnDelete:SET NULL" json:"user,omitempty"`
|
2025-11-28 23:30:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TableName 指定表名
|
|
|
|
|
|
func (TextureDownloadLog) TableName() string {
|
|
|
|
|
|
return "texture_download_logs"
|
|
|
|
|
|
}
|