Forráskód Böngészése

fix: Bugs in the attachment functionality (#1824)
Fixes #1824

Generated by OpenClaw bounty agent.

Signed-off-by: gittihub-jpg <rico@springer-mail.net>

gittihub-jpg 3 hónapja
szülő
commit
8a7f7a60a5
1 módosított fájl, 12 hozzáadás és 6 törlés
  1. 12 6
      js/privatebin.js

+ 12 - 6
js/privatebin.js

@@ -3157,6 +3157,11 @@ jQuery.PrivateBin = (function($) {
             if (!$attachment.length) {
                 return false;
             }
+            // Check if there are actual attachment data items (not just UI elements)
+            if (attachmentsData.length > 0) {
+                return true;
+            }
+            // Also check UI elements in case data was removed but UI wasn't updated
             return [...$attachment.children()].length > 0;
         };
 
@@ -3170,10 +3175,8 @@ jQuery.PrivateBin = (function($) {
          */
         me.hasAttachmentData = function()
         {
-            if ($attachment.length) {
-                return true;
-            }
-            return false;
+            // Check if there are actual attachment data items (not just UI elements)
+            return attachmentsData.length > 0;
         };
 
         /**
@@ -5181,7 +5184,7 @@ jQuery.PrivateBin = (function($) {
             const plainText = Editor.getText(),
                   format    = PasteViewer.getFormat(),
                   // the methods may return different values if no files are attached (null, undefined or false)
-                  files     = TopNav.getFileList() || AttachmentViewer.getFiles() || AttachmentViewer.hasAttachment();
+                  files     = TopNav.getFileList() || AttachmentViewer.getFiles() || AttachmentViewer.hasAttachmentData();
 
             // do not send if there is no data
             if (plainText.length === 0 && !files) {
@@ -5227,7 +5230,10 @@ jQuery.PrivateBin = (function($) {
                 };
             if (attachmentsData.length) {
                 cipherMessage['attachment'] = attachmentsData;
-                cipherMessage['attachment_name'] = AttachmentViewer.getFiles().map((fileInfo => fileInfo.name));
+                const fileNames = AttachmentViewer.getFiles();
+                if (fileNames && Array.isArray(fileNames)) {
+                    cipherMessage['attachment_name'] = fileNames.map((fileInfo => fileInfo.name));
+                }
             } else if (AttachmentViewer.hasAttachment()) {
                 // fall back to cloned part
                 let attachments = AttachmentViewer.getAttachments();