| @@ -112,7 +112,7 @@ func DeleteAttachment(ctx *context.Context) { | |||||
| ctx.Error(403) | ctx.Error(403) | ||||
| return | return | ||||
| } | } | ||||
| err = models.DeleteAttachment(attach, true) | |||||
| err = models.DeleteAttachment(attach, false) | |||||
| if err != nil { | if err != nil { | ||||
| ctx.Error(500, fmt.Sprintf("DeleteAttachment: %v", err)) | ctx.Error(500, fmt.Sprintf("DeleteAttachment: %v", err)) | ||||
| return | return | ||||
| @@ -357,11 +357,25 @@ func GetSuccessChunks(ctx *context.Context) { | |||||
| return | 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{ | ctx.JSON(200, map[string]string{ | ||||
| "uuid": fileChunk.UUID, | "uuid": fileChunk.UUID, | ||||
| "uploaded": strconv.Itoa(fileChunk.IsUploaded), | "uploaded": strconv.Itoa(fileChunk.IsUploaded), | ||||
| "uploadID":fileChunk.UploadID, | "uploadID":fileChunk.UploadID, | ||||
| "chunks": string(chunks), | "chunks": string(chunks), | ||||
| "attachID": strconv.Itoa(int(attachID)), | |||||
| }) | }) | ||||
| } | } | ||||
| @@ -472,7 +486,7 @@ func CompleteMultipart(ctx *context.Context) { | |||||
| return | return | ||||
| } | } | ||||
| _, err = models.InsertAttachment(&models.Attachment{ | |||||
| attachment, err := models.InsertAttachment(&models.Attachment{ | |||||
| UUID: uuid, | UUID: uuid, | ||||
| UploaderID: ctx.User.ID, | UploaderID: ctx.User.ID, | ||||
| IsPrivate: true, | IsPrivate: true, | ||||
| @@ -486,6 +500,21 @@ func CompleteMultipart(ctx *context.Context) { | |||||
| return | 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{ | ctx.JSON(200, map[string]string{ | ||||
| "result_code": "0", | "result_code": "0", | ||||
| }) | }) | ||||
| @@ -3,6 +3,7 @@ | |||||
| {{template "repo/header" .}} | {{template "repo/header" .}} | ||||
| <form class="ui container" action="{{.Link}}" method="post"> | <form class="ui container" action="{{.Link}}" method="post"> | ||||
| <input name="id" value="{{.dataset.ID}}" type="hidden" /> | <input name="id" value="{{.dataset.ID}}" type="hidden" /> | ||||
| <div id="datasetId" datasetId="{{.dataset.ID}}"> | |||||
| {{.CsrfTokenHtml}} | {{.CsrfTokenHtml}} | ||||
| {{template "base/alert" .}} | {{template "base/alert" .}} | ||||
| <div class="ui stackable grid {{if .Error}}hide{{end}}" id="dataset-content"> | <div class="ui stackable grid {{if .Error}}hide{{end}}" id="dataset-content"> | ||||
| @@ -65,7 +66,6 @@ | |||||
| </div> | </div> | ||||
| <div class="dataset ui middle very relaxed page"> | <div class="dataset ui middle very relaxed page"> | ||||
| <div class="column"> | <div class="column"> | ||||
| <div id="datasetId" datasetId="{{.dataset.ID}}"> | |||||
| <div id="uploader"> | <div id="uploader"> | ||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| @@ -66,6 +66,7 @@ | |||||
| file.uuid = response.data.uuid; | file.uuid = response.data.uuid; | ||||
| file.uploaded = response.data.uploaded; | file.uploaded = response.data.uploaded; | ||||
| file.chunks = response.data.chunks; | file.chunks = response.data.chunks; | ||||
| file.attachID = response.data.attachID; | |||||
| resolve(response); | resolve(response); | ||||
| }).catch(function (error) { | }).catch(function (error) { | ||||
| console.log(error); | console.log(error); | ||||
| @@ -316,6 +317,9 @@ | |||||
| } else { | } else { | ||||
| if (file.uploaded == "1") { //已上传成功 | if (file.uploaded == "1") { //已上传成功 | ||||
| //秒传 | //秒传 | ||||
| if (file.attachID == "0") { //删除数据集记录,未删除文件 | |||||
| await addAttachment(file); | |||||
| } | |||||
| console.log("文件已上传完成"); | console.log("文件已上传完成"); | ||||
| //window.location.reload(); | //window.location.reload(); | ||||
| } else { | } else { | ||||
| @@ -323,6 +327,23 @@ | |||||
| this.multipartUpload(file); | 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) { | onFileProgress(rootFile, file, chunk) { | ||||