@blocklet/editor 2.4.30 → 2.4.31
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.
|
@@ -36,7 +36,7 @@ import { INSERT_FILE_COMMAND } from '../../../ext/FilePlugin';
|
|
|
36
36
|
import { $insertSubpageListing } from '../../../ext/SubpageListingPlugin/SubpageListingPlugin';
|
|
37
37
|
import { INSERT_PAGES_KIT_COMPONENT_COMMAND, usePagesKitComponents, } from '../../../ext/PagesKitComponent/PagesKitComponentPlugin';
|
|
38
38
|
import { icons } from '../../icons';
|
|
39
|
-
import { preventDuplicateUploadSuccess } from '../../utils/prevent-duplicate-upload';
|
|
39
|
+
import { clearRecentUploads, preventDuplicateUploadSuccess } from '../../utils/prevent-duplicate-upload';
|
|
40
40
|
class ComponentPickerOption extends TypeaheadOption {
|
|
41
41
|
// What shows up in the editor
|
|
42
42
|
title;
|
|
@@ -448,6 +448,7 @@ export const uploadFile = (editor) => {
|
|
|
448
448
|
uploader.onUploadSuccess(preventDuplicateUploadSuccess(handleUploadSuccess));
|
|
449
449
|
// 点击 Uploader 中的 Done 后恢复 selection
|
|
450
450
|
uploader.onClose(() => {
|
|
451
|
+
clearRecentUploads();
|
|
451
452
|
if (selection) {
|
|
452
453
|
editor.update(() => {
|
|
453
454
|
$setSelection(selection.clone());
|
|
@@ -2,28 +2,24 @@
|
|
|
2
2
|
// ref: https://github.com/blocklet/media-kit/issues/428
|
|
3
3
|
// Module-level array to store recent uploaded files with timestamps
|
|
4
4
|
const recentUploads = [];
|
|
5
|
-
const DUPLICATE_THRESHOLD_MS = 1000;
|
|
6
5
|
export function preventDuplicateUploadSuccess(handler) {
|
|
7
6
|
return (...args) => {
|
|
8
|
-
const now = Date.now();
|
|
9
7
|
const fileHash = args[0]?.file?.hashFileName;
|
|
10
8
|
if (!fileHash) {
|
|
11
9
|
handler(...args);
|
|
12
10
|
return;
|
|
13
11
|
}
|
|
14
12
|
// Check if this file was recently uploaded
|
|
15
|
-
const isDuplicate = recentUploads.some((record) => record.fileHash === fileHash
|
|
13
|
+
const isDuplicate = recentUploads.some((record) => record.fileHash === fileHash);
|
|
16
14
|
if (isDuplicate) {
|
|
17
15
|
return;
|
|
18
16
|
}
|
|
19
17
|
// Add new upload record
|
|
20
|
-
const newRecord = { fileHash
|
|
18
|
+
const newRecord = { fileHash };
|
|
21
19
|
recentUploads.push(newRecord);
|
|
22
|
-
// Clean up old records that are beyond the threshold
|
|
23
|
-
const cutoffTime = now - DUPLICATE_THRESHOLD_MS;
|
|
24
|
-
const filteredUploads = recentUploads.filter((record) => record.timestamp >= cutoffTime);
|
|
25
|
-
recentUploads.length = 0;
|
|
26
|
-
recentUploads.push(...filteredUploads);
|
|
27
20
|
handler(...args);
|
|
28
21
|
};
|
|
29
22
|
}
|
|
23
|
+
export function clearRecentUploads() {
|
|
24
|
+
recentUploads.length = 0;
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/editor",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.31",
|
|
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.31"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@babel/core": "^7.25.2",
|