model

package
v0.0.0-...-453d458 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GB              = 1 << 30
	Day             = 24 * 60 * 60
	RFC3339         = "2006-01-02 15:04:05Z07:00"
	MIMEOctetStream = "application/octet-stream"
)

Variables

View Source
var IdForbidPattern = regexp.MustCompile(`[^0-9a-zA-Z._\-]`)

ID 只能使用 0-9, a-z, A-Z, _(下劃線), -(連字號), .(點)

Functions

func FilesToString

func FilesToString(files []File) string

FilesToString 把多个檔案转换为多个檔案的 ID 的字符串.

func Now

func Now() string

Now return time.Now().Format(RFC3339)

Types

type Bucket

type Bucket struct {
	// 自增數字ID
	ID int64 `json:"id"`

	// 倉庫資料夾名, 不分大小寫.
	// 只能使用 0-9, a-z, A-Z, _(下劃線), -(連字號), .(點)
	Name string `json:"name"`

	// 倉庫標題和副標題, 可使用任何語言任意字符.
	// 其中, Title 在數據庫中是 COLLATE NOCASE UNIQUE.
	Title    string `json:"title"`
	Subtitle string `json:"subtitle"`

	// 是否加密 (在創建時決定, 不可更改) (密碼在 ProjectConfig 中統一設定)
	Encrypted bool `json:"encrypted"`
}

Bucket 倉庫

func NewBucket

func NewBucket(form *CreateBucketForm) (*Bucket, error)

func (*Bucket) CheckName

func (bucket *Bucket) CheckName() error

type BucketStatus

type BucketStatus struct {
	*Bucket
	TotalSize  int64
	FilesCount int64
}

type ChangePwdForm

type ChangePwdForm struct {
	OldPassword string `json:"old_password" validate:"required"`
	NewPassword string `json:"new_password" validate:"required"`
}

type CreateBucketForm

type CreateBucketForm struct {
	Name      string `json:"name"      validate:"required"`
	Encrypted bool   `json:"encrypted"`
}

CreateBucketForm 用於新建倉庫, 由前端傳給后端.

type ErrSameNameFiles

type ErrSameNameFiles struct {
	File    File   `json:"file"`
	ErrType string `json:"errType"`
}

func NewErrSameNameFiles

func NewErrSameNameFiles(file File) ErrSameNameFiles

func (ErrSameNameFiles) Error

func (e ErrSameNameFiles) Error() string

type File

type File struct {
	ID         int64  `json:"id"`          // 自增數字ID
	Checksum   string `json:"checksum"`    // NOT NULL UNIQUE
	BucketName string `json:"bucket_name"` // Bucket.Name
	Name       string `json:"name"`        // 檔案名
	Notes      string `json:"notes"`       // 備註
	Keywords   string `json:"keywords"`    // 關鍵詞, 便於搜尋
	Size       int64  `json:"size"`        // length in bytes for regular files
	Type       string `json:"type"`        // 檔案類型, 例: text/js, office/docx
	Like       int64  `json:"like"`        // 點贊
	CTime      string `json:"ctime"`       // RFC3339 檔案入庫時間
	UTime      string `json:"utime"`       // RFC3339 檔案更新時間
	Checked    string `json:"checked"`     // RFC3339 上次校驗檔案完整性的時間
	Damaged    bool   `json:"damaged"`     // 上次校驗結果 (檔案是否損壞)
	Deleted    bool   `json:"deleted"`     // 把檔案标记为 "已删除"
}

File 檔案. Notes 與 Keywords 本質上是一樣的, 只是一行字符串, 用來輔助搜尋.

func NewWaitingFile

func NewWaitingFile(filePath string) (*File, error)

NewWaitingFile 根据 filePath 生成新檔案, 其中 filePath 是等待上传的檔案的路径.

func (*File) CanBePreviewed

func (f *File) CanBePreviewed() bool

添加 音频/视频 支持

func (*File) ImportFrom

func (f *File) ImportFrom(f2 FileExportImport)

func (*File) IsAudio

func (f *File) IsAudio() bool

