Documentation
¶
Overview ¶
Package sync 提供基于 TUS 协议的文件同步模块
Index ¶
- Constants
- type Handler
- func (h *Handler) DeleteFile(c *gin.Context)
- func (h *Handler) DownloadFile(c *gin.Context)
- func (h *Handler) GetFile(c *gin.Context)
- func (h *Handler) GetStatus(c *gin.Context)
- func (h *Handler) GetUpload(c *gin.Context)
- func (h *Handler) ListFiles(c *gin.Context)
- func (h *Handler) ListUploads(c *gin.Context)
- func (h *Handler) RegisterRoutes(r *gin.RouterGroup)
- type ListFilesRequest
- type ListFilesResponse
- type Module
- type Service
- func (s *Service) DeleteFile(id string) error
- func (s *Service) DownloadFile(id string) (string, string, error)
- func (s *Service) GetFile(id string) (*SyncFile, error)
- func (s *Service) GetStatus() *SyncStatus
- func (s *Service) GetTusHandler() *tusHandler.Handler
- func (s *Service) GetUpload(id string) (*UploadSession, error)
- func (s *Service) Init() error
- func (s *Service) ListActiveUploads() ([]UploadSession, error)
- func (s *Service) ListFiles(req *ListFilesRequest) (*ListFilesResponse, error)
- type StoreStats
- type SyncFile
- type SyncFileModel
- type SyncStatus
- type UploadSession
- type UploadSessionModel
Constants ¶
View Source
const ( ModuleID = "sync" ModuleName = "文件同步" ModuleVersion = "1.0.0" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler HTTP 处理器
func (*Handler) RegisterRoutes ¶
func (h *Handler) RegisterRoutes(r *gin.RouterGroup)
RegisterRoutes 注册路由
type ListFilesRequest ¶
type ListFilesRequest struct {
Path string `form:"path"`
Limit int `form:"limit"`
Offset int `form:"offset"`
}
ListFilesRequest 文件列表请求
type ListFilesResponse ¶
ListFilesResponse 文件列表响应
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module 文件同步模块
func (*Module) RegisterRoutes ¶
func (m *Module) RegisterRoutes(r *gin.RouterGroup)
RegisterRoutes 注册路由
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service 文件同步服务
func NewService ¶
NewService 创建服务实例
func (*Service) DownloadFile ¶
DownloadFile 获取文件下载路径
func (*Service) GetTusHandler ¶
func (s *Service) GetTusHandler() *tusHandler.Handler
GetTusHandler 获取 TUS 处理器
func (*Service) GetUpload ¶
func (s *Service) GetUpload(id string) (*UploadSession, error)
GetUpload 获取上传会话
func (*Service) ListActiveUploads ¶
func (s *Service) ListActiveUploads() ([]UploadSession, error)
ListActiveUploads 获取进行中的上传
func (*Service) ListFiles ¶
func (s *Service) ListFiles(req *ListFilesRequest) (*ListFilesResponse, error)
ListFiles 获取文件列表
type StoreStats ¶
type StoreStats struct {
TotalFiles int `json:"total_files"`
TotalSize int64 `json:"total_size"`
Uploading int `json:"uploading"`
}
StoreStats 存储统计
type SyncFile ¶
type SyncFile struct {
ID string `json:"id"`
Filename string `json:"filename"`
Size int64 `json:"size"`
MimeType string `json:"mime_type"`
SHA256 string `json:"sha256"`
Path string `json:"path"`
Status string `json:"status"` // uploading, completed, failed
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
UserID string `json:"user_id,omitempty"`
}
SyncFile 已同步的文件
type SyncFileModel ¶
type SyncFileModel struct {
ID string `gorm:"primaryKey"`
Filename string `gorm:"not null"`
Size int64 `gorm:"not null"`
MimeType string `gorm:"column:mime_type"`
SHA256 string `gorm:"column:sha256"`
Path string `gorm:"not null"`
Status string `gorm:"default:completed"`
UserID string `gorm:"column:user_id;index"`
CreatedAt time.Time `gorm:"autoCreateTime"`
UpdatedAt time.Time `gorm:"autoUpdateTime"`
}
SyncFileModel 数据库模型
func (SyncFileModel) TableName ¶
func (SyncFileModel) TableName() string
type SyncStatus ¶
type SyncStatus struct {
Running bool `json:"running"`
StoragePath string `json:"storage_path"`
TotalFiles int `json:"total_files"`
TotalSize int64 `json:"total_size"`
Uploading int `json:"uploading"`
}
SyncStatus 同步服务状态
type UploadSession ¶
type UploadSession struct {
ID string `json:"id"`
FileID string `json:"file_id,omitempty"`
Filename string `json:"filename"`
Size int64 `json:"size"`
Offset int64 `json:"offset"`
Progress float64 `json:"progress"`
Metadata string `json:"metadata,omitempty"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at,omitempty"`
UserID string `json:"user_id,omitempty"`
}
UploadSession 上传会话 (断点续传)
type UploadSessionModel ¶
type UploadSessionModel struct {
ID string `gorm:"primaryKey"`
FileID string `gorm:"column:file_id"`
Filename string `gorm:"not null"`
Size int64 `gorm:"not null"`
Offset int64 `gorm:"default:0"`
Metadata string `gorm:"type:text"`
UserID string `gorm:"column:user_id;index"`
CreatedAt time.Time `gorm:"autoCreateTime"`
ExpiresAt time.Time
}
UploadSessionModel 上传会话数据库模型
func (UploadSessionModel) TableName ¶
func (UploadSessionModel) TableName() string
Click to show internal directories.
Click to hide internal directories.