Add the missing tmp hash to messages
authorAlexander Ebert <ebert@woltlab.com>
Wed, 14 Aug 2024 14:57:34 +0000 (16:57 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 14 Aug 2024 14:57:34 +0000 (16:57 +0200)
ts/WoltLabSuite/Core/Component/Attachment/List.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Component/Attachment/List.js

index fd4e8535d1e49b738421adf4517a4ab41aa0f13f..f1c418ecebd4e4de38c3780fdd3bccd4e5c9ca2c 100644 (file)
@@ -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<CkeditorDropEvent>("ckeditorDrop", {
-      detail: payload,
+  listenToCkeditor(editor)
+    .uploadAttachment((payload) => {
+      const event = new CustomEvent<CkeditorDropEvent>("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<HTMLElement>(".attachment__list__existingFiles");
   if (existingFiles !== null) {
index 1d0e01bd26ff9af83f2d9f6cf915d6ab3f7d1a5b..8d12aeebe471a5ebfb0c88abf65ae6fabbc4961a 100644 (file)
@@ -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) {