Documentation
¶
Index ¶
- type AdminService
- func (s *AdminService) CleanExpiredFiles() (int, error)
- func (s *AdminService) CreateUser(username, email, password, nickname, role, status string) (*models.User, error)
- func (s *AdminService) DeleteFile(id uint) error
- func (s *AdminService) DeleteFileByCode(code string) error
- func (s *AdminService) DeleteUser(id uint) error
- func (s *AdminService) DownloadFile(c *gin.Context, id uint) error
- func (s *AdminService) DownloadFileByCode(c *gin.Context, code string) error
- func (s *AdminService) GenerateToken() (string, error)
- func (s *AdminService) GetConfig() (map[string]interface{}, error)
- func (s *AdminService) GetFile(id uint) (*models.FileCode, error)
- func (s *AdminService) GetFileByCode(code string) (*models.FileCode, error)
- func (s *AdminService) GetFiles(page, pageSize int, search string) ([]models.FileCode, int64, error)
- func (s *AdminService) GetStats() (map[string]interface{}, error)
- func (s *AdminService) GetUser(id uint) (*models.User, error)
- func (s *AdminService) GetUserByID(userID uint) (*models.User, error)
- func (s *AdminService) GetUserFiles(userID uint, page, limit int) ([]models.FileCode, int64, error)
- func (s *AdminService) GetUserStats(userID uint) (map[string]interface{}, error)
- func (s *AdminService) GetUsers(page, pageSize int, search string) ([]models.User, int64, error)
- func (s *AdminService) ResetUserPassword(userID uint, newPassword string) error
- func (s *AdminService) ServeFile(c *gin.Context, fileCode *models.FileCode) error
- func (s *AdminService) UpdateConfig(configData map[string]interface{}) error
- func (s *AdminService) UpdateFile(id uint, text, name string, expTime time.Time) error
- func (s *AdminService) UpdateFileByCode(code, text, name string, expTime time.Time) error
- func (s *AdminService) UpdateUser(id uint, email, password, nickname, role, status string) error
- func (s *AdminService) UpdateUserStatus(userID uint, isActive bool) error
- func (s *AdminService) ValidateToken(tokenString string) error
- type AuthClaims
- type AuthService
- func (s *AuthService) ChangeUserPassword(data PasswordChangeData) error
- func (s *AuthService) GetPasswordPolicy() PasswordPolicy
- func (s *AuthService) HashPassword(password string) (string, error)
- func (s *AuthService) LoginUser(data UserLoginData) (string, *models.User, error)
- func (s *AuthService) LogoutUser(sessionID string) error
- func (s *AuthService) NormalizeEmail(email string) string
- func (s *AuthService) NormalizeUsername(username string) string
- func (s *AuthService) RegisterUser(data UserRegistrationData) (*models.User, error)
- func (s *AuthService) ResetUserPassword(userID uint, newPassword string) error
- func (s *AuthService) ValidateEmail(email string) error
- func (s *AuthService) ValidatePassword(password string, username string, email string) error
- func (s *AuthService) ValidateToken(tokenString string) (*AuthClaims, error)
- func (s *AuthService) ValidateUserRegistration(data UserRegistrationData) error
- func (s *AuthService) ValidateUsername(username string) error
- func (s *AuthService) VerifyPassword(hashedPassword, password string) error
- type ChunkService
- func (s *ChunkService) CancelUpload(uploadID string) error
- func (s *ChunkService) CompleteUpload(uploadID string, expireValue int, expireStyle string) (*models.FileCode, error)
- func (s *ChunkService) GetUploadStatus(uploadID string) (*UploadStatus, error)
- func (s *ChunkService) InitChunkUpload(fileName string, fileSize int64, chunkSize int, fileHash string) (*InitChunkUploadResult, error)
- func (s *ChunkService) UploadChunk(uploadID string, chunkIndex int, file *multipart.FileHeader) (string, error)
- func (s *ChunkService) VerifyChunk(uploadID string, chunkIndex int, expectedHash string) (bool, error)
- type InitChunkUploadResult
- type PasswordChangeData
- type PasswordPolicy
- type PasswordResetData
- type ShareFileRequest
- type ShareService
- func (s *ShareService) GetFileByCode(code string, checkExpire bool) (*models.FileCode, error)
- func (s *ShareService) GetFileByCodeWithAuth(code string, checkExpire bool, userID *uint) (*models.FileCode, error)
- func (s *ShareService) GetStorageInterface() storage.StorageInterface
- func (s *ShareService) ShareFile(file *multipart.FileHeader, expireValue int, expireStyle string) (*models.FileCode, error)
- func (s *ShareService) ShareFileWithAuth(req ShareFileRequest) (*models.FileCode, error)
- func (s *ShareService) ShareText(text string, expireValue int, expireStyle string) (*models.FileCode, error)
- func (s *ShareService) ShareTextWithAuth(req ShareTextRequest) (*models.FileCode, error)
- func (s *ShareService) UpdateFileUsage(fileCode *models.FileCode) error
- type ShareTextRequest
- type UploadStatus
- type UserLoginData
- type UserRegistrationData
- type UserService
- func (s *UserService) ChangePassword(userID uint, oldPassword, newPassword string) error
- func (s *UserService) CheckStorageQuota(userID uint, additionalSize int64) error
- func (s *UserService) DeleteUserFile(userID uint, fileID uint) error
- func (s *UserService) DeleteUserFileByCode(userID uint, code string) error
- func (s *UserService) GetUserByID(userID uint) (*models.User, error)
- func (s *UserService) GetUserFiles(userID uint, page, limit int) ([]models.FileCode, int64, error)
- func (s *UserService) GetUserStats(userID uint) (map[string]interface{}, error)
- func (s *UserService) IsRegistrationAllowed() bool
- func (s *UserService) IsUserSystemEnabled() bool
- func (s *UserService) Login(usernameOrEmail, password, ipAddress, userAgent string) (string, *models.User, error)
- func (s *UserService) Logout(sessionID string) error
- func (s *UserService) NormalizeUsername(username string) string
- func (s *UserService) Register(username, email, password, nickname string) (*models.User, error)
- func (s *UserService) UpdateUserDownloadStats(userID uint) error
- func (s *UserService) UpdateUserProfile(userID uint, nickname, avatar string) error
- func (s *UserService) UpdateUserStats(userID uint, uploadCount, downloadCount int, storageSize int64) error
- func (s *UserService) UpdateUserUploadStats(userID uint, fileSize int64) error
- func (s *UserService) ValidateToken(tokenString string) (interface{}, error)
- func (s *UserService) ValidateUserInput(username, email, password string) error
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AdminService ¶
type AdminService struct {
// contains filtered or unexported fields
}
AdminService 管理员服务
func NewAdminService ¶
func NewAdminService(db *gorm.DB, config *config.Config, storageManager *storage.StorageManager) *AdminService
NewAdminService 创建管理员服务
func (*AdminService) CleanExpiredFiles ¶ added in v1.1.0
func (s *AdminService) CleanExpiredFiles() (int, error)
CleanExpiredFiles 清理过期文件
func (*AdminService) CreateUser ¶ added in v1.1.0
func (s *AdminService) CreateUser(username, email, password, nickname, role, status string) (*models.User, error)
CreateUser 创建用户 - 使用统一的认证服务
func (*AdminService) DeleteFile ¶ added in v1.1.0
func (s *AdminService) DeleteFile(id uint) error
DeleteFile 删除文件
func (*AdminService) DeleteFileByCode ¶ added in v1.1.0
func (s *AdminService) DeleteFileByCode(code string) error
DeleteFileByCode 通过代码删除文件
func (*AdminService) DeleteUser ¶ added in v1.1.0
func (s *AdminService) DeleteUser(id uint) error
DeleteUser 删除用户
func (*AdminService) DownloadFile ¶ added in v1.1.0
func (s *AdminService) DownloadFile(c *gin.Context, id uint) error
DownloadFile 下载文件
func (*AdminService) DownloadFileByCode ¶ added in v1.1.0
func (s *AdminService) DownloadFileByCode(c *gin.Context, code string) error
DownloadFileByCode 通过代码下载文件
func (*AdminService) GenerateToken ¶ added in v1.1.0
func (s *AdminService) GenerateToken() (string, error)
GenerateToken 生成管理员JWT令牌
func (*AdminService) GetConfig ¶ added in v1.1.0
func (s *AdminService) GetConfig() (map[string]interface{}, error)
GetConfig 获取配置
func (*AdminService) GetFile ¶ added in v1.1.0
func (s *AdminService) GetFile(id uint) (*models.FileCode, error)
GetFile 获取文件信息
func (*AdminService) GetFileByCode ¶ added in v1.1.0
func (s *AdminService) GetFileByCode(code string) (*models.FileCode, error)
GetFileByCode 通过代码获取文件信息
func (*AdminService) GetFiles ¶ added in v1.1.0
func (s *AdminService) GetFiles(page, pageSize int, search string) ([]models.FileCode, int64, error)
GetFiles 获取文件列表
func (*AdminService) GetStats ¶ added in v1.1.0
func (s *AdminService) GetStats() (map[string]interface{}, error)
GetStats 获取统计信息
func (*AdminService) GetUser ¶ added in v1.1.0
func (s *AdminService) GetUser(id uint) (*models.User, error)
GetUser 获取用户
func (*AdminService) GetUserByID ¶ added in v1.1.0
func (s *AdminService) GetUserByID(userID uint) (*models.User, error)
GetUserByID 获取用户信息(代理到基础方法)
func (*AdminService) GetUserFiles ¶ added in v1.1.0
GetUserFiles 获取用户文件列表
func (*AdminService) GetUserStats ¶ added in v1.1.0
func (s *AdminService) GetUserStats(userID uint) (map[string]interface{}, error)
GetUserStats 获取用户统计信息
func (*AdminService) ResetUserPassword ¶ added in v1.1.0
func (s *AdminService) ResetUserPassword(userID uint, newPassword string) error
ResetUserPassword 重置用户密码 - 使用统一的认证服务
func (*AdminService) UpdateConfig ¶ added in v1.1.0
func (s *AdminService) UpdateConfig(configData map[string]interface{}) error
UpdateConfig 更新配置
func (*AdminService) UpdateFile ¶ added in v1.1.0
UpdateFile 更新文件
func (*AdminService) UpdateFileByCode ¶ added in v1.1.0
func (s *AdminService) UpdateFileByCode(code, text, name string, expTime time.Time) error
UpdateFileByCode 通过代码更新文件
func (*AdminService) UpdateUser ¶ added in v1.1.0
func (s *AdminService) UpdateUser(id uint, email, password, nickname, role, status string) error
UpdateUser 更新用户 - 使用统一的认证服务
func (*AdminService) UpdateUserStatus ¶ added in v1.1.0
func (s *AdminService) UpdateUserStatus(userID uint, isActive bool) error
UpdateUserStatus 更新用户状态
func (*AdminService) ValidateToken ¶ added in v1.1.0
func (s *AdminService) ValidateToken(tokenString string) error
ValidateToken 验证管理员JWT令牌
type AuthClaims ¶
type AuthClaims struct {
UserID uint `json:"user_id"`
Username string `json:"username"`
Role string `json:"role"`
SessionID string `json:"session_id"`
jwt.RegisteredClaims
}
AuthClaims JWT声明
type AuthService ¶
type AuthService struct {
// contains filtered or unexported fields
}
AuthService 认证服务 - 提供统一的用户认证、密码处理、会话管理等功能
func NewAuthService ¶
func NewAuthService(db *gorm.DB, cfg *config.Config) *AuthService
NewAuthService 创建认证服务
func (*AuthService) ChangeUserPassword ¶ added in v1.1.0
func (s *AuthService) ChangeUserPassword(data PasswordChangeData) error
ChangeUserPassword 修改用户密码
func (*AuthService) GetPasswordPolicy ¶ added in v1.1.0
func (s *AuthService) GetPasswordPolicy() PasswordPolicy
GetPasswordPolicy 获取当前密码策略
func (*AuthService) HashPassword ¶ added in v1.1.0
func (s *AuthService) HashPassword(password string) (string, error)
HashPassword 对密码进行哈希处理
func (*AuthService) LoginUser ¶ added in v1.1.0
func (s *AuthService) LoginUser(data UserLoginData) (string, *models.User, error)
LoginUser 用户登录
func (*AuthService) LogoutUser ¶ added in v1.1.0
func (s *AuthService) LogoutUser(sessionID string) error
LogoutUser 用户登出
func (*AuthService) NormalizeEmail ¶ added in v1.1.0
func (s *AuthService) NormalizeEmail(email string) string
NormalizeEmail 规范化邮箱
func (*AuthService) NormalizeUsername ¶ added in v1.1.0
func (s *AuthService) NormalizeUsername(username string) string
NormalizeUsername 规范化用户名
func (*AuthService) RegisterUser ¶ added in v1.1.0
func (s *AuthService) RegisterUser(data UserRegistrationData) (*models.User, error)
RegisterUser 用户注册
func (*AuthService) ResetUserPassword ¶ added in v1.1.0
func (s *AuthService) ResetUserPassword(userID uint, newPassword string) error
ResetUserPassword 重置用户密码(管理员操作)
func (*AuthService) ValidateEmail ¶ added in v1.1.0
func (s *AuthService) ValidateEmail(email string) error
ValidateEmail 验证邮箱格式
func (*AuthService) ValidatePassword ¶ added in v1.1.0
func (s *AuthService) ValidatePassword(password string, username string, email string) error
ValidatePassword 验证密码是否符合策略
func (*AuthService) ValidateToken ¶ added in v1.1.0
func (s *AuthService) ValidateToken(tokenString string) (*AuthClaims, error)
ValidateToken 验证JWT令牌
func (*AuthService) ValidateUserRegistration ¶ added in v1.1.0
func (s *AuthService) ValidateUserRegistration(data UserRegistrationData) error
ValidateUserRegistration 验证用户注册数据
func (*AuthService) ValidateUsername ¶ added in v1.1.0
func (s *AuthService) ValidateUsername(username string) error
ValidateUsername 验证用户名
func (*AuthService) VerifyPassword ¶ added in v1.1.0
func (s *AuthService) VerifyPassword(hashedPassword, password string) error
VerifyPassword 验证密码是否正确
type ChunkService ¶
type ChunkService struct {
// contains filtered or unexported fields
}
ChunkService 分片服务
func NewChunkService ¶
func NewChunkService(db *gorm.DB, storageManager *storage.StorageManager, config *config.Config) *ChunkService
func (*ChunkService) CancelUpload ¶ added in v1.1.0
func (s *ChunkService) CancelUpload(uploadID string) error
CancelUpload 取消上传
func (*ChunkService) CompleteUpload ¶ added in v1.1.0
func (s *ChunkService) CompleteUpload(uploadID string, expireValue int, expireStyle string) (*models.FileCode, error)
CompleteUpload 完成上传
func (*ChunkService) GetUploadStatus ¶ added in v1.1.0
func (s *ChunkService) GetUploadStatus(uploadID string) (*UploadStatus, error)
GetUploadStatus 获取上传状态
func (*ChunkService) InitChunkUpload ¶ added in v1.1.0
func (s *ChunkService) InitChunkUpload(fileName string, fileSize int64, chunkSize int, fileHash string) (*InitChunkUploadResult, error)
InitChunkUpload 初始化分片上传,支持断点续传
func (*ChunkService) UploadChunk ¶ added in v1.1.0
func (s *ChunkService) UploadChunk(uploadID string, chunkIndex int, file *multipart.FileHeader) (string, error)
UploadChunk 上传分片,支持断点续传
func (*ChunkService) VerifyChunk ¶ added in v1.1.0
func (s *ChunkService) VerifyChunk(uploadID string, chunkIndex int, expectedHash string) (bool, error)
VerifyChunk 验证分片完整性
type InitChunkUploadResult ¶ added in v1.1.0
type InitChunkUploadResult struct {
Existed bool `json:"existed"`
UploadID string `json:"upload_id"`
ChunkSize int `json:"chunk_size"`
TotalChunks int `json:"total_chunks"`
UploadedChunks []int `json:"uploaded_chunks"`
FileCode string `json:"file_code,omitempty"` // 如果文件已存在,返回文件代码
ResumePosition int64 `json:"resume_position,omitempty"` // 断点续传位置
Progress string `json:"progress,omitempty"` // 上传进度
}
InitChunkUploadResult 初始化上传结果
type PasswordChangeData ¶ added in v1.1.0
PasswordChangeData 密码修改数据
type PasswordPolicy ¶ added in v1.1.0
type PasswordPolicy struct {
MinLength int
MaxLength int
RequireUpper bool
RequireLower bool
RequireNumber bool
RequireSpecial bool
ForbidCommon bool
ForbidPersonal bool
}
PasswordPolicy 密码策略
type PasswordResetData ¶ added in v1.1.0
PasswordResetData 密码重置数据
type ShareService ¶
type ShareService struct {
// contains filtered or unexported fields
}
ShareService 分享服务
func NewShareService ¶
func NewShareService(db *gorm.DB, storageManager *storage.StorageManager, config *config.Config, userService *UserService) *ShareService
func (*ShareService) GetFileByCode ¶ added in v1.1.0
GetFileByCode 根据代码获取文件
func (*ShareService) GetFileByCodeWithAuth ¶ added in v1.1.0
func (s *ShareService) GetFileByCodeWithAuth(code string, checkExpire bool, userID *uint) (*models.FileCode, error)
GetFileByCodeWithAuth 根据代码获取文件(带认证检查)
func (*ShareService) GetStorageInterface ¶ added in v1.1.0
func (s *ShareService) GetStorageInterface() storage.StorageInterface
GetStorageInterface 获取当前存储接口
func (*ShareService) ShareFile ¶ added in v1.1.0
func (s *ShareService) ShareFile(file *multipart.FileHeader, expireValue int, expireStyle string) (*models.FileCode, error)
ShareFile 分享文件
func (*ShareService) ShareFileWithAuth ¶ added in v1.1.0
func (s *ShareService) ShareFileWithAuth(req ShareFileRequest) (*models.FileCode, error)
ShareFileWithAuth 带认证的分享文件
func (*ShareService) ShareText ¶ added in v1.1.0
func (s *ShareService) ShareText(text string, expireValue int, expireStyle string) (*models.FileCode, error)
ShareText 分享文本
func (*ShareService) ShareTextWithAuth ¶ added in v1.1.0
func (s *ShareService) ShareTextWithAuth(req ShareTextRequest) (*models.FileCode, error)
ShareTextWithAuth 带认证的分享文本
func (*ShareService) UpdateFileUsage ¶ added in v1.1.0
func (s *ShareService) UpdateFileUsage(fileCode *models.FileCode) error
UpdateFileUsage 更新文件使用次数
type UploadStatus ¶ added in v1.1.0
type UploadStatus struct {
UploadID string `json:"upload_id"`
FileName string `json:"file_name"`
FileSize int64 `json:"file_size"`
TotalChunks int `json:"total_chunks"`
UploadedChunks []int `json:"uploaded_chunks"`
MissingChunks []int `json:"missing_chunks"`
Progress string `json:"progress"`
ResumePosition int64 `json:"resume_position"`
Status string `json:"status"` // uploading, completed, failed, canceled
}
UploadStatus 上传状态结构
type UserLoginData ¶ added in v1.1.0
UserLoginData 用户登录数据
type UserRegistrationData ¶ added in v1.1.0
UserRegistrationData 用户注册数据
type UserService ¶
type UserService struct {
// contains filtered or unexported fields
}
UserService 用户服务
func NewUserService ¶
func NewUserService(db *gorm.DB, cfg *config.Config) *UserService
NewUserService 创建用户服务
func (*UserService) ChangePassword ¶ added in v1.1.0
func (s *UserService) ChangePassword(userID uint, oldPassword, newPassword string) error
ChangePassword 修改密码
func (*UserService) CheckStorageQuota ¶ added in v1.1.0
func (s *UserService) CheckStorageQuota(userID uint, additionalSize int64) error
CheckStorageQuota 检查用户存储配额
func (*UserService) DeleteUserFile ¶ added in v1.1.0
func (s *UserService) DeleteUserFile(userID uint, fileID uint) error
DeleteUserFile 删除用户文件
func (*UserService) DeleteUserFileByCode ¶ added in v1.1.0
func (s *UserService) DeleteUserFileByCode(userID uint, code string) error
DeleteUserFileByCode 根据code删除用户文件
func (*UserService) GetUserByID ¶ added in v1.1.0
func (s *UserService) GetUserByID(userID uint) (*models.User, error)
GetUserByID 根据ID获取用户
func (*UserService) GetUserFiles ¶ added in v1.1.0
GetUserFiles 获取用户上传的文件
func (*UserService) GetUserStats ¶ added in v1.1.0
func (s *UserService) GetUserStats(userID uint) (map[string]interface{}, error)
GetUserStats 获取用户统计信息
func (*UserService) IsRegistrationAllowed ¶ added in v1.1.0
func (s *UserService) IsRegistrationAllowed() bool
IsRegistrationAllowed 检查是否允许用户注册
func (*UserService) IsUserSystemEnabled ¶ added in v1.1.0
func (s *UserService) IsUserSystemEnabled() bool
IsUserSystemEnabled 检查用户系统是否启用
func (*UserService) Login ¶ added in v1.1.0
func (s *UserService) Login(usernameOrEmail, password, ipAddress, userAgent string) (string, *models.User, error)
Login 用户登录
func (*UserService) Logout ¶ added in v1.1.0
func (s *UserService) Logout(sessionID string) error
Logout 用户登出
func (*UserService) NormalizeUsername ¶ added in v1.1.0
func (s *UserService) NormalizeUsername(username string) string
NormalizeUsername 规范化用户名
func (*UserService) Register ¶ added in v1.1.0
func (s *UserService) Register(username, email, password, nickname string) (*models.User, error)
Register 用户注册
func (*UserService) UpdateUserDownloadStats ¶ added in v1.1.0
func (s *UserService) UpdateUserDownloadStats(userID uint) error
UpdateUserDownloadStats 更新用户下载统计信息
func (*UserService) UpdateUserProfile ¶ added in v1.1.0
func (s *UserService) UpdateUserProfile(userID uint, nickname, avatar string) error
UpdateUserProfile 更新用户资料
func (*UserService) UpdateUserStats ¶ added in v1.1.0
func (s *UserService) UpdateUserStats(userID uint, uploadCount, downloadCount int, storageSize int64) error
UpdateUserStats 更新用户统计信息
func (*UserService) UpdateUserUploadStats ¶ added in v1.1.0
func (s *UserService) UpdateUserUploadStats(userID uint, fileSize int64) error
UpdateUserUploadStats 更新用户上传统计信息
func (*UserService) ValidateToken ¶ added in v1.1.0
func (s *UserService) ValidateToken(tokenString string) (interface{}, error)
ValidateToken 验证token
func (*UserService) ValidateUserInput ¶ added in v1.1.0
func (s *UserService) ValidateUserInput(username, email, password string) error
ValidateUserInput 验证用户输入
type ValidationError ¶ added in v1.1.0
ValidationError 验证错误
func (ValidationError) Error ¶ added in v1.1.0
func (e ValidationError) Error() string