db

package
v1.9.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdminOperationLog added in v1.9.5

type AdminOperationLog struct {
	gorm.Model
	Action    string `gorm:"size:100;index" json:"action"`
	Target    string `gorm:"size:255" json:"target"`
	Success   bool   `json:"success"`
	Message   string `gorm:"type:text" json:"message"`
	ActorID   *uint  `gorm:"index" json:"actor_id"`
	ActorName string `gorm:"size:100" json:"actor_name"`
	IP        string `gorm:"size:45" json:"ip"`
	LatencyMs int64  `json:"latency_ms"`
}

AdminOperationLog 记录后台运维操作 Action: 具体操作标识,例如 maintenance.clean_temp Target: 操作影响的目标对象描述 Success: 操作是否成功 Message: 可读的描述信息 Actor: 操作者信息 LatencyMs: 操作耗时(毫秒,可选)

type AdminOperationLogQuery added in v1.9.5

type AdminOperationLogQuery struct {
	Action   string
	Actor    string
	Success  *bool
	Page     int
	PageSize int
}

AdminOperationLogQuery 查询后台操作日志 Success: nil 表示忽略; true/false 表示按结果过滤

type ChunkQuery

type ChunkQuery struct {
	UploadID   string `json:"upload_id"`
	ChunkIndex *int   `json:"chunk_index"`
	Status     string `json:"status"`
	Completed  *bool  `json:"completed"`
	Limit      int    `json:"limit"`
	Offset     int    `json:"offset"`
}

ChunkQuery 分片查询条件

type ChunkStats

type ChunkStats struct {
	gorm.Model
	TotalChunks     int64 `json:"total_chunks"`
	CompletedChunks int64 `json:"completed_chunks"`
	PendingChunks   int64 `json:"pending_chunks"`
	FailedChunks    int64 `json:"failed_chunks"`
}

ChunkStats 分片统计查询结果

type ChunkUpdate

type ChunkUpdate struct {
	gorm.Model
	ChunkHash  *string    `json:"chunk_hash"`
	Completed  *bool      `json:"completed"`
	RetryCount *int       `json:"retry_count"`
	LastError  *string    `json:"last_error"`
	Status     *string    `json:"status"`
	UpdatedAt  *time.Time `json:"updated_at"`
}

ChunkUpdate 分片更新数据

type FileCode

type FileCode struct {
	gorm.Model
	Code         string     `gorm:"uniqueIndex;size:255" json:"code"`
	Prefix       string     `gorm:"size:255" json:"prefix"`
	Suffix       string     `gorm:"size:255" json:"suffix"`
	UUIDFileName string     `gorm:"size:255" json:"uuid_file_name"`
	FilePath     string     `gorm:"size:255" json:"file_path"`
	Size         int64      `gorm:"default:0" json:"size"`
	Text         string     `gorm:"type:text" json:"text"`
	ExpiredAt    *time.Time `json:"expired_at"`
	ExpiredCount int        `gorm:"default:0" json:"expired_count"`
	UsedCount    int        `gorm:"default:0" json:"used_count"`

	FileHash  string `gorm:"size:64" json:"file_hash"`
	IsChunked bool   `gorm:"default:false" json:"is_chunked"`
	UploadID  string `gorm:"size:36" json:"upload_id"`

	// 新增:用户认证相关字段
	UserID      *uint  `gorm:"index" json:"user_id"`                           // 上传用户ID,为null表示匿名上传
	UploadType  string `gorm:"size:20;default:'anonymous'" json:"upload_type"` // anonymous, authenticated
	RequireAuth bool   `gorm:"default:false" json:"require_auth"`              // 是否需要登录才能下载
	OwnerIP     string `gorm:"size:45" json:"owner_ip"`                        // 上传者IP地址
}

FileCode 文件代码模型

func (*FileCode) GetFilePath

func (f *FileCode) GetFilePath() string

GetFilePath 获取文件路径

func (*FileCode) IsExpired

func (f *FileCode) IsExpired() bool

