Browse Source

支持.tar.gz格式文件解压

Signed-off-by: zouap <zouap@pcl.ac.cn>
pull/435/head
zouap 3 years ago
parent
commit
5c0e4ed465
3 changed files with 13 additions and 6 deletions
  1. +1
    -1
      models/attachment.go
  2. +2
    -2
      modules/worker/task.go
  3. +10
    -3
      routers/repo/attachment.go

+ 1
- 1
models/attachment.go View File

@@ -378,7 +378,7 @@ func GetUnDecompressAttachments() ([]*Attachment, error) {

func getUnDecompressAttachments(e Engine) ([]*Attachment, error) {
attachments := make([]*Attachment, 0, 10)
return attachments, e.Where("decompress_state = ? and dataset_id != 0 and attachment.type = ? and name like '%.zip'", DecompressStateInit, TypeCloudBrainOne).Find(&attachments)
return attachments, e.Where("decompress_state = ? and dataset_id != 0 and attachment.type = ? and (name like '%.zip' or name like '%.tar.gz')", DecompressStateInit, TypeCloudBrainOne).Find(&attachments)
}

func GetAllPublicAttachments() ([]*AttachmentUsername, error) {


+ 2
- 2
modules/worker/task.go View File

@@ -13,8 +13,8 @@ const (
DecompressTaskName = "Decompress"
)

func SendDecompressTask(ctx context.Context, uuid string) error {
args := []tasks.Arg{{Name: "uuid", Type: "string", Value: uuid}}
func SendDecompressTask(ctx context.Context, uuid string, name string) error {
args := []tasks.Arg{{Name: "uuid", Type: "string", Value: uuid}, {Name: "name", Type: "string", Value: name}}
task, err := tasks.NewSignature(DecompressTaskName, args)
if err != nil {
log.Error("NewSignature failed:", err.Error())


+ 10
- 3
routers/repo/attachment.go View File

@@ -386,7 +386,7 @@ func AddAttachment(ctx *context.Context) {
if attachment.DatasetID != 0 {
if strings.HasSuffix(attachment.Name, ".zip") {
if typeCloudBrain == models.TypeCloudBrainOne {
err = worker.SendDecompressTask(contexExt.Background(), uuid)
err = worker.SendDecompressTask(contexExt.Background(), uuid, attachment.Name)
if err != nil {
log.Error("SendDecompressTask(%s) failed:%s", uuid, err.Error())
} else {
@@ -406,6 +406,13 @@ func AddAttachment(ctx *context.Context) {
})
}

func isCanDecompress(name string) bool {
if strings.HasSuffix(name, ".zip") || strings.HasSuffix(name, ".tar.gz") {
return true
}
return false
}

func UpdateAttachmentDecompressState(ctx *context.Context) {
uuid := ctx.Query("uuid")
result := ctx.Query("result")
@@ -768,7 +775,7 @@ func CompleteMultipart(ctx *context.Context) {
if attachment.DatasetID != 0 {
if strings.HasSuffix(attachment.Name, ".zip") {
if typeCloudBrain == models.TypeCloudBrainOne {
err = worker.SendDecompressTask(contexExt.Background(), uuid)
err = worker.SendDecompressTask(contexExt.Background(), uuid, attachment.Name)
if err != nil {
log.Error("SendDecompressTask(%s) failed:%s", uuid, err.Error())
} else {
@@ -838,7 +845,7 @@ func HandleUnDecompressAttachment() {
}

for _, attach := range attachs {
err = worker.SendDecompressTask(contexExt.Background(), attach.UUID)
err = worker.SendDecompressTask(contexExt.Background(), attach.UUID, attach.Name)
if err != nil {
log.Error("SendDecompressTask(%s) failed:%s", attach.UUID, err.Error())
} else {


Loading…
Cancel
Save