Documentation ¶
Index ¶
- Constants
- Variables
- func BackupDownFileEp(inb *miso.Inbound)
- func BootstrapServer(args []string)
- func CheckAllNormalFiles(fileIds []string) (bool, error)
- func CheckBackupAuth(rail miso.Rail, auth string) error
- func CheckFileExists(fileId string) (bool, error)
- func CopyChkSum(r io.Reader, w io.Writer) (int64, string, error)
- func CreateFileRec(rail miso.Rail, c CreateFile) error
- func DefBuf() []byte
- func DeleteFileEp(inb *miso.Inbound, req DeleteFileReq) (any, error)
- func DirectDownloadFileEp(inb *miso.Inbound)
- func DownloadFile(rail miso.Rail, w http.ResponseWriter, fileId string) error
- func DownloadFileKey(rail miso.Rail, w http.ResponseWriter, fileKey string) error
- func FastCheckFileExists(rail miso.Rail, fileId string) error
- func FileLockKey(fileId string) string
- func FindDuplicateFile(rail miso.Rail, db *gorm.DB, filename string, size int64, md5 string) (string, error)
- func GenFileId() string
- func GenFileKeyEp(inb *miso.Inbound, req DownloadFileReq) (string, error)
- func GenStoragePath(fileId string) string
- func GenTrashPath(fileId string) string
- func GetFileInfoEp(inb *miso.Inbound, req FileInfoReq) (api.FstoreFile, error)
- func InitStorageDir(rail miso.Rail) error
- func InitTrashDir(rail miso.Rail) error
- func LDelFile(rail miso.Rail, db *gorm.DB, fileId string) error
- func MigrateFileServer(rail miso.Rail) error
- func MultiCopyChkSum(r io.Reader, ws ...io.Writer) (int64, string, error)
- func NewUploadLock(rail miso.Rail, filename string, size int64, md5 string) *miso.RLock
- func OnUnzipFileEvent(rail miso.Rail, evt UnzipFileEvent) error
- func PhyDelFile(rail miso.Rail, db *gorm.DB, fileId string, op PDelFileOp) error
- func PrepareEventBus(rail miso.Rail) error
- func RandFileKey(rail miso.Rail, name string, fileId string) (string, error)
- func RefreshFileKeyExp(rail miso.Rail, fileKey string) error
- func RemoveDeletedFiles(rail miso.Rail, db *gorm.DB) error
- func RemoveDeletedFilesEp(inb *miso.Inbound) (any, error)
- func SanitizeStorage(rail miso.Rail) error
- func SanitizeStorageEp(inb *miso.Inbound) (any, error)
- func StreamFileKey(rail miso.Rail, w http.ResponseWriter, fileKey string, br ByteRange) error
- func TempKeyDownloadFileEp(inb *miso.Inbound)
- func TempKeyStreamFileEp(inb *miso.Inbound)
- func TransferFile(rail miso.Rail, w http.ResponseWriter, ff DFile, br ByteRange) error
- func TriggerUnzipFilePipeline(rail miso.Rail, db *gorm.DB, req api.UnzipFileReq) error
- func TryMigrateFileServer(rail miso.Rail) error
- func UnzipFileEp(inb *miso.Inbound, req api.UnzipFileReq) (any, error)
- func UploadFile(rail miso.Rail, rd io.Reader, filename string) (string, error)
- func UploadFileEp(inb *miso.Inbound) (string, error)
- type BackupFileInf
- type ByteRange
- type CachedFile
- type CreateFile
- type DFile
- type DeleteFileReq
- type DownloadFileReq
- type File
- type FileInfo
- type FileInfoReq
- type ListBackupFileReq
- type ListBackupFileResp
- type PDelFileDirectOp
- type PDelFileOp
- type PDelFileTrashOp
- type PendingPhyDelFile
- type SavedZipEntry
- type TableCol
- type UnpackedZipEntry
- type UnzipFileEvent
Constants ¶
const ( FileIdPrefix = "file_" // prefix of file_id StatusNormal = "NORMAL" // file.status - normal StatusLogicDel = "LOG_DEL" // file.status - logically deleted StatusPhysicDel = "PHY_DEL" // file.status - physically deleted PdelStrategyDirect = "direct" // file delete strategy - direct PdelStrategyTrash = "trash" // file delete strategy - trash ByteRangeMaxSize = 30_000_000 // 30 mb )
const ( FILE_ID_COL = "fstore_file_id" FILE_INFO_MIGR_SQL = "ALTER TABLE file_info ADD COLUMN fstore_file_id VARCHAR(32) NOT NULL DEFAULT '' COMMENT 'mini-fstore file id';" )
const ( PropStorageDir = "fstore.storage.dir" // where files are stored PropTrashDir = "fstore.trash.dir" // where files are dumped to PropTempDir = "fstore.tmp.dir" // temp directory PropPDelStrategy = "fstore.pdelete.strategy" // strategy used to 'physically' delete files PropSanitizeStorageTaskDryRun = "task.sanitize-storage-task.dry-run" // Enable dry run for SanitizeStorageTask PropEnableFstoreBackup = "fstore.backup.enabled" PropMigrFileServerEnabled = "fstore.migr.file-miso.enabled" // file-server migration enabled PropMigrFileServerDryRun = "fstore.migr.file-miso.dry-run" // dry run file-server migration PropMigrFileServerStorage = "fstore.migr.file-miso.storage" // location file-server's files, files are copied to mini-fstore's server manually PropMigrFileServerMySQLUser = "fstore.migr.file-miso.miso.user" // file-server's db mysql user PropMigrFileServerMySQLPwd = "fstore.migr.file-miso.miso.password" // file-server's db mysql password PropMigrFileServerMySQLDatabase = "fstore.migr.file-miso.miso.database" // file-server's db mysql schema name PropMigrFileServerMySQLHost = "fstore.migr.file-miso.miso.host" // file-server's db mysql host PropMigrFileServerMySQLPort = "fstore.migr.file-miso.miso.port" // file-server's db mysql port )
const (
DEFAULT_BUFFER_SIZE = int64(64 * 1024)
)
const (
PropBackupAuthSecret = "fstore.backup.secret"
)
const (
ResCodeFstoreUpload = "fstore-upload"
)
const (
UnzipPipelineEventBus = "mini-fstore.unzip.pipeline"
)
const (
Version = "v0.1.16"
)
Variables ¶
var ( ErrFileNotFound = miso.NewErrf("File is not found").WithCode(api.FileNotFound) ErrFileDeleted = miso.NewErrf("File has been deleted already").WithCode(api.FileDeleted) ErrUnknownError = miso.NewErrf("Unknown error").WithCode(api.UnknownError) ErrFileIdRequired = miso.NewErrf("fileId is required").WithCode(api.InvalidRequest) ErrFilenameRequired = miso.NewErrf("filename is required").WithCode(api.InvalidRequest) ErrNotZipFile = miso.NewErrf("Not a zip file").WithCode(api.IllegalFormat) )
var (
ErrInvalidAuth = miso.NewErrf("Invalid authorization").WithCode(api.InvalidAuthorization)
)
var ( UnzipResultCache = miso.NewRCache[api.UnzipFileReplyEvent]("mini-fstore:file:unzip:result", miso.RCacheConfig{ Exp: time.Minute * 15, }) )
Functions ¶
func BackupDownFileEp ¶
func BootstrapServer ¶
func BootstrapServer(args []string)
func CheckAllNormalFiles ¶
func CheckFileExists ¶
func CopyChkSum ¶
CopyChkSum copy data from reader to writer and calculate the md5 checksum on the fly.
return the transferred size in bytes and the md5 checksum
func DeleteFileEp ¶
func DeleteFileEp(inb *miso.Inbound, req DeleteFileReq) (any, error)
mark file deleted
func DirectDownloadFileEp ¶ added in v0.1.11
func DownloadFile ¶
Download file by file_id
func DownloadFileKey ¶
Download file by a generated random file key
func FastCheckFileExists ¶ added in v0.1.10
func FindDuplicateFile ¶
func GenFileKeyEp ¶
func GenFileKeyEp(inb *miso.Inbound, req DownloadFileReq) (string, error)
generate random file key for downloading the file
func GetFileInfoEp ¶
func GetFileInfoEp(inb *miso.Inbound, req FileInfoReq) (api.FstoreFile, error)
Get file's info
func MigrateFileServer ¶
Migrate from file-server
Files must be copied to mini-fstore's machine beforehand (at least somewhere mini-fstore can access).
The location of these files must be specified in property: 'fstore.migr.file-miso.storage'.
func MultiCopyChkSum ¶
CopyChkSum copy data from reader to multiple writer(s) and calculate the md5 checksum on the fly.
return the transferred size in bytes and the md5 checksum
func NewUploadLock ¶ added in v0.1.7
func OnUnzipFileEvent ¶ added in v0.1.7
func OnUnzipFileEvent(rail miso.Rail, evt UnzipFileEvent) error
func PhyDelFile ¶
Mark file as physically deleted by changing it's status
func PrepareEventBus ¶ added in v0.1.7
func RandFileKey ¶
Create random file key for the file
func RefreshFileKeyExp ¶
Refresh file key's expiration
func RemoveDeletedFiles ¶ added in v0.1.11
List logically deleted files, and based on the configured strategy, deleted them 'physically'.
This func reads property 'fstore.pdelete.strategy'.
If strategy is 'direct', files are deleted directly. If strategy is 'trash' (default), files are moved to 'trash' directory, which is specified in property 'fstore.trash.dir'
This func should only be used during server maintenance (no one can upload file).
func RemoveDeletedFilesEp ¶ added in v0.1.11
func SanitizeStorage ¶
func StreamFileKey ¶
Stream file by a generated random file key
func TempKeyDownloadFileEp ¶ added in v0.1.11
Download file
func TempKeyStreamFileEp ¶ added in v0.1.11
Stream file (support byte-range requests)
func TransferFile ¶
Transfer file
func TriggerUnzipFilePipeline ¶ added in v0.1.7
Trigger unzip file pipeline.
Unzipping is asynchrounous, the unzipped files are saved in mini-fstore, and the final result is replied to the specified event bus.
func TryMigrateFileServer ¶ added in v0.1.7
func UnzipFileEp ¶ added in v0.1.7
Types ¶
type BackupFileInf ¶
type ByteRange ¶
type ByteRange struct { Start int64 // start of byte range (inclusive) End int64 // end of byte range (inclusive) // contains filtered or unexported fields }
func ZeroByteRange ¶
func ZeroByteRange() ByteRange
type CachedFile ¶
func ResolveFileKey ¶
func ResolveFileKey(rail miso.Rail, fileKey string) (bool, CachedFile)
Resolve CachedFile for the given fileKey
type CreateFile ¶
type DFile ¶
func (*DFile) StoragePath ¶ added in v0.1.7
Return the actual storage path including symbolic link.
A file could be a symbolic link to another file (using field f.Link).
Be cautious if this path is used to delete/remove files (i.e., it shouldn't).
type DeleteFileReq ¶
type DeleteFileReq struct {
FileId string `form:"fileId" valid:"notEmpty" desc:"actual file_id of the file record"`
}
type DownloadFileReq ¶
type File ¶
type File struct { Id int64 `json:"id"` FileId string `json:"fileId"` Link string `json:"-"` Name string `json:"name"` Status string `json:"status"` Size int64 `json:"size"` Md5 string `json:"md5"` UplTime miso.ETime `json:"uplTime"` LogDelTime *miso.ETime `json:"logDelTime"` PhyDelTime *miso.ETime `json:"phyDelTime"` }
func ListLDelFile ¶
List logically deleted files
func (*File) IsLogiDeleted ¶
Check if the file is logically already
func (*File) StoragePath ¶ added in v0.1.7
Return the actual storage path including symbolic link.
A file could be a symbolic link to another file (using field f.Link).
Be cautious if this path is used to delete/remove files (i.e., it shouldn't).
type FileInfoReq ¶
type ListBackupFileReq ¶
type ListBackupFileResp ¶
type ListBackupFileResp struct {
Files []BackupFileInf
}
func BackupListFilesEp ¶
func BackupListFilesEp(inb *miso.Inbound, req ListBackupFileReq) (ListBackupFileResp, error)
func ListBackupFiles ¶
func ListBackupFiles(rail miso.Rail, tx *gorm.DB, req ListBackupFileReq) (ListBackupFileResp, error)
type PDelFileDirectOp ¶
type PDelFileDirectOp struct { }
The 'direct' implementation of of PDelFileOp, files are deleted directly
type PDelFileOp ¶
type PDelFileOp interface {
// contains filtered or unexported methods
}
func NewPDelFileOp ¶
func NewPDelFileOp(strategy string) PDelFileOp
type PDelFileTrashOp ¶
type PDelFileTrashOp struct { }
The 'trash' implementation of of PDelFileOp, files are deleted directly
type PendingPhyDelFile ¶
type SavedZipEntry ¶ added in v0.1.7
func SaveZipFile ¶ added in v0.1.7
func SaveZipFile(rail miso.Rail, db *gorm.DB, entry UnpackedZipEntry) (SavedZipEntry, error)
func SaveZipFiles ¶ added in v0.1.7
func SaveZipFiles(rail miso.Rail, db *gorm.DB, entries []UnpackedZipEntry) ([]SavedZipEntry, error)
func UnzipFile ¶ added in v0.1.7
func UnzipFile(rail miso.Rail, db *gorm.DB, evt UnzipFileEvent) ([]SavedZipEntry, error)