Files
EveryPublish/server/internal/models/models.go
T

167 lines
6.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 models
import "time"
// Base 通用字段
type Base struct {
ID uint64 `gorm:"primaryKey;autoIncrement" json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// User 网站用户
type User struct {
Base
Email string `gorm:"uniqueIndex;size:191" json:"email"`
PasswordHash string `gorm:"size:255" json:"-"`
Nickname string `gorm:"size:64" json:"nickname"`
Role string `gorm:"size:16;default:user" json:"role"`
TOTPSecret string `gorm:"size:64" json:"-"`
TOTPEnabled bool `gorm:"default:false" json:"totpEnabled"`
Status string `gorm:"size:16;default:active" json:"status"`
}
// Workspace 工作空间(租户)
type Workspace struct {
Base
Name string `gorm:"size:128" json:"name"`
OwnerID uint64 `gorm:"index" json:"ownerId"`
Plan string `gorm:"size:32;default:free" json:"plan"`
Status string `gorm:"size:16;default:active" json:"status"`
}
// Member 工作空间成员(角色:owner/admin/operator/reviewer/viewer)
type Member struct {
Base
WorkspaceID uint64 `gorm:"uniqueIndex:uk_ws_user" json:"workspaceId"`
UserID uint64 `gorm:"uniqueIndex:uk_ws_user" json:"userId"`
Role string `gorm:"size:16;default:viewer" json:"role"`
}
// Account 平台账号(凭据仅在 Agent 本机保险库,服务器零凭据)
type Account struct {
Base
WorkspaceID uint64 `gorm:"index" json:"workspaceId"`
Platform string `gorm:"size:32;index" json:"platform"`
AccountName string `gorm:"size:128" json:"accountName"`
Remark string `gorm:"size:255" json:"remark"`
AvatarURL string `gorm:"size:512" json:"avatarUrl"`
Status string `gorm:"size:16;default:unbound" json:"status"`
Health int `gorm:"default:100" json:"health"`
AgentDeviceID uint64 `gorm:"index" json:"agentDeviceId"`
IPProfile string `gorm:"size:191" json:"ipProfile"`
LastActiveAt *time.Time `json:"lastActiveAt"`
LastError string `gorm:"size:512" json:"lastError"`
}
// Material 素材
type Material struct {
Base
WorkspaceID uint64 `gorm:"index" json:"workspaceId"`
Name string `gorm:"size:255" json:"name"`
Kind string `gorm:"size:16;default:video" json:"kind"`
Size int64 `json:"size"`
SHA256 string `gorm:"size:64;index" json:"sha256"`
Mime string `gorm:"size:128" json:"mime"`
StorageKey string `gorm:"size:512" json:"-"`
Group string `gorm:"size:64" json:"group"`
Tags string `gorm:"type:text" json:"tags"`
Status string `gorm:"size:16;default:ready" json:"status"`
CreatedBy uint64 `json:"createdBy"`
}
// Task 发布任务(状态机:draft→pending_review→approved→queued→dispatched→running→success/failed→retrying;可 cancelled/suspended/rejected)
type Task struct {
Base
WorkspaceID uint64 `gorm:"index" json:"workspaceId"`
Title string `gorm:"size:255" json:"title"`
Content string `gorm:"type:text" json:"content"`
Tags string `gorm:"type:text" json:"tags"`
AccountIDs string `gorm:"type:text" json:"accountIds"`
MaterialIDs string `gorm:"type:text" json:"materialIds"`
ScheduleAt *time.Time `gorm:"index" json:"scheduleAt"`
Status string `gorm:"size:32;index;default:draft" json:"status"`
Priority int `gorm:"default:5" json:"priority"`
RetryCount int `gorm:"default:0" json:"retryCount"`
MaxRetry int `gorm:"default:3" json:"maxRetry"`
ErrorMessage string `gorm:"size:1024" json:"errorMessage"`
PublishedAt *time.Time `json:"publishedAt"`
PublishedURLs string `gorm:"type:text" json:"publishedUrls"`
Receipts string `gorm:"type:text" json:"receipts"`
CreatedBy uint64 `json:"createdBy"`
ReviewedBy uint64 `json:"reviewedBy"`
ReviewNote string `gorm:"size:512" json:"reviewNote"`
}
// AgentDevice 客户端设备(配对时注册 Ed25519 公钥)
type AgentDevice struct {
Base
WorkspaceID uint64 `gorm:"index" json:"workspaceId"`
Name string `gorm:"size:128" json:"name"`
OS string `gorm:"size:32" json:"os"`
Version string `gorm:"size:32" json:"version"`
PublicKey string `gorm:"type:text" json:"-"`
Status string `gorm:"size:16;default:offline" json:"status"`
IP string `gorm:"size:64" json:"ip"`
Revoked bool `gorm:"default:false" json:"revoked"`
LastSeenAt *time.Time `json:"lastSeenAt"`
PairedAt time.Time `json:"pairedAt"`
}
// Challenge 二次验证挑战(qr/sms/confirm/captcha/pending;超时挂起,永不暴力破解)
type Challenge struct {
Base
WorkspaceID uint64 `gorm:"index" json:"workspaceId"`
AccountID uint64 `gorm:"index" json:"accountId"`
DeviceID uint64 `gorm:"index" json:"deviceId"`
Platform string `gorm:"size:32" json:"platform"`
Kind string `gorm:"size:16" json:"kind"`
Status string `gorm:"size:16;default:active" json:"status"`
QRToken string `gorm:"size:512" json:"qrToken"`
QRURL string `gorm:"size:1024" json:"qrUrl"`
Prompt string `gorm:"size:512" json:"prompt"`
Payload string `gorm:"type:text" json:"payload"`
ExpiresAt time.Time `gorm:"index" json:"expiresAt"`
SolvedAt *time.Time `json:"solvedAt"`
}
// AuditLog 审计日志
type AuditLog struct {
Base
WorkspaceID uint64 `gorm:"index" json:"workspaceId"`
UserID uint64 `gorm:"index" json:"userId"`
Action string `gorm:"size:64;index" json:"action"`
Resource string `gorm:"size:128" json:"resource"`
Detail string `gorm:"type:text" json:"detail"`
IP string `gorm:"size:64" json:"ip"`
}
// Notification 站内通知
type Notification struct {
Base
WorkspaceID uint64 `gorm:"index" json:"workspaceId"`
UserID uint64 `gorm:"index" json:"userId"`
Kind string `gorm:"size:32" json:"kind"`
Title string `gorm:"size:255" json:"title"`
Content string `gorm:"type:text" json:"content"`
Read bool `gorm:"default:false" json:"read"`
}
// PairingCode 配对码(一次性,5 分钟过期)
type PairingCode struct {
Base
WorkspaceID uint64 `gorm:"index" json:"workspaceId"`
Code string `gorm:"size:12;uniqueIndex" json:"code"`
ExpiresAt time.Time `json:"expiresAt"`
Used bool `gorm:"default:false" json:"used"`
DeviceID uint64 `json:"deviceId"`
}
// TransferToken 素材直链下载 token(短时签名)
type TransferToken struct {
Base
MaterialID uint64 `gorm:"index" json:"materialId"`
Token string `gorm:"size:191;uniqueIndex" json:"token"`
ExpiresAt time.Time `json:"expiresAt"`
}