From 9493cd07a8bed10887735fd4315b7954d5f1d1af Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 14 Aug 2024 16:57:34 +0200 Subject: [PATCH] Add the missing tmp hash to messages --- .../Core/Component/Attachment/List.ts | 31 ++++++++++++++++--- .../Core/Component/Attachment/List.js | 19 +++++++++++- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/ts/WoltLabSuite/Core/Component/Attachment/List.ts b/ts/WoltLabSuite/Core/Component/Attachment/List.ts index fd4e8535d1..f1c418eceb 100644 --- a/ts/WoltLabSuite/Core/Component/Attachment/List.ts +++ b/ts/WoltLabSuite/Core/Component/Attachment/List.ts @@ -11,6 +11,10 @@ function fileToAttachment(fileList: HTMLElement, file: WoltlabCoreFileElement, e fileList.append(createAttachmentFromFile(file, editor)); } +type Context = { + tmpHash: string; +}; + export function setup(editorId: string): void { const container = document.getElementById(`attachments_${editorId}`); if (container === null) { @@ -42,12 +46,29 @@ export function setup(editorId: string): void { fileToAttachment(fileList!, event.detail, editor); }); - listenToCkeditor(editor).uploadAttachment((payload) => { - const event = new CustomEvent("ckeditorDrop", { - detail: payload, + listenToCkeditor(editor) + .uploadAttachment((payload) => { + const event = new CustomEvent("ckeditorDrop", { + detail: payload, + }); + uploadButton.dispatchEvent(event); + }) + .collectMetaData((payload) => { + let context: Context | undefined = undefined; + try { + if (uploadButton.dataset.context !== undefined) { + context = JSON.parse(uploadButton.dataset.context); + } + } catch (e) { + if (window.ENABLE_DEBUG_MODE) { + console.warn("Unable to parse the context.", e); + } + } + + if (context !== undefined) { + payload.metaData.tmpHash = context.tmpHash; + } }); - uploadButton.dispatchEvent(event); - }); const existingFiles = container.querySelector(".attachment__list__existingFiles"); if (existingFiles !== null) { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Attachment/List.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Attachment/List.js index 1d0e01bd26..8d12aeebe4 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Attachment/List.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Attachment/List.js @@ -31,11 +31,28 @@ define(["require", "exports", "./Entry", "../Ckeditor/Event", "../File/woltlab-c uploadButton.addEventListener("uploadStart", (event) => { fileToAttachment(fileList, event.detail, editor); }); - (0, Event_1.listenToCkeditor)(editor).uploadAttachment((payload) => { + (0, Event_1.listenToCkeditor)(editor) + .uploadAttachment((payload) => { const event = new CustomEvent("ckeditorDrop", { detail: payload, }); uploadButton.dispatchEvent(event); + }) + .collectMetaData((payload) => { + let context = undefined; + try { + if (uploadButton.dataset.context !== undefined) { + context = JSON.parse(uploadButton.dataset.context); + } + } + catch (e) { + if (window.ENABLE_DEBUG_MODE) { + console.warn("Unable to parse the context.", e); + } + } + if (context !== undefined) { + payload.metaData.tmpHash = context.tmpHash; + } }); const existingFiles = container.querySelector(".attachment__list__existingFiles"); if (existingFiles !== null) { -- 2.20.1