IsExpired 检查是否过期

type FileCodeQuery

type FileCodeQuery struct {
	gorm.Model
	Code        string     `json:"code"`
	UserID      *uint      `json:"user_id"`
	UploadType  string     `json:"upload_type"`
	RequireAuth *bool      `json:"require_auth"`
	IsExpired   *bool      `json:"is_expired"`
	Search      string     `json:"search"` // 模糊搜索文件名
	StartDate   *time.Time `json:"start_date"`
	EndDate     *time.Time `json:"end_date"`
	Limit       int        `json:"limit"`
	Offset      int        `json:"offset"`
}

FileCodeQuery 文件代码查询条件

type FileCodeStats

type FileCodeStats struct {
	gorm.Model
	TotalFiles     int64 `json:"total_files"`
	TotalSize      int64 `json:"total_size"`
	TodayUploads   int64 `json:"today_uploads"`
	TodayDownloads int64 `json:"today_downloads"`
	ExpiredFiles   int64 `json:"expired_files"`
	AnonymousFiles int64 `json:"anonymous_files"`
	UserFiles      int64 `json:"user_files"`
}

FileCodeStats 文件统计查询结果

type FileCodeUpdate

type FileCodeUpdate struct {
	gorm.Model
	ExpiredAt    *time.Time `json:"expired_at"`
	ExpiredCount *int       `json:"expired_count"`
	UsedCount    *int       `json:"used_count"`
	RequireAuth  *bool      `json:"require_auth"`
	OwnerIP      *string    `json:"owner_ip"`
}

FileCodeUpdate 文件代码更新数据

type SessionQuery

type SessionQuery struct {
	gorm.Model
	UserID    *uint      `json:"user_id"`
	SessionID string     `json:"session_id"`
	IPAddress string     `json:"ip_address"`
	IsActive  *bool      `json:"is_active"`
	StartDate *time.Time `json:"start_date"`
	EndDate   *time.Time `json:"end_date"`
	Limit     int        `json:"limit"`
	Offset    int        `json:"offset"`
}

SessionQuery 会话查询条件

type SessionUpdate

type SessionUpdate struct {
	gorm.Model
	IsActive  *bool      `json:"is_active"`
	ExpiresAt *time.Time `json:"expires_at"`
	UpdatedAt *time.Time `json:"updated_at"`
}

SessionUpdate 会话更新数据

type TransferLog added in v1.9.5

type TransferLog struct {
	gorm.Model
	Operation  string `gorm:"size:20;index" json:"operation"`
	FileCodeID uint   `gorm:"index" json:"file_code_id"`
	FileCode   string `gorm:"size:255" json:"file_code"`
	FileName   string `gorm:"size:255" json:"file_name"`
	FileSize   int64  `json:"file_size"`
	UserID     *uint  `gorm:"index" json:"user_id"`
	Username   string `gorm:"size:100" json:"username"`
	IP         string `gorm:"size:45" json:"ip"`
	DurationMs int64  `json:"duration_ms"`
}

TransferLog 记录上传/下载操作日志 当系统要求登录上传/下载时,用于追踪用户行为 Operation: upload 或 download DurationMs: 针对下载记录耗时,上传默认为0 Username保留冗余信息,便于查询,即使用户被删除仍保留原始名字

type TransferLogQuery added in v1.9.5

type TransferLogQuery struct {
	Operation string `json:"operation"`
	UserID    *uint  `json:"user_id"`
	Search    string `json:"search"`
	Page      int    `json:"page"`
	PageSize  int    `json:"page_size"`
}

TransferLogQuery 查询条件

type UploadChunk

