@widgetic/file-browser 0.5.48 → 0.5.49
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.
- package/dist/actions/dragSelectedToFolder.js +115 -104
- package/dist/components/FolderTree.svelte.d.ts +7 -4
- package/dist/components/core/FileBrowser.svelte +1 -3
- package/dist/components/core/dropzoneClick.js +2 -3
- package/dist/components/previews/FilePreview.svelte.d.ts +2 -2
- package/dist/config.js +3 -4
- package/dist/i18n/context.js +2 -2
- package/dist/i18n/errors.js +1 -2
- package/dist/i18n/messages.js +2 -2
- package/dist/i18n/text.js +2 -2
- package/dist/mediaLibrary/capabilities.js +3 -4
- package/dist/mediaLibrary/context.js +3 -4
- package/dist/mediaLibrary/errors.js +35 -46
- package/dist/mediaLibrary/normalize.js +42 -45
- package/dist/mediaLibrary/paging.js +45 -100
- package/dist/mediaLibrary/resolve.js +95 -214
- package/dist/mediaLibrary/treeOps.js +20 -40
- package/dist/mediaLibrary/urls.js +10 -12
- package/dist/mediaLibrary/widgetic.js +54 -140
- package/dist/stores/dragStore.js +1 -1
- package/dist/stores/fileStore.d.ts +3 -3
- package/dist/stores/fileStore.js +37 -44
- package/dist/stores/folderCountStore.js +11 -12
- package/dist/stores/missingFilesStore.js +3 -3
- package/dist/stores/navigationStore.d.ts +1 -1
- package/dist/stores/navigationStore.js +178 -217
- package/dist/stores/persistentSelectStore.d.ts +1 -1
- package/dist/stores/persistentSelectStore.js +94 -117
- package/dist/stores/searchStore.js +1 -1
- package/dist/stores/uploadApiStore.js +7 -7
- package/dist/stores/viewportStore.js +4 -4
- package/dist/types/index.js +1 -0
- package/dist/utils/apiConfig.js +9 -9
- package/dist/utils/brandKitLibraryTree.js +42 -57
- package/dist/utils/dateUtils.js +9 -11
- package/dist/utils/dragToFolder/batchMoveResult.js +54 -114
- package/dist/utils/dragToFolder/folderDropTarget.js +17 -23
- package/dist/utils/dragToFolder/springStep.js +3 -4
- package/dist/utils/fileGoneProbe.js +16 -65
- package/dist/utils/fileKinds.js +13 -14
- package/dist/utils/fileNames.js +7 -7
- package/dist/utils/fileOperations.js +332 -440
- package/dist/utils/fileTypes.js +14 -19
- package/dist/utils/fileUtils.js +31 -85
- package/dist/utils/folderUtils.js +4 -5
- package/dist/utils/gridLayout.js +7 -7
- package/dist/utils/imagePreviewCache.js +15 -26
- package/dist/utils/imagePreviewFrame.js +13 -13
- package/dist/utils/imagePreviewVisualState.js +4 -5
- package/dist/utils/imageTransform.js +14 -27
- package/dist/utils/itemMenuCapabilities.js +7 -7
- package/dist/utils/libraryTree.js +39 -55
- package/dist/utils/pendingUploadDeletes.js +113 -289
- package/dist/utils/previewKeys.js +1 -1
- package/dist/utils/previewListNavigation.js +11 -13
- package/dist/utils/previewNavigation.js +7 -10
- package/dist/utils/recentFiles.js +6 -16
- package/dist/utils/recentFilesLimit.js +2 -2
- package/dist/utils/removeItems.js +29 -61
- package/dist/utils/resolveFileUrl.js +6 -6
- package/dist/utils/safeText.js +12 -14
- package/dist/utils/searchDropdownPhase.js +2 -2
- package/dist/utils/searchItems.js +14 -30
- package/dist/utils/searchNavigation.js +5 -5
- package/dist/utils/uploadAuth.js +36 -111
- package/dist/utils/uploadDisplayProgress.js +1 -1
- package/dist/utils/uploadLimits.js +66 -138
- package/dist/utils/uploadListReconcile.js +11 -24
- package/dist/utils/uploadPanelDismiss.js +1 -1
- package/dist/utils/uploadPanelProgress.js +4 -4
- package/dist/utils/uploadProgressMath.js +11 -13
- package/dist/utils/uploadRefusals.js +24 -40
- package/dist/utils/uploadResponseMapping.js +8 -9
- package/dist/utils/uploadUiHelpers.js +17 -17
- package/dist/utils/userUploadsStorage.js +133 -270
- package/dist/utils/videoFrame.js +2 -2
- package/dist/utils/widgeticDelete.js +30 -103
- package/dist/utils/widgeticTusUpload.js +105 -189
- package/dist/utils/widgeticUpload.js +62 -130
- package/dist/utils/xhrMultipartUpload.js +116 -164
- package/package.json +1 -1
package/dist/utils/dateUtils.js
CHANGED
|
@@ -4,23 +4,21 @@ import { translateEnglish } from '../i18n/context';
|
|
|
4
4
|
* Format a date as month, day and year ("Oct 5, 2026"). The month's name and the order of the three follow `locale`
|
|
5
5
|
* (a BCP 47 tag like "de" or "pt-BR"; the File Browser's own locale when called from a screen).
|
|
6
6
|
*/
|
|
7
|
-
export function formatDate(date, locale) {
|
|
8
|
-
|
|
9
|
-
var dateObj = typeof date === 'string' ? new Date(date) : date;
|
|
7
|
+
export function formatDate(date, locale = 'en-US') {
|
|
8
|
+
const dateObj = typeof date === 'string' ? new Date(date) : date;
|
|
10
9
|
return new Intl.DateTimeFormat(locale, { month: 'short', day: 'numeric', year: 'numeric' }).format(dateObj);
|
|
11
10
|
}
|
|
12
11
|
/**
|
|
13
12
|
* Format a date relative to the current time ("2 days ago"). The words come from the File Browser's messages: pass the
|
|
14
13
|
* `t` of the screen to have them in the page's language (English when left out).
|
|
15
14
|
*/
|
|
16
|
-
export function formatRelativeDate(date, translate) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var monthsAgo = differenceInMonths(now, inputDate);
|
|
15
|
+
export function formatRelativeDate(date, translate = translateEnglish) {
|
|
16
|
+
const now = new Date();
|
|
17
|
+
const inputDate = new Date(date);
|
|
18
|
+
const hoursAgo = differenceInHours(now, inputDate);
|
|
19
|
+
const daysAgo = differenceInDays(now, inputDate);
|
|
20
|
+
const weeksAgo = differenceInWeeks(now, inputDate);
|
|
21
|
+
const monthsAgo = differenceInMonths(now, inputDate);
|
|
24
22
|
if (hoursAgo < 1) {
|
|
25
23
|
return translate('date.fewSecondsAgo');
|
|
26
24
|
}
|
|
@@ -1,48 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
38
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
39
|
-
if (ar || !(i in from)) {
|
|
40
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
41
|
-
ar[i] = from[i];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
45
|
-
};
|
|
46
1
|
import { ENDPOINTS } from '../apiConfig';
|
|
47
2
|
import { findItemById, moveItems } from '../fileOperations';
|
|
48
3
|
import { MediaLibraryError } from '../../mediaLibrary/errors';
|
|
@@ -51,22 +6,20 @@ import { fileStore } from '../../stores/fileStore';
|
|
|
51
6
|
import { getNavigationStore } from '../../stores/navigationStore';
|
|
52
7
|
import { persistentSelectStore } from '../../stores/persistentSelectStore';
|
|
53
8
|
function actualTargetId(targetFolderId) {
|
|
54
|
-
|
|
9
|
+
const root = get(fileStore).root;
|
|
55
10
|
if (targetFolderId === 'root' || (root && targetFolderId === root.id)) {
|
|
56
11
|
return '';
|
|
57
12
|
}
|
|
58
13
|
return targetFolderId;
|
|
59
14
|
}
|
|
60
15
|
function findFolderPath(root, targetId) {
|
|
61
|
-
|
|
62
|
-
if (path === void 0) { path = []; }
|
|
16
|
+
const search = (folder, path = []) => {
|
|
63
17
|
if (folder.id === targetId)
|
|
64
18
|
return path;
|
|
65
19
|
if (folder.children) {
|
|
66
|
-
for (
|
|
67
|
-
var child = _a[_i];
|
|
20
|
+
for (const child of folder.children) {
|
|
68
21
|
if (child.type === 'folder') {
|
|
69
|
-
|
|
22
|
+
const result = search(child, [...path, child.id]);
|
|
70
23
|
if (result !== null)
|
|
71
24
|
return result;
|
|
72
25
|
}
|
|
@@ -80,68 +33,55 @@ function findFolderPath(root, targetId) {
|
|
|
80
33
|
* Commits a batch move (API when needed, then one atomic tree update).
|
|
81
34
|
* Mirrors MoveDialog semantics.
|
|
82
35
|
*/
|
|
83
|
-
export function commitBatchMove(args) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
failedCount = 0;
|
|
114
|
-
apiResults.forEach(function (result, index) {
|
|
115
|
-
var sourceItem = sourceItems[index];
|
|
116
|
-
if (result.status === 'fulfilled' && result.value.success) {
|
|
117
|
-
idsToMove.push(sourceItem.id);
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
failedCount += 1;
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
if (idsToMove.length === 0) {
|
|
124
|
-
return [2 /*return*/, { ok: false, movedIds: [], failedCount: failedCount }];
|
|
125
|
-
}
|
|
126
|
-
movedIds = moveItems(idsToMove, actualTarget);
|
|
127
|
-
if (movedIds.length === 0) {
|
|
128
|
-
throw new MediaLibraryError('FAILED', 'Tree update failed after move', {
|
|
129
|
-
messageKey: 'moveDialog.noneMoved'
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
root = get(fileStore).root;
|
|
133
|
-
targetPath = actualTarget ? findFolderPath(root, actualTarget) : [];
|
|
134
|
-
for (_i = 0, movedIds_1 = movedIds; _i < movedIds_1.length; _i++) {
|
|
135
|
-
id = movedIds_1[_i];
|
|
136
|
-
movedItem = findItemById(id);
|
|
137
|
-
if ((movedItem === null || movedItem === void 0 ? void 0 : movedItem.type) === 'folder') {
|
|
138
|
-
newParentPath = targetPath !== null && targetPath !== void 0 ? targetPath : [];
|
|
139
|
-
navigationStore.updateMovedFolderPaths(movedItem.id, newParentPath);
|
|
140
|
-
}
|
|
141
|
-
persistentSelectStore.removeSelection(id, currentFilter);
|
|
142
|
-
}
|
|
143
|
-
return [2 /*return*/, { ok: failedCount === 0, movedIds: movedIds, failedCount: failedCount }];
|
|
144
|
-
}
|
|
145
|
-
});
|
|
36
|
+
export async function commitBatchMove(args) {
|
|
37
|
+
const { sourceItems, targetFolderId, localOnly, currentFilter, navigationStoreId } = args;
|
|
38
|
+
if (sourceItems.length === 0) {
|
|
39
|
+
return { ok: false, movedIds: [], failedCount: 0 };
|
|
40
|
+
}
|
|
41
|
+
const actualTarget = actualTargetId(targetFolderId);
|
|
42
|
+
const navigationStore = getNavigationStore(navigationStoreId);
|
|
43
|
+
const moveEndpoint = typeof window !== 'undefined' && import.meta.env.DEV
|
|
44
|
+
? '/api/files/move'
|
|
45
|
+
: ENDPOINTS.FILE_MOVE;
|
|
46
|
+
const apiResults = await Promise.allSettled(sourceItems.map((sourceItem) => localOnly
|
|
47
|
+
? Promise.resolve({ success: true })
|
|
48
|
+
: fetch(moveEndpoint, {
|
|
49
|
+
method: 'POST',
|
|
50
|
+
headers: { 'Content-Type': 'application/json' },
|
|
51
|
+
body: JSON.stringify({
|
|
52
|
+
itemId: sourceItem.id,
|
|
53
|
+
targetFolderId: actualTarget
|
|
54
|
+
})
|
|
55
|
+
}).then((response) => response.json())));
|
|
56
|
+
const idsToMove = [];
|
|
57
|
+
let failedCount = 0;
|
|
58
|
+
apiResults.forEach((result, index) => {
|
|
59
|
+
const sourceItem = sourceItems[index];
|
|
60
|
+
if (result.status === 'fulfilled' && result.value.success) {
|
|
61
|
+
idsToMove.push(sourceItem.id);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
failedCount += 1;
|
|
65
|
+
}
|
|
146
66
|
});
|
|
67
|
+
if (idsToMove.length === 0) {
|
|
68
|
+
return { ok: false, movedIds: [], failedCount };
|
|
69
|
+
}
|
|
70
|
+
const movedIds = moveItems(idsToMove, actualTarget);
|
|
71
|
+
if (movedIds.length === 0) {
|
|
72
|
+
throw new MediaLibraryError('FAILED', 'Tree update failed after move', {
|
|
73
|
+
messageKey: 'moveDialog.noneMoved'
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const root = get(fileStore).root;
|
|
77
|
+
const targetPath = actualTarget ? findFolderPath(root, actualTarget) : [];
|
|
78
|
+
for (const id of movedIds) {
|
|
79
|
+
const movedItem = findItemById(id);
|
|
80
|
+
if (movedItem?.type === 'folder') {
|
|
81
|
+
const newParentPath = targetPath ?? [];
|
|
82
|
+
navigationStore.updateMovedFolderPaths(movedItem.id, newParentPath);
|
|
83
|
+
}
|
|
84
|
+
persistentSelectStore.removeSelection(id, currentFilter);
|
|
85
|
+
}
|
|
86
|
+
return { ok: failedCount === 0, movedIds, failedCount };
|
|
147
87
|
}
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
const FOLDER_TARGET_ATTR = 'data-folder-drop-target';
|
|
2
2
|
/** Walk `elementsFromPoint` and return the nearest folder drop target. */
|
|
3
|
-
export function resolveFolderDropTarget(clientX, clientY, root) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var elements = doc.elementsFromPoint(clientX, clientY);
|
|
8
|
-
for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) {
|
|
9
|
-
var el = elements_1[_i];
|
|
3
|
+
export function resolveFolderDropTarget(clientX, clientY, root = document) {
|
|
4
|
+
const doc = root instanceof Document ? root : root.ownerDocument ?? document;
|
|
5
|
+
const elements = doc.elementsFromPoint(clientX, clientY);
|
|
6
|
+
for (const el of elements) {
|
|
10
7
|
if (!(el instanceof HTMLElement))
|
|
11
8
|
continue;
|
|
12
|
-
|
|
9
|
+
const match = el.closest(`[${FOLDER_TARGET_ATTR}]`);
|
|
13
10
|
if (match instanceof HTMLElement) {
|
|
14
|
-
|
|
11
|
+
const folderId = match.getAttribute(FOLDER_TARGET_ATTR);
|
|
15
12
|
if (folderId) {
|
|
16
|
-
return { folderId
|
|
13
|
+
return { folderId, element: match };
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
16
|
}
|
|
@@ -22,8 +19,7 @@ export function resolveFolderDropTarget(clientX, clientY, root) {
|
|
|
22
19
|
function folderDescendantIds(folder, into) {
|
|
23
20
|
if (folder.type !== 'folder' || !folder.children)
|
|
24
21
|
return;
|
|
25
|
-
for (
|
|
26
|
-
var child = _a[_i];
|
|
22
|
+
for (const child of folder.children) {
|
|
27
23
|
if (child.type === 'folder') {
|
|
28
24
|
into.add(child.id);
|
|
29
25
|
folderDescendantIds(child, into);
|
|
@@ -31,16 +27,15 @@ function folderDescendantIds(folder, into) {
|
|
|
31
27
|
}
|
|
32
28
|
}
|
|
33
29
|
function isDescendantOf(folderId, ancestorId, root) {
|
|
34
|
-
|
|
30
|
+
const walk = (node) => {
|
|
35
31
|
if (node.id === ancestorId) {
|
|
36
|
-
|
|
32
|
+
const descendants = new Set();
|
|
37
33
|
if (node.type === 'folder')
|
|
38
34
|
folderDescendantIds(node, descendants);
|
|
39
35
|
return descendants.has(folderId) || node.id === folderId;
|
|
40
36
|
}
|
|
41
37
|
if (node.children) {
|
|
42
|
-
for (
|
|
43
|
-
var child = _a[_i];
|
|
38
|
+
for (const child of node.children) {
|
|
44
39
|
if (walk(child))
|
|
45
40
|
return true;
|
|
46
41
|
}
|
|
@@ -57,20 +52,19 @@ function isDescendantOf(folderId, ancestorId, root) {
|
|
|
57
52
|
export function canDropOnFolder(targetFolderId, sourceItems, immediateParentId, root) {
|
|
58
53
|
if (!targetFolderId)
|
|
59
54
|
return false;
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
const normalizedTarget = targetFolderId === 'root' || targetFolderId === root.id ? '' : targetFolderId;
|
|
56
|
+
const normalizedParent = immediateParentId ?? '';
|
|
62
57
|
// Same folder as current location
|
|
63
58
|
if (normalizedTarget === normalizedParent)
|
|
64
59
|
return false;
|
|
65
|
-
|
|
66
|
-
for (
|
|
67
|
-
var sourceFolderId = sourceFolderIds_1[_i];
|
|
60
|
+
const sourceFolderIds = sourceItems.filter((i) => i.type === 'folder').map((i) => i.id);
|
|
61
|
+
for (const sourceFolderId of sourceFolderIds) {
|
|
68
62
|
if (normalizedTarget === sourceFolderId)
|
|
69
63
|
return false;
|
|
70
64
|
if (normalizedTarget && isDescendantOf(normalizedTarget, sourceFolderId, root))
|
|
71
65
|
return false;
|
|
72
66
|
}
|
|
73
|
-
if (sourceFolderIds.some(
|
|
67
|
+
if (sourceFolderIds.some((id) => id === normalizedTarget))
|
|
74
68
|
return false;
|
|
75
69
|
return true;
|
|
76
70
|
}
|
|
@@ -13,10 +13,9 @@ export function springLerpPoint(current, target, factor) {
|
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
/** Default follow strength for the ghost stack anchor (spec ~0.18). */
|
|
16
|
-
export
|
|
16
|
+
export const DEFAULT_GHOST_FOLLOW_FACTOR = 0.18;
|
|
17
17
|
/** Deeper stack cards lag slightly more than the front card. */
|
|
18
|
-
export function layerFollowFactor(layerIndex, baseFactor) {
|
|
19
|
-
|
|
20
|
-
var lag = 1 - layerIndex * 0.045;
|
|
18
|
+
export function layerFollowFactor(layerIndex, baseFactor = DEFAULT_GHOST_FOLLOW_FACTOR) {
|
|
19
|
+
const lag = 1 - layerIndex * 0.045;
|
|
21
20
|
return Math.max(0.08, baseFactor * lag);
|
|
22
21
|
}
|
|
@@ -10,77 +10,28 @@
|
|
|
10
10
|
* blocked, a network error or any other status says nothing about the file, so the file stays and its preview shows the error state.
|
|
11
11
|
* The request is a GET for the first byte (CORS is allowed for GET) so it works across origins.
|
|
12
12
|
*/
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
13
|
/** Status codes that say the file is no longer at its address. */
|
|
50
|
-
|
|
14
|
+
const GONE_STATUS_CODES = new Set([404, 410]);
|
|
51
15
|
/**
|
|
52
16
|
* `true` only when the server answered that the file does not exist; `false` for every other outcome (found, blocked, offline).
|
|
53
17
|
*
|
|
54
18
|
* @param fileUrl - The address of the file.
|
|
55
19
|
* @param fetchImplementation - `fetch`, replaceable in tests.
|
|
56
20
|
*/
|
|
57
|
-
export function isFileGone(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (!fileUrl)
|
|
66
|
-
return [2 /*return*/, false];
|
|
67
|
-
_a.label = 1;
|
|
68
|
-
case 1:
|
|
69
|
-
_a.trys.push([1, 3, , 4]);
|
|
70
|
-
return [4 /*yield*/, fetchImplementation(fileUrl, {
|
|
71
|
-
method: 'GET',
|
|
72
|
-
headers: { Range: 'bytes=0-0' }
|
|
73
|
-
})];
|
|
74
|
-
case 2:
|
|
75
|
-
response = _a.sent();
|
|
76
|
-
return [2 /*return*/, GONE_STATUS_CODES.has(response.status)];
|
|
77
|
-
case 3:
|
|
78
|
-
error_1 = _a.sent();
|
|
79
|
-
// A blocked or failed request is not proof: keep the file.
|
|
80
|
-
console.warn('[fileGoneProbe] Could not ask whether the file still exists; keeping it:', fileUrl, error_1);
|
|
81
|
-
return [2 /*return*/, false];
|
|
82
|
-
case 4: return [2 /*return*/];
|
|
83
|
-
}
|
|
21
|
+
export async function isFileGone(fileUrl, fetchImplementation = (input, init) => fetch(input, init)) {
|
|
22
|
+
// Without an address there is nothing to ask: the file is not proven gone, and nothing is removed because of it.
|
|
23
|
+
if (!fileUrl)
|
|
24
|
+
return false;
|
|
25
|
+
try {
|
|
26
|
+
const response = await fetchImplementation(fileUrl, {
|
|
27
|
+
method: 'GET',
|
|
28
|
+
headers: { Range: 'bytes=0-0' }
|
|
84
29
|
});
|
|
85
|
-
|
|
30
|
+
return GONE_STATUS_CODES.has(response.status);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
// A blocked or failed request is not proof: keep the file.
|
|
34
|
+
console.warn('[fileGoneProbe] Could not ask whether the file still exists; keeping it:', fileUrl, error);
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
86
37
|
}
|
package/dist/utils/fileKinds.js
CHANGED
|
@@ -3,7 +3,7 @@ import { FILE_TYPES } from './fileTypes';
|
|
|
3
3
|
* Types a host sends when it does not really know what a file is.
|
|
4
4
|
* They say nothing about the file, so the file name decides instead.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
const UNINFORMATIVE_MIME_TYPES = new Set([
|
|
7
7
|
'application/octet-stream',
|
|
8
8
|
'binary/octet-stream',
|
|
9
9
|
'application/unknown',
|
|
@@ -11,9 +11,8 @@ var UNINFORMATIVE_MIME_TYPES = new Set([
|
|
|
11
11
|
]);
|
|
12
12
|
/** The extension of a file name or URL path, with its dot and in lower case ("" when there is none). */
|
|
13
13
|
function extensionOf(fileName) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var dotIndex = lastSegment.lastIndexOf('.');
|
|
14
|
+
const lastSegment = fileName.split(/[?#]/)[0].split('/').pop() ?? '';
|
|
15
|
+
const dotIndex = lastSegment.lastIndexOf('.');
|
|
17
16
|
// A leading dot (".env") is part of the name, not an extension.
|
|
18
17
|
return dotIndex > 0 ? lastSegment.slice(dotIndex).toLowerCase() : '';
|
|
19
18
|
}
|
|
@@ -28,15 +27,14 @@ function extensionOf(fileName) {
|
|
|
28
27
|
* reported here, so it keeps being tried as a picture.
|
|
29
28
|
*/
|
|
30
29
|
export function isKnownNonImageFile(file) {
|
|
31
|
-
|
|
32
|
-
var mimeType = ((_a = file.mimeType) !== null && _a !== void 0 ? _a : '').trim().toLowerCase();
|
|
30
|
+
const mimeType = (file.mimeType ?? '').trim().toLowerCase();
|
|
33
31
|
if (mimeType !== '' && !UNINFORMATIVE_MIME_TYPES.has(mimeType)) {
|
|
34
32
|
return !mimeType.startsWith('image/');
|
|
35
33
|
}
|
|
36
|
-
return FILE_TYPES.document.includes(extensionOf(
|
|
34
|
+
return FILE_TYPES.document.includes(extensionOf(file.name ?? ''));
|
|
37
35
|
}
|
|
38
36
|
/** Mime types of font files that do not start with `font/` (older servers still send these). */
|
|
39
|
-
|
|
37
|
+
const LEGACY_FONT_MIME_TYPES = new Set([
|
|
40
38
|
'application/font-woff',
|
|
41
39
|
'application/font-woff2',
|
|
42
40
|
'application/font-sfnt',
|
|
@@ -50,9 +48,8 @@ var LEGACY_FONT_MIME_TYPES = new Set([
|
|
|
50
48
|
* or `null` when there is no extension or the tabs do not know it.
|
|
51
49
|
*/
|
|
52
50
|
export function fileKindFromExtension(nameOrAddress) {
|
|
53
|
-
|
|
54
|
-
for (
|
|
55
|
-
var _b = _a[_i], kind = _b[0], extensions = _b[1];
|
|
51
|
+
const extension = extensionOf(nameOrAddress ?? '');
|
|
52
|
+
for (const [kind, extensions] of Object.entries(FILE_TYPES)) {
|
|
56
53
|
if (extensions.includes(extension))
|
|
57
54
|
return kind;
|
|
58
55
|
}
|
|
@@ -65,7 +62,7 @@ export function fileKindFromExtension(nameOrAddress) {
|
|
|
65
62
|
export function fileKindFromMimeType(mimeType) {
|
|
66
63
|
// "image/png; charset=binary" is still image/png. A missing or "binary, who knows" type matches none of the
|
|
67
64
|
// kinds below, so it ends up as null like any other type the tabs have no kind for.
|
|
68
|
-
|
|
65
|
+
const mime = (mimeType ?? '').split(';')[0].trim().toLowerCase();
|
|
69
66
|
if (mime === 'image/svg+xml')
|
|
70
67
|
return 'svg';
|
|
71
68
|
if (mime.startsWith('image/'))
|
|
@@ -92,6 +89,8 @@ export function fileKindFromMimeType(mimeType) {
|
|
|
92
89
|
* A file nothing says anything about is a document.
|
|
93
90
|
*/
|
|
94
91
|
export function getFileTypeOf(file) {
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
return (fileKindFromExtension(file.url) ??
|
|
93
|
+
fileKindFromExtension(file.name) ??
|
|
94
|
+
fileKindFromMimeType(file.mimeType) ??
|
|
95
|
+
'document');
|
|
97
96
|
}
|
package/dist/utils/fileNames.js
CHANGED
|
@@ -7,14 +7,14 @@ export function splitFileName(name) {
|
|
|
7
7
|
if (/^\.[^.]+$/.test(name)) {
|
|
8
8
|
return { baseName: name, extension: '' };
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
const parts = name.split('.');
|
|
11
11
|
if (parts.length <= 1) {
|
|
12
12
|
return { baseName: name, extension: '' };
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
const originalExtension = parts[parts.length - 1];
|
|
15
15
|
return {
|
|
16
16
|
baseName: parts.slice(0, -1).join('.'),
|
|
17
|
-
extension: originalExtension
|
|
17
|
+
extension: originalExtension ?? ''
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
@@ -24,15 +24,15 @@ export function splitFileName(name) {
|
|
|
24
24
|
* never changes what kind of file it is.
|
|
25
25
|
*/
|
|
26
26
|
export function getRenamedFileName(currentName, typedName) {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const currentNameParts = currentName.split('.');
|
|
28
|
+
const newNameParts = typedName.split('.');
|
|
29
29
|
// If current file has an extension but new name doesn't (or has a different one)
|
|
30
30
|
if (currentNameParts.length > 1 &&
|
|
31
31
|
(newNameParts.length === 1 ||
|
|
32
32
|
newNameParts[newNameParts.length - 1] !== currentNameParts[currentNameParts.length - 1])) {
|
|
33
33
|
// Preserve the original extension
|
|
34
|
-
|
|
35
|
-
return
|
|
34
|
+
const originalExtension = currentNameParts[currentNameParts.length - 1];
|
|
35
|
+
return `${typedName}.${originalExtension}`;
|
|
36
36
|
}
|
|
37
37
|
return typedName;
|
|
38
38
|
}
|