浏览代码

Merge remote-tracking branch 'origin/master' into js/removeJQuery

# Conflicts:
#	js/package-lock.json
#	js/package.json
#	js/privatebin.js
#	lib/Configuration.php

Co-authored-by: Junie <junie@jetbrains.com>
rugk 2 月之前
父节点
当前提交
7c576c326a
共有 4 个文件被更改,包括 230 次插入275 次删除
  1. 1 0
      CHANGELOG.md
  2. 163 230
      js/package-lock.json
  3. 2 1
      js/package.json
  4. 64 44
      js/privatebin.js

+ 1 - 0
CHANGELOG.md

@@ -1,6 +1,7 @@
 # PrivateBin version history
 
 ## 2.0.5 (not yet released)
+* FIXED: State corruption after "Remove attachment" (#1824)
 
 ## 2.0.4 (2026-05-03)
 * ADDED: Translations for Swedish & Persian

文件差异内容过多而无法显示
+ 163 - 230
js/package-lock.json


+ 2 - 1
js/package.json

@@ -10,9 +10,10 @@
     "@peculiar/webcrypto": "^1.5.0",
     "eslint": "^9.37.0",
     "fast-check": "^4.7.0",
-    "jsdom": "^26.0.0",
+    "jsdom": "^26.1.0",
     "jsdom-global": "^3.0.2",
     "jsverify": "^0.8.3",
+    "mime-types": "^3.0.2",
     "mocha": "^11.7.5",
     "nyc": "^17.1.0"
   },

+ 64 - 44
js/privatebin.js

@@ -2958,7 +2958,7 @@ window.PrivateBin = (function () {
          * @function
          */
         me.removeAttachmentData = function () {
-            files = undefined;
+            files = [];
             attachmentsData = [];
         };
 
@@ -4695,30 +4695,45 @@ window.PrivateBin = (function () {
                 qrCodeLink.addEventListener('click', displayQrCode);
             }
 
-            // bootstrap template drop downs
-            if (expiration) {
-                expiration.parentElement.querySelectorAll('ul.dropdown-menu li a').forEach(link => {
-                    link.addEventListener('click', updateExpiration);
-                });
-            }
-            if (formatter) {
-                formatter.parentElement.querySelectorAll('ul.dropdown-menu li a').forEach(link => {
-                    link.addEventListener('click', updateFormat);
-                });
-            }
+            if (Helper.isBootstrap5()) {
+                const pasteExpirationSelect = document.getElementById('pasteExpiration');
+                if (pasteExpirationSelect) {
+                    pasteExpirationSelect.addEventListener('change', function () {
+                        pasteExpiration = Model.getExpirationDefault();
+                    });
+                }
+                const pasteFormatterSelect = document.getElementById('pasteFormatter');
+                if (pasteFormatterSelect) {
+                    pasteFormatterSelect.addEventListener('change', function () {
+                        PasteViewer.setFormat(Model.getFormatDefault());
+                    });
+                }
+            } else {
+                // bootstrap template drop downs
+                if (expiration) {
+                    expiration.parentElement.querySelectorAll('ul.dropdown-menu li a').forEach(link => {
+                        link.addEventListener('click', updateExpiration);
+                    });
+                }
+                if (formatter) {
+                    formatter.parentElement.querySelectorAll('ul.dropdown-menu li a').forEach(link => {
+                        link.addEventListener('click', updateFormat);
+                    });
+                }
 
-            // bootstrap5 & page drop downs
-            const pasteExpirationSelect = document.getElementById('pasteExpiration');
-            if (pasteExpirationSelect) {
-                pasteExpirationSelect.addEventListener('change', function () {
-                    pasteExpiration = Model.getExpirationDefault();
-                });
-            }
-            const pasteFormatterSelect = document.getElementById('pasteFormatter');
-            if (pasteFormatterSelect) {
-                pasteFormatterSelect.addEventListener('change', function () {
-                    PasteViewer.setFormat(Model.getFormatDefault());
-                });
+                // page drop downs
+                const pasteExpirationSelect = document.getElementById('pasteExpiration');
+                if (pasteExpirationSelect) {
+                    pasteExpirationSelect.addEventListener('change', function () {
+                        pasteExpiration = Model.getExpirationDefault();
+                    });
+                }
+                const pasteFormatterSelect = document.getElementById('pasteFormatter');
+                if (pasteFormatterSelect) {
+                    pasteFormatterSelect.addEventListener('change', function () {
+                        PasteViewer.setFormat(Model.getFormatDefault());
+                    });
+                }
             }
 
             // initiate default state of checkboxes
@@ -4820,28 +4835,33 @@ window.PrivateBin = (function () {
          */
         me.run = function () {
             let isPost = Object.keys(data).length > 0,
-                ajaxParams = {
-                    type: isPost ? 'POST' : 'GET',
-                    url: url,
-                    headers: ajaxHeaders,
-                    dataType: 'json',
-                    success: function (result) {
-                        if (result.status === 0) {
-                            success(0, result);
-                        } else if (result.status === 1) {
-                            fail(1, result);
-                        } else {
-                            fail(2, result);
-                        }
-                    }
+                options = {
+                    method: isPost ? 'POST' : 'GET',
+                    headers: ajaxHeaders
                 };
             if (isPost) {
-                ajaxParams.data = JSON.stringify(data);
+                options.body = JSON.stringify(data);
             }
-            $.ajax(ajaxParams).fail(function (jqXHR, textStatus, errorThrown) {
-                console.error(textStatus, errorThrown);
-                fail(3, jqXHR);
-            });
+            fetch(url, options)
+                .then(response => {
+                    if (!response.ok) {
+                        throw response;
+                    }
+                    return response.json();
+                })
+                .then(result => {
+                    if (result.status === 0) {
+                        success(0, result);
+                    } else if (result.status === 1) {
+                        fail(1, result);
+                    } else {
+                        fail(2, result);
+                    }
+                })
+                .catch(error => {
+                    console.error(error);
+                    fail(3, error);
+                });
         };
 
         /**
@@ -5211,7 +5231,7 @@ window.PrivateBin = (function () {
                 };
             if (attachmentsData.length) {
                 cipherMessage['attachment'] = attachmentsData;
-                cipherMessage['attachment_name'] = AttachmentViewer.getFiles()?.map((fileInfo => fileInfo.name)) ?? [];
+                cipherMessage['attachment_name'] = AttachmentViewer.getFiles().map(fileInfo => fileInfo.name);
             } else if (AttachmentViewer.hasAttachment()) {
                 // fall back to cloned part
                 let attachments = AttachmentViewer.getAttachments();

部分文件因为文件数量过多而无法显示