@blocklet/editor 2.4.16 → 2.4.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -402,7 +402,7 @@ export const uploadFile = (editor) => {
|
|
|
402
402
|
editor.blur();
|
|
403
403
|
let selection = null;
|
|
404
404
|
// listen to all upload success
|
|
405
|
-
|
|
405
|
+
const handleUploadSuccess = ({ file, response }) => {
|
|
406
406
|
// missing the source: function-upload-file
|
|
407
407
|
if (file.source !== 'function-upload-file') {
|
|
408
408
|
const { data } = response;
|
|
@@ -436,7 +436,8 @@ export const uploadFile = (editor) => {
|
|
|
436
436
|
}, 10);
|
|
437
437
|
}
|
|
438
438
|
}
|
|
439
|
-
}
|
|
439
|
+
};
|
|
440
|
+
uploader.onUploadSuccess(preventDuplicateUploadSuccess(handleUploadSuccess));
|
|
440
441
|
// 点击 Uploader 中的 Done 后恢复 selection
|
|
441
442
|
uploader.onClose(() => {
|
|
442
443
|
if (selection) {
|
|
@@ -450,3 +451,19 @@ export const uploadFile = (editor) => {
|
|
|
450
451
|
throw new Error('Missing required `window.uploaderRef`');
|
|
451
452
|
}
|
|
452
453
|
};
|
|
454
|
+
// Avoid handling upload success multiple times for the same file within a short interval
|
|
455
|
+
// ref: https://github.com/blocklet/media-kit/issues/428
|
|
456
|
+
function preventDuplicateUploadSuccess(handler) {
|
|
457
|
+
let lastHandledTimestamp = 0;
|
|
458
|
+
let lastHandledFileHash = '';
|
|
459
|
+
return (...args) => {
|
|
460
|
+
const now = Date.now();
|
|
461
|
+
const fileHash = args[0]?.file?.hashFileName;
|
|
462
|
+
if (now - lastHandledTimestamp < 1000 && fileHash === lastHandledFileHash) {
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
lastHandledTimestamp = now;
|
|
466
|
+
lastHandledFileHash = fileHash;
|
|
467
|
+
handler(...args);
|
|
468
|
+
};
|
|
469
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/editor",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.18",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"ufo": "^1.5.4",
|
|
70
70
|
"url-join": "^4.0.1",
|
|
71
71
|
"zustand": "^4.5.5",
|
|
72
|
-
"@blocklet/pdf": "^2.4.
|
|
72
|
+
"@blocklet/pdf": "^2.4.18"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@babel/core": "^7.25.2",
|