Feat: OneDrive 策略外链
This commit is contained in:
parent
d764157d87
commit
7c1ff19406
4 changed files with 13 additions and 7 deletions
|
@ -101,7 +101,7 @@ func (fs *FileSystem) GetPhysicalFileContent(ctx context.Context, path string) (
|
|||
// isText - 是否为文本文件,文本文件会忽略重定向,直接由
|
||||
// 服务端拉取中转给用户,故会对文件大小进行限制
|
||||
func (fs *FileSystem) Preview(ctx context.Context, id uint, isText bool) (*response.ContentResponse, error) {
|
||||
err := fs.resetFileIDIfNotExist(ctx, id)
|
||||
err := fs.ResetFileIDIfNotExist(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ func (fs *FileSystem) GetContent(ctx context.Context, id uint) (response.RSClose
|
|||
return nil, err
|
||||
}
|
||||
|
||||
err = fs.resetFileIDIfNotExist(ctx, id)
|
||||
err = fs.ResetFileIDIfNotExist(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ func (fs *FileSystem) GroupFileByPolicy(ctx context.Context, files []model.File)
|
|||
|
||||
// GetDownloadURL 创建文件下载链接, timeout 为数据库中存储过期时间的字段
|
||||
func (fs *FileSystem) GetDownloadURL(ctx context.Context, id uint, timeout string) (string, error) {
|
||||
err := fs.resetFileIDIfNotExist(ctx, id)
|
||||
err := fs.ResetFileIDIfNotExist(ctx, id)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ func (fs *FileSystem) GetDownloadURL(ctx context.Context, id uint, timeout strin
|
|||
// GetSource 获取可直接访问文件的外链地址
|
||||
func (fs *FileSystem) GetSource(ctx context.Context, fileID uint) (string, error) {
|
||||
// 查找文件记录
|
||||
err := fs.resetFileIDIfNotExist(ctx, fileID)
|
||||
err := fs.ResetFileIDIfNotExist(ctx, fileID)
|
||||
if err != nil {
|
||||
return "", ErrObjectNotExist.WithError(err)
|
||||
}
|
||||
|
@ -308,7 +308,7 @@ func (fs *FileSystem) ResetFileIfNotExist(ctx context.Context, path string) erro
|
|||
}
|
||||
|
||||
// ResetFileIfNotExist 重设当前目标文件为 id,如果当前目标为空
|
||||
func (fs *FileSystem) resetFileIDIfNotExist(ctx context.Context, id uint) error {
|
||||
func (fs *FileSystem) ResetFileIDIfNotExist(ctx context.Context, id uint) error {
|
||||
// 找到文件
|
||||
if len(fs.FileTarget) == 0 {
|
||||
file, err := model.GetFilesByIDs([]uint{id}, fs.User.ID)
|
||||
|
|
|
@ -592,7 +592,7 @@ func TestFileSystem_ResetFileIDIfNotExist(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
asserts.Equal(ErrObjectNotExist, fs.resetFileIDIfNotExist(ctx, 1))
|
||||
asserts.Equal(ErrObjectNotExist, fs.ResetFileIDIfNotExist(ctx, 1))
|
||||
}
|
||||
|
||||
func TestFileSystem_Search(t *testing.T) {
|
||||
|
|
|
@ -24,7 +24,7 @@ var HandledExtension = []string{"jpg", "jpeg", "png", "gif"}
|
|||
// GetThumb 获取文件的缩略图
|
||||
func (fs *FileSystem) GetThumb(ctx context.Context, id uint) (*response.ContentResponse, error) {
|
||||
// 根据 ID 查找文件
|
||||
err := fs.resetFileIDIfNotExist(ctx, id)
|
||||
err := fs.ResetFileIDIfNotExist(ctx, id)
|
||||
if err != nil || fs.FileTarget[0].PicInfo == "" {
|
||||
return &response.ContentResponse{
|
||||
Redirect: false,
|
||||
|
|
|
@ -168,6 +168,12 @@ func (service *FileAnonymousGetService) Download(ctx context.Context, c *gin.Con
|
|||
return serializer.Err(serializer.CodeNotSet, err.Error(), err)
|
||||
}
|
||||
|
||||
// 查找文件记录
|
||||
err = fs.ResetFileIDIfNotExist(ctx, service.ID)
|
||||
if err != nil {
|
||||
return serializer.Err(serializer.CodeNotSet, err.Error(), err)
|
||||
}
|
||||
|
||||
if fs.Policy.Type == "onedrive" {
|
||||
// 获取文件临时下载地址
|
||||
downloadURL, err := fs.GetDownloadURL(ctx, 0, "download_timeout")
|
||||
|
|
Loading…
Add table
Reference in a new issue