Documentation
¶
Index ¶
- Constants
- Variables
- func AddFilesToDB(files []FileAndMeta, db *bolt.DB) error
- func AddToFileChecked(files []*File) error
- func AscOrDesc(descending bool) string
- func CRC32Str36(s string) string
- func CheckNotAllowInBackup()
- func CopyFile(dstPath, srcPath string) error
- func CreateDatabase()
- func DamagedOfFileChecked(fcMap map[string]*FileChecked) (ids []string)
- func DatabaseFilesSize(db *bolt.DB) (fileN int, totalSize int64, err error)
- func DeleteFilesByID(ids []string, db *bolt.DB) error
- func DeleteFromFileChecked(ids []string) error
- func DeleteInDB(ids []string, db *bolt.DB) error
- func DirIsEmpty(dirpath string) (ok bool, err error)
- func DirIsNotEmpty(dirpath string) (ok bool, err error)
- func ExecutableDir() string
- func FileSizeToString(size float64, fixed int) string
- func FindOrphans() (fileOrphans, metaOrphans []string, err error)
- func FolderMustEmpty(folder string)
- func GetCwd() string
- func GetExePath() string
- func GetFilenamesBase(folder string) ([]string, error)
- func GetKeysAndIdsLength(bucketName []byte, db *bolt.DB) (keyAndLength map[string]int, err error)
- func IdsToNames(ids []string, db *bolt.DB) (names []string, err error)
- func InitFileChecked()
- func KeyExistsInBucket(key []byte, b *bolt.Bucket) bool
- func MakeFolders(verbose bool)
- func MkdirIfNotExists(name string) error
- func MustInWuliu()
- func NameToID(name string) string
- func NamesInBuffer() ([]string, error)
- func NamesInFiles() ([]string, error)
- func NamesInInput() ([]string, error)
- func NamesToIds(names []string) (ids []string)
- func Now() string
- func OpenDB(root string) (*bolt.DB, error)
- func PaddingRight(s, char string, length int) string
- func PathExists(name string) bool
- func PathNotExists(name string) (ok bool)
- func PrintErrorExit(err error)
- func PrintFilesIdList(files []*File)
- func PrintFilesMore(files []*File)
- func PrintFilesSimple(files []*File)
- func PrintList[T any](list []T)
- func PrintListWithSuffix[T any](list []T, suffix string)
- func PrintVersionExit(ok bool)
- func PrintWhereExit(ok bool)
- func PutToBucket(key, value []byte, b *bolt.Bucket) error
- func ReadFileChecked(root string) (fcMap map[string]*FileChecked, err error)
- func RebuildAlbumsBucket(files []*File, tx *bolt.Tx) error
- func RebuildCTimeBucket(db *bolt.DB) error
- func RebuildCollBucket(files []*File, tx *bolt.Tx) error
- func RebuildDatabase(root string)
- func RebuildKeywordsBucket(files []*File, tx *bolt.Tx) error
- func RebuildSomeBuckets(db *bolt.DB) error
- func RenameCTime(ctime, oldid, newid string, tx *bolt.Tx) error
- func StringSetToSlice(m map[string]bool) (keys []string)
- func StringSliceToSet(s []string) map[string]bool
- func TypeByFilename(filename string) (filetype string)
- func WrapErrors(allErrors ...error) (wrapped error)
- func WriteFile(name string, data []byte) error
- func WriteJSON(data any, filename string) ([]byte, error)
- func WriteMSGP(data any, filename string) error
- func WriteProjectInfo(info ProjectInfo) error
- type Base64String
- type EditFiles
- type File
- func FilesExistInDB(files []*File, db *bolt.DB) (existFiles []*File)
- func GetAllDocs(db *bolt.DB) (docs []*File, err error)
- func GetAllFiles(db *bolt.DB) (files []*File, err error)
- func GetAllFilesTx(tx *bolt.Tx) (files []*File, err error)
- func GetAllFilesTxMetadata() ([]*File, error)
- func GetAllPics(db *bolt.DB) (pics []*File, err error)
- func GetFileInBucket(id string, b *bolt.Bucket) (f File, err error)
- func GetFileInDB(id string, db *bolt.DB) (f File, err error)
- func GetFilesByIDs(ids []string, tx *bolt.Tx) (files []*File, err error)
- func GetFilesInBucket(pattern, mode string, bucketName []byte, db *bolt.DB) (files []*File, err error)
- func NewFile(name string) *File
- func NewFilesFrom(names []string, folder string) (files []*File, err error)
- func ReadFile(filePath string) (f File)
- type FileAndMeta
- type FileChecked
- type HexString
- type ProjectInfo
- type ProjectStatus
Constants ¶
const ( GB = 1 << 30 MB = 1024 * 1024 Day = 24 * 60 * 60 RFC3339 = "2006-01-02 15:04:05Z07:00" MIMEOctetStream = "application/octet-stream" NormalFilePerm = 0666 NormalDirPerm = 0750 RepoName = "Wuliu File Manager" RepoURL = "https://github.com/ahui2016/wuliu" ProjectInfoPath = "project.json" FileCheckedPath = "file_checked.json" DatabasePath = "project.db" )
const ( FILES = "files" METADATA = "metadata" INPUT = "input" BUFFER = "buffer" WEBPAGES = "webpages" TEMPLATES = "webpages/templates" RECYCLEBIN = "recyclebin" )
const (
DatabasePath = "project.sqlite.db"
)
Variables ¶
var ( FilesBucket = []byte("FilesBucket") FilenameBucket = []byte("FilenameBucket") ChecksumBucket = []byte("ChecksumBucket") SizeBucket = []byte("SizeBucket") TypeBucket = []byte("TypeBucket") LikeBucket = []byte("LikeBucket") LabelBucket = []byte("LabelBucket") NotesBucket = []byte("NotesBucket") KeywordsBucket = []byte("KeywordsBucket") CollectionsBucket = []byte("CollectionsBucket") AlbumsBucket = []byte("AlbumsBucket") CTimeBucket = []byte("CTimeBucket") UTimeBucket = []byte("UTimeBucket") )
var Buckets = [][]byte{ FilesBucket, FilenameBucket, ChecksumBucket, SizeBucket, TypeBucket, LikeBucket, LabelBucket, NotesBucket, KeywordsBucket, CollectionsBucket, AlbumsBucket, CTimeBucket, UTimeBucket, }
var DocsSuffixList = []string{
"html",
"htm",
"css",
"xml",
"atom",
"rss",
"txt",
"md",
"js",
"json",
"pdf",
}
DocsSuffixList 瀏覽器可預覽的文檔類型。
var Folders = []string{ FILES, METADATA, INPUT, BUFFER, WEBPAGES, TEMPLATES, RECYCLEBIN, }
Functions ¶
func AddFilesToDB ¶
func AddFilesToDB(files []FileAndMeta, db *bolt.DB) error
func AddToFileChecked ¶
func CheckNotAllowInBackup ¶
func CheckNotAllowInBackup()
func CreateDatabase ¶
func CreateDatabase()
func DamagedOfFileChecked ¶
func DamagedOfFileChecked(fcMap map[string]*FileChecked) (ids []string)
func DatabaseFilesSize ¶
func DeleteFilesByID ¶
DeleteFilesByID 尝试删除档案,包括档案本身, metadata 以及数据库条目。 注意,这里说的删除是将档案移动到专案根目录的 recyclebin 中, 如果 recyclebin 里有同名档案则直接覆盖。
func DeleteFromFileChecked ¶
func DirIsEmpty ¶
func DirIsNotEmpty ¶
func ExecutableDir ¶
func ExecutableDir() string
func FileSizeToString ¶
FileSizeToString 把文件大小转换为方便人类阅读的格式。 fixed 指定小数点后几位, 设为负数表示不限制小数位。
func FindOrphans ¶
func FolderMustEmpty ¶
func FolderMustEmpty(folder string)
func GetExePath ¶
func GetExePath() string
GetExePath returns the path name for the executable that started the current process.
func GetFilenamesBase ¶
GetFilenamesBase 假设 folder 里全是普通档案,没有资料夹。
func GetKeysAndIdsLength ¶
func InitFileChecked ¶
func InitFileChecked()
func MakeFolders ¶
func MakeFolders(verbose bool)
func MkdirIfNotExists ¶
MkdirIfNotExists 创建資料夹, 忽略 ErrExist. 在 Windows 里, 文件夹的只读属性不起作用, 为了统一行为, 不把資料夹设为只读.
func MustInWuliu ¶
func MustInWuliu()
func NamesInBuffer ¶
func NamesInFiles ¶
func NamesInInput ¶
func NamesToIds ¶
func PaddingRight ¶
func PathExists ¶
func PathNotExists ¶
func PrintErrorExit ¶
func PrintErrorExit(err error)
func PrintFilesIdList ¶
func PrintFilesIdList(files []*File)
func PrintFilesMore ¶
func PrintFilesMore(files []*File)
func PrintFilesSimple ¶
func PrintFilesSimple(files []*File)
func PrintListWithSuffix ¶
func PrintVersionExit ¶
func PrintVersionExit(ok bool)
func PrintWhereExit ¶
func PrintWhereExit(ok bool)
func ReadFileChecked ¶
func ReadFileChecked(root string) (fcMap map[string]*FileChecked, err error)
func RebuildCTimeBucket ¶
func RebuildSomeBuckets ¶
RebuildSomeBuckets 重建数据库的一部分索引,不需要读取硬盘。 由于不需要读取硬盘,因此不能反映最新的变化。
func RenameCTime ¶
RenameCTime 在更改檔案名稱時順便更新 CTimeBucket.
func StringSetToSlice ¶
func StringSliceToSet ¶
StringSliceToSet 用 map 當作 set
func WriteProjectInfo ¶
func WriteProjectInfo(info ProjectInfo) error
Types ¶
type Base64String ¶
type Base64String = string
type EditFiles ¶
type EditFiles struct { IDs []string `json:"ids"` // 通过 ID 指定档案 Filenames []string `json:"filenames"` // 通过档案名称指定档案 Like int `json:"like"` // 點贊 Label string `json:"label"` // 标签,便於搜尋 Notes string `json:"notes"` // 備註,便於搜尋 Keywords []string `json:"keywords"` // 關鍵詞, 便於搜尋 Collections []string `json:"collections"` // 集合(分组),一个档案可属于多个集合 Albums []string `json:"albums"` // 相册(专辑),主要用于图片和音乐 }
EditFiles 用于批量修改档案属性。
func NewEditFiles ¶
type File ¶
type File struct { ID string `json:"id"` // 档案名称的 CRC32 Filename string `json:"filename"` // 档案名称 Checksum string `json:"checksum"` // BLAKE2b Size int64 `json:"size"` // length in bytes for regular files Type string `json:"type"` // 檔案類型, 例: text/js, office/docx Like int `json:"like"` // 點贊 Label string `json:"label"` // 标签,便於搜尋 Notes string `json:"notes"` // 備註,便於搜尋 Keywords []string `json:"keywords"` // 關鍵詞, 便於搜尋 Collections []string `json:"collections"` // 集合(分组),一个档案可属于多个集合 Albums []string `json:"albums"` // 相册(专辑),主要用于图片和音乐 CTime string `json:"ctime"` // RFC3339 檔案入庫時間 UTime string `json:"utime"` // RFC3339 檔案更新時間 }
func GetAllFilesTxMetadata ¶
func GetFilesInBucket ¶
func GetFilesInBucket(pattern, mode string, bucketName []byte, db *bolt.DB) (files []*File, err error)
GetFilesInBucket, 其中 mode 是 exactly/contains/prefix/suffix 其中之一。
func NewFilesFrom ¶
NewFilesFrom 把档案名 (names) 转换为 files, 此时假设档案在 folder 资料夹内。
type FileAndMeta ¶
type FileChecked ¶
type HexString ¶
type HexString = string
func FileSum512 ¶
BLAKE2b is faster than MD5, SHA-1, SHA-2, and SHA-3, on 64-bit x86-64 and ARM architectures. https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE2 https://blog.min.io/fast-hashing-in-golang-using-blake2/ https://pkg.go.dev/crypto/sha256#example-New-File
type ProjectInfo ¶
type ProjectInfo struct { RepoName string // 用于判断资料夹是否 Wuliu 专案 ProjectName string // 备份时要求专案名称相同 IsBackup bool // 是否副本(副本禁止添加、删除等) Projects []string // 第一个是主专案,然后是备份专案 LastBackupAt []string // 上次备份时间 CheckInterval int // 检查完整性, 单位: day CheckSizeLimit int // 检查完整性, 单位: MB ExportSizeLimit int64 // 導出檔案體積上限,單位: MB ThumbSize [2]int // 縮略圖尺寸 }
func NewProjectInfo ¶
func NewProjectInfo(name string) (info ProjectInfo)
func ReadProjectInfo ¶
func ReadProjectInfo(root string) (info ProjectInfo)
type ProjectStatus ¶
type ProjectStatus struct { *ProjectInfo Root string // 专案根目录 TotalSize int64 // 全部檔案體積合計 FilesCount int // 檔案數量合計 DamagedCount int // 受損檔案數量合計 }