diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2021-09-02 05:53:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-01 23:53:29 +0200 |
commit | 07fde28ddb9dd26dabb1c736f6a62fe642bb8003 (patch) | |
tree | e5c99f852c2791b7eb61fe1b01eadb6c3fe1384d | |
parent | 6e0e414f553279d0ee330b078637d2b163b85159 (diff) | |
download | gitea-07fde28ddb9dd26dabb1c736f6a62fe642bb8003.tar.gz gitea-07fde28ddb9dd26dabb1c736f6a62fe642bb8003.zip |
Fix wrong attachment removal (#16915)
-rw-r--r-- | web_src/js/index.js | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/web_src/js/index.js b/web_src/js/index.js index ba025cfade..5ea16f44f8 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -1030,7 +1030,7 @@ async function initRepository() { if ($dropzone.length === 1) { $dropzone.data('saved', false); - const filenameDict = {}; + const fileUuidDict = {}; dz = await createDropzone($dropzone[0], { url: $dropzone.data('upload-url'), headers: {'X-Csrf-Token': csrf}, @@ -1048,28 +1048,24 @@ async function initRepository() { thumbnailHeight: 480, init() { this.on('success', (file, data) => { - filenameDict[file.name] = { - uuid: data.uuid, + fileUuidDict[file.uuid] = { submitted: false }; const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid); $dropzone.find('.files').append(input); }); this.on('removedfile', (file) => { - if (!(file.name in filenameDict)) { - return; - } - $(`#${filenameDict[file.name].uuid}`).remove(); - if ($dropzone.data('remove-url') && !filenameDict[file.name].submitted) { + $(`#${file.uuid}`).remove(); + if ($dropzone.data('remove-url') && !fileUuidDict[file.uuid].submitted) { $.post($dropzone.data('remove-url'), { - file: filenameDict[file.name].uuid, + file: file.uuid, _csrf: csrf, }); } }); this.on('submit', () => { - $.each(filenameDict, (name) => { - filenameDict[name].submitted = true; + $.each(fileUuidDict, (fileUuid) => { + fileUuidDict[fileUuid].submitted = true; }); }); this.on('reload', () => { @@ -1082,9 +1078,8 @@ async function initRepository() { dz.emit('thumbnail', this, imgSrc); dz.emit('complete', this); dz.files.push(this); - filenameDict[this.name] = { + fileUuidDict[this.uuid] = { submitted: true, - uuid: this.uuid }; $dropzone.find(`img[src='${imgSrc}']`).css('max-width', '100%'); const input = $(`<input id="${this.uuid}" name="files" type="hidden">`).val(this.uuid); @@ -2695,7 +2690,6 @@ $(document).ready(async () => { // Dropzone for (const el of document.querySelectorAll('.dropzone')) { - const filenameDict = {}; const $dropzone = $(el); await createDropzone(el, { url: $dropzone.data('upload-url'), @@ -2713,18 +2707,15 @@ $(document).ready(async () => { thumbnailWidth: 480, thumbnailHeight: 480, init() { - this.on('success', (file, data) => { - filenameDict[file.name] = data.uuid; + this.on('success', (_file, data) => { const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid); $dropzone.find('.files').append(input); }); this.on('removedfile', (file) => { - if (file.name in filenameDict) { - $(`#${filenameDict[file.name]}`).remove(); - } + $(`#${file.uuid}`).remove(); if ($dropzone.data('remove-url')) { $.post($dropzone.data('remove-url'), { - file: filenameDict[file.name], + file: file.uuid, _csrf: csrf }); } |