Browse Source

del attachment

tags/vopendata0.1.2
yuyuanshifu 5 years ago
parent
commit
2f14aa642a
3 changed files with 53 additions and 3 deletions
  1. +31
    -2
      routers/repo/attachment.go
  2. +1
    -1
      templates/repo/datasets/index.tmpl
  3. +21
    -0
      web_src/js/App.vue

+ 31
- 2
routers/repo/attachment.go View File

@@ -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",
})


+ 1
- 1
templates/repo/datasets/index.tmpl View File

@@ -3,6 +3,7 @@
{{template "repo/header" .}}
<form class="ui container" action="{{.Link}}" method="post">
<input name="id" value="{{.dataset.ID}}" type="hidden" />
<div id="datasetId" datasetId="{{.dataset.ID}}">
{{.CsrfTokenHtml}}
{{template "base/alert" .}}
<div class="ui stackable grid {{if .Error}}hide{{end}}" id="dataset-content">
@@ -65,7 +66,6 @@
</div>
<div class="dataset ui middle very relaxed page">
<div class="column">
<div id="datasetId" datasetId="{{.dataset.ID}}">
<div id="uploader">
</div>
</div>


+ 21
- 0
web_src/js/App.vue View File

@@ -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) {


Loading…
Cancel
Save