Documentation
¶
Index ¶
- Constants
- func GenerateFileStoragePath(purpose string, owner uint, fileExt string) string
- func GenerateFileStoragePathWithName(purpose string, owner uint, fileName string) string
- func GetPartCount(size int64, partSize int64) int64
- func InitDB(db *gorm.DB) error
- func SaveCopyFile(db *gorm.DB, fi *FileInfo) error
- func SaveTempFile(tempFile *TempFile) error
- func UploadFile(ctx context.Context, fi *FileInfo, r io.Reader) error
- type CheckMultipartUploadResponse
- type FileInfo
- func GetCompanyFileByID(db *gorm.DB, companyID, id uint) (*FileInfo, error)
- func GetFileByChunkHash(db *gorm.DB, hashstr string, size int64) (*FileInfo, error)
- func GetFileByHash(db *gorm.DB, hashstr string) (*FileInfo, error)
- func GetFileByID(db *gorm.DB, id uint) (*FileInfo, error)
- func GetFileByPublicURL(db *gorm.DB, publicURL string) (*FileInfo, error)
- type FileStatus
- type InitMultipartUploadRequest
- type LocalStorage
- func (ls *LocalStorage) CopyDir(storagePath, dest string) error
- func (ls *LocalStorage) DeleteFile(storagePath string) error
- func (ls *LocalStorage) GetPresignedURL(method, storagePath string) (string, error)
- func (ls *LocalStorage) GetPublicURL(storagePath string, _ bool) string
- func (ls *LocalStorage) ReadFile(storagePath string) (io.ReadCloser, error)
- func (ls *LocalStorage) Save(ctx context.Context, fi *FileInfo, r io.Reader) error
- type MinFs
- func (mfs *MinFs) CopyDir(storagePath, dest string) error
- func (mfs *MinFs) DeleteFile(storagePath string) error
- func (mfs *MinFs) GetPresignedURL(method, storagePath string) (string, error)
- func (mfs *MinFs) GetPublicURL(storagePath string, _ bool) string
- func (mfs *MinFs) ReadFile(storagePath string) (io.ReadCloser, error)
- func (mfs *MinFs) Save(ctx context.Context, fi *FileInfo, r io.Reader) error
- type Storager
- type TempFile
- type TencentCos
- func (tc *TencentCos) CompleteUploadTask(ctx context.Context, tempFile *TempFile) error
- func (tc *TencentCos) CopyDir(storagePath, dest string) error
- func (tc *TencentCos) DeleteFile(storagePath string) error
- func (tc *TencentCos) GetPresignedURL(method, storagePath string) (string, error)
- func (tc *TencentCos) GetPublicURL(storagePath string, temp bool) string
- func (tc *TencentCos) InitUploadTask(ctx context.Context, tempFile *TempFile) error
- func (tc *TencentCos) ListUploadExistsTrunk(ctx context.Context, tempFile *TempFile) ([]int, error)
- func (tc *TencentCos) ReadFile(storagePath string) (io.ReadCloser, error)
- func (tc *TencentCos) Save(ctx context.Context, fi *FileInfo, r io.Reader) error
- func (tc *TencentCos) UploadTrunk(ctx context.Context, tempFile *TempFile, partNumber int, r io.Reader, ...) error
- type Uploader
Constants ¶
const ( TableNameFileInfo = "core_upload_files" TableNameTempFile = "core_upload_files_tmp" )
const (
// SettingPrefix 配置前缀
SettingPrefix = "cos-"
)
Variables ¶
This section is empty.
Functions ¶
func GenerateFileStoragePath ¶
GenerateFileStoragePath 生成文件存储路径
func GenerateFileStoragePathWithName ¶ added in v1.3.2
GenerateFileStoragePathWithName 生成文件存储路径
Types ¶
type CheckMultipartUploadResponse ¶
type CheckMultipartUploadResponse struct {
// UploadID 上传ID, 用于后续上传分片
UploadID string `json:"upload_id"`
// PartSize 分片大小
PartSize int64 `json:"part_size"`
// PartCount 分片数量
PartCount int `json:"part_count"`
// PartNumbersUploaded 已上传的分片
PartNumbersUploaded []int `json:"uploaded"`
// PartNumbersNeedUpload 需要上传的分片
PartNumbersNeedUpload []int `json:"need_upload"`
// UploadStatus 上传状态
UploadStatus FileStatus `json:"upload_status"`
// FileInfo 文件信息
FileInfo *FileInfo `json:"file_info"`
}
CheckMultipartUploadResponse 检查分片上传响应
type FileInfo ¶
type FileInfo struct {
gorm.Model
// CompanyID 公司ID
CompanyID uint `gorm:"column:company_id" json:"company_id"`
// Uin 用户ID
Uin uint `gorm:"column:uin" json:"uin"`
// Purpose 用途分类
Purpose config.FilePurpose `gorm:"column:purpose;type:varchar(32)" json:"purpose"`
// Filename 原始文件名
Filename string `gorm:"column:filename;type:varchar(128)" json:"filename"`
// FileExt 文件扩展名
FileExt string `gorm:"column:file_ext;type:varchar(8)" json:"file_ext"`
// MIMEType MIME类型
MIMEType string `gorm:"column:mime_type" json:"mime_type"`
// Size 文件大小
Size int64 `gorm:"column:size" json:"size"`
// Hash 文件hash hashMethod:hashValue
Hash string `gorm:"column:hash;type:varchar(256);index" json:"hash"`
// ChunkHash is the hash of the chunk of the file.
ChunkHash string `gorm:"column:chunk_hash;type:varchar(64)" json:"chunk_hash"`
// StoragePath 存储的相对路径
StoragePath string `gorm:"column:path;type:varchar(128)" json:"-"`
// PublicURL 公网访问地址,如果为空,则表示只能通过预签名URL访问
PublicURL string `gorm:"column:public_url;type:varchar(256);index" json:"-"`
// CopyNumber 文件副本数量
CopyNumber int `gorm:"column:copy_number;type:int;default:1" json:"-"`
// Status 文件状态
Status FileStatus `gorm:"column:status;type:varchar(15);default:'normal'" json:"status"`
// ErrMsg 错误信息
ErrMsg string `gorm:"column:err_msg;type:varchar(256)" json:"err_msg"`
}
FileInfo .
func GetCompanyFileByID ¶
GetCompanyFileByID 通过id获取文件信息
func GetFileByChunkHash ¶
GetFileByChunkHash 通过hash获取文件信息
func GetFileByHash ¶
GetFileByHash 通过hash获取文件信息
func GetFileByPublicURL ¶
GetFileByPublicURL 通过publicURL获取文件信息
type FileStatus ¶
type FileStatus string
FileStatus 文件状态
const ( // FileStatusUnknown 未知 FileStatusUnknown FileStatus = "unknown" // FileStatusNormal 正常 FileStatusNormal FileStatus = "normal" // FileStatusDeleted 已删除 FileStatusDeleted FileStatus = "deleted" // FileStatusFailed 上传失败 FileStatusFailed FileStatus = "failed" // FileStatusUploading 上传中 FileStatusUploading FileStatus = "uploading" // FileStatusUploadWaitComp 上传等待完成 FileStatusUploadWaitComp FileStatus = "upload_wait_comp" // FileStatusUploadSuccess 上传成功 FileStatusUploadSuccess FileStatus = "upload_success" )
type InitMultipartUploadRequest ¶
type InitMultipartUploadRequest struct {
SHA1 string `json:"sha1"`
Size int64 `json:"size"`
Filename string `json:"filename"`
// 仅后台使用
CompanyID uint `json:"-"`
Uin uint `json:"-"`
EmployeeID uint `json:"-"`
UploadID string `json:"-"`
}
InitMultipartUploadRequest 分片上传请求
type LocalStorage ¶
type LocalStorage struct {
Dir string
// contains filtered or unexported fields
}
LocalStorage .
func NewLocalStorage ¶
func NewLocalStorage(cfg config.LocalStorageConfig) (*LocalStorage, error)
NewLocalStorage .
func (*LocalStorage) CopyDir ¶ added in v0.4.13
func (ls *LocalStorage) CopyDir(storagePath, dest string) error
CopyDir 复制文件或文件夹
func (*LocalStorage) DeleteFile ¶ added in v0.4.10
func (ls *LocalStorage) DeleteFile(storagePath string) error
DeleteFile 删除文件
func (*LocalStorage) GetPresignedURL ¶
func (ls *LocalStorage) GetPresignedURL(method, storagePath string) (string, error)
func (*LocalStorage) GetPublicURL ¶
func (ls *LocalStorage) GetPublicURL(storagePath string, _ bool) string
func (*LocalStorage) ReadFile ¶ added in v0.4.10
func (ls *LocalStorage) ReadFile(storagePath string) (io.ReadCloser, error)
ReadFile 获取文件内容
type MinFs ¶ added in v0.4.10
type MinFs struct {
// contains filtered or unexported fields
}
MinFs .
func NewMinFs ¶ added in v0.4.10
func NewMinFs(cfg config.MinossConfig, opt config.StorageOption) (*MinFs, error)
NewMinFs 初始化MinFs
func (*MinFs) DeleteFile ¶ added in v0.4.10
DeleteFile 删除文件
func (*MinFs) GetPresignedURL ¶ added in v0.4.10
GetPresignedURL 获取预签名URL
func (*MinFs) GetPublicURL ¶ added in v0.4.10
GetPublicURL 获取公共URL
type Storager ¶
type Storager interface {
Save(ctx context.Context, fi *FileInfo, data io.Reader) error
GetPublicURL(storagePath string, temp bool) string
GetPresignedURL(method, storagePath string) (string, error)
ReadFile(storagePath string) (io.ReadCloser, error)
// Stat(name string) (*FileInfo, error)
DeleteFile(storagePath string) error
CopyDir(storagePath, dest string) error
}
Storager .
type TempFile ¶
type TempFile struct {
gorm.Model
CompanyID uint `gorm:"column:company_id;index" json:"company_id"`
Uin uint `gorm:"column:uin;index" json:"uin"`
EmployeeID uint `gorm:"column:employee_id" json:"employee_id"`
// Purpose is the purpose of the file.
Purpose config.FilePurpose `gorm:"column:purpose;type:varchar(32)" json:"purpose"`
Filename string `gorm:"column:filename;type:varchar(128)" json:"filename"`
// FileExt is the extension of the file.
FileExt string `gorm:"column:file_ext;type:varchar(8)" json:"file_ext"`
MIMEType string `gorm:"column:mime_type" json:"mime_type"`
// Size is the size of the file.
Size int64 `gorm:"column:size" json:"size"`
// ChunkHash
ChunkHash string `gorm:"column:chunk_hash;type:varchar(64)" json:"chunk_hash"`
// StoragePath is the path of the file in the storage.
StoragePath string `gorm:"column:path;type:varchar(128)" json:"-"`
// PublicURL is the public URL of the file.
PublicURL string `gorm:"column:public_url;type:varchar(256)" json:"-"`
// ErrMsg is the error message of the file.
ErrMsg string `gorm:"column:err_msg;type:varchar(256)" json:"err_msg"`
// Annotations is the annotations of the file.
Annotations map[string]string `gorm:"-" json:"annotations"`
AnnotationsStr string `gorm:"column:annotations;type:varchar(255)" json:"-"`
// ThirdUploadID 对象存储的分片上传ID
ThirdUploadID string `gorm:"column:third_upload_id;type:varchar(128)" json:"-"`
// ExpiredAt 对象存储的分片上传ID过期时间
ExpiredAt time.Time `gorm:"column:expired_at" json:"-"`
// PartSize 对象存储的分片大小
PartSize int64 `gorm:"column:part_size" json:"-"`
// PartCount 对象存储的分片数量
PartCount int64 `gorm:"column:part_count" json:"-"`
}
TempFile 临时文件信息
func GetTempFileByHash ¶
GetTempFileByHash 根据hash获取临时文件
func GetTempFileByThirdUploadID ¶
GetTempFileByThirdUploadID 根据thirdUploadID获取临时文件
type TencentCos ¶
type TencentCos struct {
// contains filtered or unexported fields
}
TencentCos ..
func NewTencentCos ¶
func NewTencentCos(cfg config.TencentCOSConfig, opt config.StorageOption) (*TencentCos, error)
NewTencentCos .
func (*TencentCos) CompleteUploadTask ¶
func (tc *TencentCos) CompleteUploadTask(ctx context.Context, tempFile *TempFile) error
CompleteUploadTask .
func (*TencentCos) CopyDir ¶ added in v0.4.13
func (tc *TencentCos) CopyDir(storagePath, dest string) error
CopyDir 复制文件或文件夹
func (*TencentCos) DeleteFile ¶ added in v0.4.10
func (tc *TencentCos) DeleteFile(storagePath string) error
DeleteFile 删除文件
func (*TencentCos) GetPresignedURL ¶
func (tc *TencentCos) GetPresignedURL(method, storagePath string) (string, error)
GetPresignedURL 获取预签名URL
func (*TencentCos) GetPublicURL ¶
func (tc *TencentCos) GetPublicURL(storagePath string, temp bool) string
GetPublicURL .
func (*TencentCos) InitUploadTask ¶
func (tc *TencentCos) InitUploadTask(ctx context.Context, tempFile *TempFile) error
InitUploadTask .
func (*TencentCos) ListUploadExistsTrunk ¶
ListUploadExistsTrunk .
func (*TencentCos) ReadFile ¶ added in v0.4.10
func (tc *TencentCos) ReadFile(storagePath string) (io.ReadCloser, error)
ReadFile 获取文件内容
type Uploader ¶
type Uploader struct {
// contains filtered or unexported fields
}
Uploader 大文件分片上传
func GetUploader ¶
func GetUploader(ctx context.Context, logger *zap.SugaredLogger, group, key string, req InitMultipartUploadRequest) (*Uploader, error)
GetUploader 获取大文件上传器
func (*Uploader) CompleteUpload ¶
CompleteUpload 合并分片
func (*Uploader) ListTrunks ¶
func (u *Uploader) ListTrunks() (*CheckMultipartUploadResponse, error)
ListTrunks 列出分片