type UploadChunk struct {
	gorm.Model

	UploadID    string `gorm:"index;size:36" json:"upload_id"`
	ChunkIndex  int    `json:"chunk_index"`
	ChunkHash   string `gorm:"size:64" json:"chunk_hash"`
	TotalChunks int    `json:"total_chunks"`
	FileSize    int64  `json:"file_size"`
	ChunkSize   int    `json:"chunk_size"`
	FileName    string `gorm:"size:255" json:"file_name"`

	Completed  bool   `gorm:"default:false" json:"completed"`
	RetryCount int    `gorm:"default:0" json:"retry_count"`            // 重试次数
	LastError  string `gorm:"type:text" json:"last_error"`             // 最后错误信息
	Status     string `gorm:"size:20;default:'pending'" json:"status"` // pending, uploading, completed, failed
}

UploadChunk 上传分片模型

type User

type User struct {
	gorm.Model
	Username      string     `gorm:"uniqueIndex;size:50" json:"username"`
	Email         string     `gorm:"uniqueIndex;size:100" json:"email"`
	PasswordHash  string     `gorm:"size:128" json:"-"`                      // 密码哈希,不返回给前端
	Nickname      string     `gorm:"size:50" json:"nickname"`                // 用户昵称
	Avatar        string     `gorm:"size:255" json:"avatar"`                 // 头像URL
	Role          string     `gorm:"size:20;default:'user'" json:"role"`     // admin, user
	Status        string     `gorm:"size:20;default:'active'" json:"status"` // active, inactive, banned
	EmailVerified bool       `gorm:"default:false" json:"email_verified"`    // 邮箱是否验证
	LastLoginAt   *time.Time `json:"last_login_at"`                          // 最后登录时间
	LastLoginIP   string     `gorm:"size:45" json:"last_login_ip"`           // 最后登录IP

	// 用户上传统计
	TotalUploads    int   `gorm:"default:0" json:"total_uploads"`     // 总上传次数
	TotalDownloads  int   `gorm:"default:0" json:"total_downloads"`   // 总下载次数
	TotalStorage    int64 `gorm:"default:0" json:"total_storage"`     // 总存储大小(字节)
	MaxUploadSize   int64 `gorm:"default:0" json:"max_upload_size"`   // 最大单次上传大小(字节),0表示使用系统默认
	MaxStorageQuota int64 `gorm:"default:0" json:"max_storage_quota"` // 最大存储配额(字节),0表示无限制
}

User 用户模型

type UserAPIKey added in v1.9.9

type UserAPIKey struct {
	gorm.Model
	UserID     uint   `gorm:"index"`
	Name       string `gorm:"size:100"`
	Prefix     string `gorm:"size:16"`
	KeyHash    string `gorm:"size:64;uniqueIndex"`
	LastUsedAt *time.Time
	ExpiresAt  *time.Time
	RevokedAt  *time.Time
	Revoked    bool `gorm:"default:false"`
}

func (UserAPIKey) TableName added in v1.9.9

func (UserAPIKey) TableName() string

TableName 指定表名

type UserQuery

type UserQuery struct {
	ID       *uint  `json:"id"`
	Username string `json:"username"`
	Email    string `json:"email"`
	Role     string `json:"role"`
	Status   string `json:"status"`
	Search   string `json:"search"` // 模糊搜索用户名或邮箱
	Limit    int    `json:"limit"`
	Offset   int    `json:"offset"`
}

UserQuery 用户查询条件

type UserSession

type UserSession struct {
	gorm.Model
	UserID    uint      `gorm:"index" json:"user_id"`
	SessionID string    `gorm:"uniqueIndex;size:128" json:"session_id"` // JWT token ID
	IPAddress string    `gorm:"size:45" json:"ip_address"`              // 登录IP
	UserAgent string    `gorm:"size:500" json:"user_agent"`             // 用户代理
	ExpiresAt time.Time `json:"expires_at"`                             // 过期时间

	IsActive bool `gorm:"default:true" json:"is_active"` // 是否活跃
}

UserSession 用户会话模型

type UserStats

type UserStats struct {
	UserID         uint  `json:"user_id"`
	TotalUploads   int   `json:"total_uploads"`
	TotalDownloads int   `json:"total_downloads"`
	TotalStorage   int64 `json:"total_storage"`
	FileCount      int   `json:"file_count"`
}

UserStats 用户统计查询结果

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL