From 2f14aa642aa3995514e7b25e45a02fa8fa82172e Mon Sep 17 00:00:00 2001 From: yuyuanshifu <747342561@qq.com> Date: Mon, 27 Jul 2020 14:14:17 +0800 Subject: [PATCH] del attachment --- routers/repo/attachment.go | 33 ++++++++++++++++++++++++++++-- templates/repo/datasets/index.tmpl | 2 +- web_src/js/App.vue | 21 +++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) 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" .}}
+
{{.CsrfTokenHtml}} {{template "base/alert" .}}
@@ -65,7 +66,6 @@
-
diff --git a/web_src/js/App.vue b/web_src/js/App.vue index d16699fbe..a30a30dc0 100755 --- a/web_src/js/App.vue +++ b/web_src/js/App.vue @@ -66,6 +66,7 @@ file.uuid = response.data.uuid; file.uploaded = response.data.uploaded; file.chunks = response.data.chunks; + file.attachID = response.data.attachID; resolve(response); }).catch(function (error) { console.log(error); @@ -316,6 +317,9 @@ } else { if (file.uploaded == "1") { //已上传成功 //秒传 + if (file.attachID == "0") { //删除数据集记录,未删除文件 + await addAttachment(file); + } console.log("文件已上传完成"); //window.location.reload(); } else { @@ -323,6 +327,23 @@ this.multipartUpload(file); } } + + function addAttachment(file){ + return new Promise((resolve, reject) => { + axios.post('/attachments/add', qs.stringify({ + uuid: file.uuid, + file_name: file.name, + size: file.size, + dataset_id: file.datasetId, + _csrf: csrf + })).then(function (response) { + resolve(response); + }).catch(function (error) { + console.log(error); + reject(error); + }); + }) + } }, // 文件进度的回调 onFileProgress(rootFile, file, chunk) {