Feat: archive & download routers for test
This commit is contained in:
parent
ba34a092d1
commit
e8aa0435c5
5 changed files with 64 additions and 4 deletions
|
@ -166,6 +166,10 @@ func addDefaultGroups() {
|
||||||
Color: "danger",
|
Color: "danger",
|
||||||
WebDAVEnabled: true,
|
WebDAVEnabled: true,
|
||||||
Aria2Option: "0,0,0",
|
Aria2Option: "0,0,0",
|
||||||
|
OptionsSerialized: GroupOption{
|
||||||
|
ArchiveDownloadEnabled: true,
|
||||||
|
ArchiveTaskEnabled: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
if err := DB.Create(&defaultAdminGroup).Error; err != nil {
|
if err := DB.Create(&defaultAdminGroup).Error; err != nil {
|
||||||
util.Log().Panic("无法创建管理用户组, %s", err)
|
util.Log().Panic("无法创建管理用户组, %s", err)
|
||||||
|
|
|
@ -1 +1,16 @@
|
||||||
package filesystem
|
package filesystem
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
/* ==============
|
||||||
|
压缩/解压缩
|
||||||
|
==============
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Compress 创建给定目录和文件的压缩文件
|
||||||
|
func (fs *FileSystem) Compress(ctx context.Context, dirs, files []uint) (io.ReadSeeker, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
|
@ -56,16 +56,16 @@ const (
|
||||||
CodeObjectExist = 40004
|
CodeObjectExist = 40004
|
||||||
// CodeSignExpired 签名过期
|
// CodeSignExpired 签名过期
|
||||||
CodeSignExpired = 40005
|
CodeSignExpired = 40005
|
||||||
|
// CodePolicyNotAllowed 当前存储策略不允许
|
||||||
|
CodePolicyNotAllowed = 40006
|
||||||
|
// CodeGroupNotAllowed 用户组无法进行此操作
|
||||||
|
CodeGroupNotAllowed = 40007
|
||||||
// CodeDBError 数据库操作失败
|
// CodeDBError 数据库操作失败
|
||||||
CodeDBError = 50001
|
CodeDBError = 50001
|
||||||
// CodeEncryptError 加密失败
|
// CodeEncryptError 加密失败
|
||||||
CodeEncryptError = 50002
|
CodeEncryptError = 50002
|
||||||
// CodePolicyNotAllowed 当前存储策略不允许
|
|
||||||
CodePolicyNotAllowed = 50003
|
|
||||||
// CodeIOFailed IO操作失败
|
// CodeIOFailed IO操作失败
|
||||||
CodeIOFailed = 50004
|
CodeIOFailed = 50004
|
||||||
// CodeGroupNotAllowed 当前用户组不允许
|
|
||||||
CodeGroupNotAllowed = 50005
|
|
||||||
//CodeParamErr 各种奇奇怪怪的参数错误
|
//CodeParamErr 各种奇奇怪怪的参数错误
|
||||||
CodeParamErr = 40001
|
CodeParamErr = 40001
|
||||||
// CodeNotSet 未定错误,后续尝试从error中获取
|
// CodeNotSet 未定错误,后续尝试从error中获取
|
||||||
|
|
21
pkg/task/pool.go
Normal file
21
pkg/task/pool.go
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
package task
|
||||||
|
|
||||||
|
type Pool struct {
|
||||||
|
// 容量
|
||||||
|
capacity int
|
||||||
|
// 终止信号
|
||||||
|
terminateSignal chan error
|
||||||
|
// 全部任务完成的信号
|
||||||
|
finishSignal chan bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type Worker interface {
|
||||||
|
Do() error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pool *Pool) Submit(worker Worker) {
|
||||||
|
err := worker.Do()
|
||||||
|
if err != nil {
|
||||||
|
close(pool.terminateSignal)
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package explorer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"github.com/HFO4/cloudreve/pkg/filesystem"
|
"github.com/HFO4/cloudreve/pkg/filesystem"
|
||||||
"github.com/HFO4/cloudreve/pkg/serializer"
|
"github.com/HFO4/cloudreve/pkg/serializer"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -28,6 +29,25 @@ type ItemService struct {
|
||||||
|
|
||||||
// ArchiveAndDownload 创建归档并下載文件
|
// ArchiveAndDownload 创建归档并下載文件
|
||||||
func (service *ItemService) ArchiveAndDownload(ctx context.Context, c *gin.Context) serializer.Response {
|
func (service *ItemService) ArchiveAndDownload(ctx context.Context, c *gin.Context) serializer.Response {
|
||||||
|
// 创建文件系统
|
||||||
|
fs, err := filesystem.NewFileSystemFromContext(c)
|
||||||
|
if err != nil {
|
||||||
|
return serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查用户组权限
|
||||||
|
if !fs.User.Group.OptionsSerialized.ArchiveDownloadEnabled {
|
||||||
|
return serializer.Err(serializer.CodeGroupNotAllowed, "当前用户组无法进行此操作", nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始压缩,获取压缩后的stream
|
||||||
|
rs, err := fs.Compress(ctx, service.Dirs, service.Items)
|
||||||
|
if err != nil {
|
||||||
|
return serializer.Err(serializer.CodeNotSet, "无法创建压缩文件", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(rs)
|
||||||
|
|
||||||
return serializer.Response{
|
return serializer.Response{
|
||||||
Code: 0,
|
Code: 0,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue