mirror of https://github.com/cloudreve/Cloudreve
feat: get file source link in batch
parent
4a4375a796
commit
1038bae238
2
assets
2
assets
|
@ -1 +1 @@
|
||||||
Subproject commit c4a7dfea2c05077e6e7c7042c8598886bf6f5531
|
Subproject commit e4ccca3e28f2df52646385ef3957e79f4d203f94
|
|
@ -31,6 +31,9 @@ type GroupOption struct {
|
||||||
ShareDownload bool `json:"share_download,omitempty"`
|
ShareDownload bool `json:"share_download,omitempty"`
|
||||||
Aria2 bool `json:"aria2,omitempty"` // 离线下载
|
Aria2 bool `json:"aria2,omitempty"` // 离线下载
|
||||||
Aria2Options map[string]interface{} `json:"aria2_options,omitempty"` // 离线下载用户组配置
|
Aria2Options map[string]interface{} `json:"aria2_options,omitempty"` // 离线下载用户组配置
|
||||||
|
SourceBatchSize int `json:"source_batch,omitempty"`
|
||||||
|
Aria2BatchSize int `json:"aria2_batch,omitempty"`
|
||||||
|
Aria2TaskSizeLimit uint64 `json:"aria2_size,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetGroupByID 用ID获取用户组
|
// GetGroupByID 用ID获取用户组
|
||||||
|
|
|
@ -108,6 +108,8 @@ func addDefaultGroups() {
|
||||||
ArchiveTask: true,
|
ArchiveTask: true,
|
||||||
ShareDownload: true,
|
ShareDownload: true,
|
||||||
Aria2: true,
|
Aria2: true,
|
||||||
|
SourceBatchSize: 1000,
|
||||||
|
Aria2BatchSize: 50,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := DB.Create(&defaultAdminGroup).Error; err != nil {
|
if err := DB.Create(&defaultAdminGroup).Error; err != nil {
|
||||||
|
@ -127,6 +129,8 @@ func addDefaultGroups() {
|
||||||
WebDAVEnabled: true,
|
WebDAVEnabled: true,
|
||||||
OptionsSerialized: GroupOption{
|
OptionsSerialized: GroupOption{
|
||||||
ShareDownload: true,
|
ShareDownload: true,
|
||||||
|
SourceBatchSize: 10,
|
||||||
|
Aria2BatchSize: 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := DB.Create(&defaultAdminGroup).Error; err != nil {
|
if err := DB.Create(&defaultAdminGroup).Error; err != nil {
|
||||||
|
|
|
@ -80,6 +80,8 @@ const (
|
||||||
CodeInvalidChunkIndex = 400012
|
CodeInvalidChunkIndex = 400012
|
||||||
// CodeInvalidContentLength 无效的正文长度
|
// CodeInvalidContentLength 无效的正文长度
|
||||||
CodeInvalidContentLength = 400013
|
CodeInvalidContentLength = 400013
|
||||||
|
// CodeBatchSourceSize 超出批量获取外链限制
|
||||||
|
CodeBatchSourceSize = 40014
|
||||||
// CodeDBError 数据库操作失败
|
// CodeDBError 数据库操作失败
|
||||||
CodeDBError = 50001
|
CodeDBError = 50001
|
||||||
// CodeEncryptError 加密失败
|
// CodeEncryptError 加密失败
|
||||||
|
|
|
@ -76,3 +76,11 @@ func BuildObjectList(parent uint, objects []Object, policy *model.Policy) Object
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sources 获取外链的结果响应
|
||||||
|
type Sources struct {
|
||||||
|
URL string `json:"url"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Parent uint `json:"parent"`
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ type group struct {
|
||||||
ShareDownload bool `json:"shareDownload"`
|
ShareDownload bool `json:"shareDownload"`
|
||||||
CompressEnabled bool `json:"compress"`
|
CompressEnabled bool `json:"compress"`
|
||||||
WebDAVEnabled bool `json:"webdav"`
|
WebDAVEnabled bool `json:"webdav"`
|
||||||
|
SourceBatchSize int `json:"sourceBatch"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type tag struct {
|
type tag struct {
|
||||||
|
@ -98,6 +99,7 @@ func BuildUser(user model.User) User {
|
||||||
ShareDownload: user.Group.OptionsSerialized.ShareDownload,
|
ShareDownload: user.Group.OptionsSerialized.ShareDownload,
|
||||||
CompressEnabled: user.Group.OptionsSerialized.ArchiveTask,
|
CompressEnabled: user.Group.OptionsSerialized.ArchiveTask,
|
||||||
WebDAVEnabled: user.Group.WebDAVEnabled,
|
WebDAVEnabled: user.Group.WebDAVEnabled,
|
||||||
|
SourceBatchSize: user.Group.OptionsSerialized.SourceBatchSize,
|
||||||
},
|
},
|
||||||
Tags: buildTagRes(tags),
|
Tags: buildTagRes(tags),
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,20 +121,6 @@ func GetSource(c *gin.Context) {
|
||||||
c.JSON(200, serializer.ParamErr("文件不存在", err))
|
c.JSON(200, serializer.ParamErr("文件不存在", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceURL, err := fs.GetSource(ctx, fileID.(uint))
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(200, serializer.Err(serializer.CodeNotSet, err.Error(), err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.JSON(200, serializer.Response{
|
|
||||||
Code: 0,
|
|
||||||
Data: struct {
|
|
||||||
URL string `json:"url"`
|
|
||||||
}{URL: sourceURL},
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Thumb 获取文件缩略图
|
// Thumb 获取文件缩略图
|
||||||
|
@ -143,18 +129,12 @@ func Thumb(c *gin.Context) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
fs, err := filesystem.NewFileSystemFromContext(c)
|
var service explorer.ItemIDService
|
||||||
if err != nil {
|
if err := c.ShouldBindJSON(&service); err == nil {
|
||||||
c.JSON(200, serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err))
|
res := service.Sources(ctx, c)
|
||||||
return
|
c.JSON(200, res)
|
||||||
}
|
} else {
|
||||||
defer fs.Recycle()
|
c.JSON(200, ErrorResponse(err))
|
||||||
|
|
||||||
// 获取文件ID
|
|
||||||
fileID, ok := c.Get("object_id")
|
|
||||||
if !ok {
|
|
||||||
c.JSON(200, serializer.ParamErr("文件不存在", err))
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取缩略图
|
// 获取缩略图
|
||||||
|
|
|
@ -558,7 +558,7 @@ func InitMasterRouter() *gin.Engine {
|
||||||
// 获取缩略图
|
// 获取缩略图
|
||||||
file.GET("thumb/:id", controllers.Thumb)
|
file.GET("thumb/:id", controllers.Thumb)
|
||||||
// 取得文件外链
|
// 取得文件外链
|
||||||
file.GET("source/:id", controllers.GetSource)
|
file.POST("source", controllers.GetSource)
|
||||||
// 打包要下载的文件
|
// 打包要下载的文件
|
||||||
file.POST("archive", controllers.Archive)
|
file.POST("archive", controllers.Archive)
|
||||||
// 创建文件压缩任务
|
// 创建文件压缩任务
|
||||||
|
|
|
@ -428,3 +428,40 @@ func (service *FileIDService) PutContent(ctx context.Context, c *gin.Context) se
|
||||||
Code: 0,
|
Code: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sources 批量获取对象的外链
|
||||||
|
func (s *ItemIDService) Sources(ctx context.Context, c *gin.Context) serializer.Response {
|
||||||
|
fs, err := filesystem.NewFileSystemFromContext(c)
|
||||||
|
if err != nil {
|
||||||
|
return serializer.Err(serializer.CodePolicyNotAllowed, "无法初始化文件系统", err)
|
||||||
|
}
|
||||||
|
defer fs.Recycle()
|
||||||
|
|
||||||
|
if len(s.Raw().Items) > fs.User.Group.OptionsSerialized.SourceBatchSize {
|
||||||
|
return serializer.Err(serializer.CodeBatchSourceSize, "超出批量获取外链的最大数量限制", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res := make([]serializer.Sources, 0, len(s.Raw().Items))
|
||||||
|
for _, id := range s.Raw().Items {
|
||||||
|
fs.FileTarget = []model.File{}
|
||||||
|
sourceURL, err := fs.GetSource(ctx, id)
|
||||||
|
if len(fs.FileTarget) > 0 {
|
||||||
|
current := serializer.Sources{
|
||||||
|
URL: sourceURL,
|
||||||
|
Name: fs.FileTarget[0].Name,
|
||||||
|
Parent: fs.FileTarget[0].FolderID,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
current.Error = err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
res = append(res, current)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return serializer.Response{
|
||||||
|
Code: 0,
|
||||||
|
Data: res,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue