diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index a35eb7745..416815e50 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -112,7 +112,7 @@ func DeleteAttachment(ctx *context.Context) { ctx.Error(403) return } - err = models.DeleteAttachment(attach, true) + err = models.DeleteAttachment(attach, false) if err != nil { ctx.Error(500, fmt.Sprintf("DeleteAttachment: %v", err)) return @@ -357,11 +357,25 @@ func GetSuccessChunks(ctx *context.Context) { return } + var attachID int64 + attach, err := models.GetAttachmentByUUID(fileChunk.UUID) + if err != nil { + if models.IsErrAttachmentNotExist(err) { + attachID = 0 + } else { + ctx.ServerError("GetAttachmentByUUID", err) + return + } + } else { + attachID = attach.ID + } + ctx.JSON(200, map[string]string{ "uuid": fileChunk.UUID, "uploaded": strconv.Itoa(fileChunk.IsUploaded), "uploadID":fileChunk.UploadID, "chunks": string(chunks), + "attachID": strconv.Itoa(int(attachID)), }) } @@ -472,7 +486,7 @@ func CompleteMultipart(ctx *context.Context) { return } - _, err = models.InsertAttachment(&models.Attachment{ + attachment, err := models.InsertAttachment(&models.Attachment{ UUID: uuid, UploaderID: ctx.User.ID, IsPrivate: true, @@ -486,6 +500,21 @@ func CompleteMultipart(ctx *context.Context) { return } + if attachment.DatasetID != 0 { + if strings.HasSuffix(attachment.Name, ".zip") { + err = worker.SendDecompressTask(contexExt.Background(), uuid) + if err != nil { + log.Error("SendDecompressTask(%s) failed:%s", uuid, err.Error()) + } else { + attachment.DecompressState = models.DecompressStateIng + err = models.UpdateAttachment(attachment) + if err != nil { + log.Error("UpdateAttachment state(%s) failed:%s", uuid, err.Error()) + } + } + } + } + ctx.JSON(200, map[string]string{ "result_code": "0", }) diff --git a/templates/repo/datasets/index.tmpl b/templates/repo/datasets/index.tmpl index d4d015708..da5058c39 100755 --- a/templates/repo/datasets/index.tmpl +++ b/templates/repo/datasets/index.tmpl @@ -3,6 +3,7 @@ {{template "repo/header" .}}