func (*File) IsImage

func (f *File) IsImage() bool

func (*File) IsPDF

func (f *File) IsPDF() bool

func (*File) IsText

func (f *File) IsText() bool

func (*File) IsVideo

func (f *File) IsVideo() bool

func (*File) Rename

func (f *File) Rename(name string)

type FileExportImport

type FileExportImport struct {
	BucketName string
	Notes      string
	Keywords   string
	Like       int64
	CTime      string
	UTime      string
}

func ExportFileFrom

func ExportFileFrom(f File) FileExportImport

func ImportFileFrom

func ImportFileFrom(tomlPath string) (imported FileExportImport, err error)

type FileIdForm

type FileIdForm struct {
	ID int64 `json:"id" params:"id" validate:"required,gt=0"`
}

FileIdForm 同時也用於 bucket id.

type FileIdRangeForm

type FileIdRangeForm struct {
	Start int64 `json:"start" params:"start" validate:"required,gt=0"`
	End   int64 `json:"end"   params:"end"   validate:"required,gt=0"`
}

type FilePlus

type FilePlus struct {
	File
	Encrypted bool `json:"encrypted"`
}

FilePlus 檔案以及更多資訊.

type FilesOptions

type FilesOptions struct {
	ID    int64  `json:"id"   params:"id"`
	Name  string `json:"name" params:"name"`
	Sort  string `json:"sort" params:"sort"`
	UTime string `json:"utime" params:"utime"`
}

type MoveFileToBucketForm

type MoveFileToBucketForm struct {
	FileID     int64  `json:"file_id"     validate:"required,gt=0"`
	BucketName string `json:"bucket_name" validate:"required"`
}

type MovedFile

type MovedFile struct {
	Src string
	Dst string
}

func (*MovedFile) Move

func (m *MovedFile) Move() error

Move calls os.Rename, moves the file from Src to Dst.

func (*MovedFile) Rollback

func (m *MovedFile) Rollback() error

Rollback moves the file from Dst back to Src.

type OneTextForm

type OneTextForm struct {
	Text string `json:"text" validate:"required"`
}

type Project

type Project struct {
	Host             string   `json:"host"`
	Title            string   `json:"title"`
	Subtitle         string   `json:"subtitle"`
	CipherKey        string   `json:"cipherkey"` // 被加密的真正密鑰
	ApiDelay         int64    `json:"api_delay"` // 後端 API 延遲, 單位: 毫秒
	RecentFilesLimit int64    `json:"recent_files_limit"`
	CheckInterval    int64    `json:"check_interval"`   // 檢查周期, 單位: day
	CheckSizeLimit   int64    `json:"check_size_limit"` // 每次檢查檔案體積上限, 單位: GB
	IsBackup         bool     `json:"is_backup"`
	BackupProjects   []string `json:"backup_projects"`
	LastBackupAt     string   `json:"last_backup_at"`  // RFC3339
	DownloadExport   bool     `json:"download_export"` // 下載時導出
	MarkdownStyle    string   `json:"markdown_style"`
}

Project 專案

func NewProject

func NewProject(title string, cipherkey string) *Project

type ProjectStatus

type ProjectStatus struct {
	*Project
	Root              string // 专案根目录
	TotalSize         int64  // 全部檔案體積合計
	FilesCount        int64  // 檔案數量合計
	WaitingCheckCount int64  // 待檢查檔案數量合計
	DamagedCount      int64  // 受損檔案數量合計
}

type RenameWaitingFileForm

type RenameWaitingFileForm struct {
	OldName string `json:"old_name" validate:"required"`
	NewName string `json:"new_name" validate:"required"`
}

type UpdateFileInfoForm

type UpdateFileInfoForm struct {
	ID       int64  `json:"id"       validate:"required,gt=0"`
	Name     string `json:"name"     validate:"required"`
	Notes    string `json:"notes"`
	Keywords string `json:"keywords"`
	Like     int64  `json:"like"`
	CTime    string `json:"ctime"    validate:"required"`
	UTime    string `json:"utime"`
}

Jump to

Keyboard shortcuts

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