sync

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package sync 提供基于 TUS 协议的文件同步模块

Index

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 NewHandler

func NewHandler(service *Service) *Handler

NewHandler 创建处理器

func (*Handler) DeleteFile

func (h *Handler) DeleteFile(c *gin.Context)

DeleteFile 删除文件

func (*Handler) DownloadFile

func (h *Handler) DownloadFile(c *gin.Context)

DownloadFile 下载文件

func (*Handler) GetFile

func (h *Handler) GetFile(c *gin.Context)

GetFile 获取文件详情

func (*Handler) GetStatus

func (h *Handler) GetStatus(c *gin.Context)

GetStatus 获取服务状态

func (*Handler) GetUpload

func (h *Handler) GetUpload(c *gin.Context)

GetUpload 获取上传会话详情

func (*Handler) ListFiles

func (h *Handler) ListFiles(c *gin.Context)

ListFiles 获取文件列表

func (*Handler) ListUploads

func (h *Handler) ListUploads(c *gin.Context)

ListUploads 获取进行中的上传

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

type ListFilesResponse struct {
	Files []SyncFile `json:"files"`
	Total int        `json:"total"`
}

ListFilesResponse 文件列表响应

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module 文件同步模块

func New

func New() *Module

New 创建模块实例

func (*Module) Dependencies

func (m *Module) Dependencies() []string

Dependencies 返回依赖模块

func (*Module) ID

func (m *Module) ID() string

ID 返回模块ID

func (*Module) Init

func (m *Module) Init(ctx *module.Context) error

Init 初始化模块

func (*Module) Name

func (m *Module) Name() string

Name 返回模块名称

func (*Module) RegisterRoutes

func (m *Module) RegisterRoutes(r *gin.RouterGroup)

RegisterRoutes 注册路由

func (*Module) Start

func (m *Module) Start() error

Start 启动模块

func (*Module) Stop

func (m *Module) Stop() error

Stop 停止模块

func (*Module) Version

func (m *Module) Version() string

Version 返回模块版本

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service 文件同步服务

func NewService

func NewService(logger *zap.Logger, db *gorm.DB, dataDir string) *Service

NewService 创建服务实例

func (*Service) DeleteFile

func (s *Service) DeleteFile(id string) error

DeleteFile 删除文件

func (*Service) DownloadFile

func (s *Service) DownloadFile(id string) (string, string, error)

DownloadFile 获取文件下载路径

func (*Service) GetFile

func (s *Service) GetFile(id string) (*SyncFile, error)

GetFile 获取单个文件

func (*Service) GetStatus

func (s *Service) GetStatus() *SyncStatus

GetStatus 获取服务状态

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) Init

func (s *Service) Init() error

Init 初始化服务

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

Jump to

Keyboard shortcuts

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