@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
|
@@ -1,100 +1,43 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
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);
|
|
23
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
-
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;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
1
|
import { capabilitiesOf } from './capabilities';
|
|
49
2
|
import { MediaLibraryError, toMediaLibraryError } from './errors';
|
|
50
3
|
import { normalizeMediaLibraryFile, normalizeMediaLibraryPage } from './normalize';
|
|
51
4
|
/** How long a library gets to answer `list`, `rename` and `delete` before the File Browser gives up on it. */
|
|
52
|
-
export
|
|
5
|
+
export const DEFAULT_CALL_TIMEOUT_MS = 30_000;
|
|
53
6
|
/** The name of the folder the library's files are shown in, unless the library names it. */
|
|
54
|
-
export
|
|
7
|
+
export const DEFAULT_LIBRARY_LABEL = 'Uploads';
|
|
55
8
|
/** What the visitor is told when a library does not answer in time. */
|
|
56
|
-
|
|
9
|
+
const TIMEOUT_MESSAGE = 'The media library did not answer in time';
|
|
57
10
|
/**
|
|
58
11
|
* Runs one call of a library with a time limit. The library gets an `AbortSignal` that fires on timeout or when the
|
|
59
12
|
* caller gives up; a library that ignores it is still let go of, so the screen never waits forever.
|
|
60
13
|
*/
|
|
61
|
-
function callWithTimeout(run, callerSignal, timeoutMs) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
callController.signal.addEventListener('abort', function () {
|
|
80
|
-
if (callerSignal.aborted)
|
|
81
|
-
reject(new MediaLibraryError('ABORTED', 'The request was cancelled'));
|
|
82
|
-
}, { once: true });
|
|
83
|
-
});
|
|
84
|
-
_a.label = 1;
|
|
85
|
-
case 1:
|
|
86
|
-
_a.trys.push([1, , 3, 4]);
|
|
87
|
-
return [4 /*yield*/, Promise.race([run(callController.signal), timedOut, cancelled])];
|
|
88
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
89
|
-
case 3:
|
|
90
|
-
if (timer !== undefined)
|
|
91
|
-
clearTimeout(timer);
|
|
92
|
-
callerSignal.removeEventListener('abort', forwardAbort);
|
|
93
|
-
return [7 /*endfinally*/];
|
|
94
|
-
case 4: return [2 /*return*/];
|
|
95
|
-
}
|
|
96
|
-
});
|
|
14
|
+
async function callWithTimeout(run, callerSignal, timeoutMs) {
|
|
15
|
+
if (callerSignal.aborted)
|
|
16
|
+
throw new MediaLibraryError('ABORTED', 'The request was cancelled');
|
|
17
|
+
const callController = new AbortController();
|
|
18
|
+
const forwardAbort = () => callController.abort();
|
|
19
|
+
callerSignal.addEventListener('abort', forwardAbort, { once: true });
|
|
20
|
+
let timer;
|
|
21
|
+
const timedOut = new Promise((_, reject) => {
|
|
22
|
+
timer = setTimeout(() => {
|
|
23
|
+
callController.abort();
|
|
24
|
+
reject(new MediaLibraryError('NETWORK', TIMEOUT_MESSAGE, { messageKey: 'libraryError.timeout' }));
|
|
25
|
+
}, timeoutMs);
|
|
26
|
+
});
|
|
27
|
+
const cancelled = new Promise((_, reject) => {
|
|
28
|
+
callController.signal.addEventListener('abort', () => {
|
|
29
|
+
if (callerSignal.aborted)
|
|
30
|
+
reject(new MediaLibraryError('ABORTED', 'The request was cancelled'));
|
|
31
|
+
}, { once: true });
|
|
97
32
|
});
|
|
33
|
+
try {
|
|
34
|
+
return await Promise.race([run(callController.signal), timedOut, cancelled]);
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
if (timer !== undefined)
|
|
38
|
+
clearTimeout(timer);
|
|
39
|
+
callerSignal.removeEventListener('abort', forwardAbort);
|
|
40
|
+
}
|
|
98
41
|
}
|
|
99
42
|
function isObject(value) {
|
|
100
43
|
return value !== null && typeof value === 'object';
|
|
@@ -105,152 +48,90 @@ function isObject(value) {
|
|
|
105
48
|
* Throws a `TypeError` naming the problem when it is not a provider (no `list` function), so a partner's mistake
|
|
106
49
|
* shows up at mount time with a clear message instead of as an empty screen.
|
|
107
50
|
*/
|
|
108
|
-
export function resolveMediaLibrary(provider, options) {
|
|
109
|
-
var _this = this;
|
|
110
|
-
var _a;
|
|
111
|
-
if (options === void 0) { options = {}; }
|
|
51
|
+
export function resolveMediaLibrary(provider, options = {}) {
|
|
112
52
|
if (!isObject(provider) || typeof provider.list !== 'function') {
|
|
113
53
|
throw new TypeError('mediaLibrary must be an object with a list({ cursor, limit, signal }) function');
|
|
114
54
|
}
|
|
115
|
-
for (
|
|
116
|
-
var optionalFunction = _b[_i];
|
|
55
|
+
for (const optionalFunction of ['upload', 'rename', 'delete']) {
|
|
117
56
|
if (provider[optionalFunction] !== undefined &&
|
|
118
57
|
typeof provider[optionalFunction] !== 'function') {
|
|
119
|
-
throw new TypeError(
|
|
58
|
+
throw new TypeError(`mediaLibrary.${optionalFunction} must be a function when it is given`);
|
|
120
59
|
}
|
|
121
60
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
61
|
+
const library = provider;
|
|
62
|
+
const callTimeoutMs = options.callTimeoutMs ?? DEFAULT_CALL_TIMEOUT_MS;
|
|
63
|
+
const normalizeOptions = { baseHref: options.baseHref };
|
|
64
|
+
const id = typeof library.id === 'string' && library.id.trim() !== ''
|
|
126
65
|
? library.id.trim().slice(0, 64)
|
|
127
66
|
: 'host';
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
id
|
|
133
|
-
label
|
|
134
|
-
hasOwnLabel
|
|
135
|
-
capabilities
|
|
136
|
-
listPage
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
case 0:
|
|
147
|
-
_a.trys.push([0, 2, , 3]);
|
|
148
|
-
return [4 /*yield*/, library.list(__assign(__assign({}, request), { signal: signal }))];
|
|
149
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
150
|
-
case 2:
|
|
151
|
-
error_1 = _a.sent();
|
|
152
|
-
throw toMediaLibraryError(error_1, 'Could not load the files', 'libraryError.loadFailed');
|
|
153
|
-
case 3: return [2 /*return*/];
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
}); }, request.signal, callTimeoutMs)];
|
|
157
|
-
case 1:
|
|
158
|
-
raw = _a.sent();
|
|
159
|
-
return [2 /*return*/, normalizeMediaLibraryPage(raw, normalizeOptions)];
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
});
|
|
67
|
+
const hasOwnLabel = typeof library.label === 'string' && library.label.trim() !== '';
|
|
68
|
+
const label = hasOwnLabel ? library.label.trim().slice(0, 64) : DEFAULT_LIBRARY_LABEL;
|
|
69
|
+
const capabilities = capabilitiesOf(library);
|
|
70
|
+
const resolved = {
|
|
71
|
+
id,
|
|
72
|
+
label,
|
|
73
|
+
hasOwnLabel,
|
|
74
|
+
capabilities,
|
|
75
|
+
async listPage(request) {
|
|
76
|
+
const raw = await callWithTimeout(async (signal) => {
|
|
77
|
+
try {
|
|
78
|
+
return await library.list({ ...request, signal });
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
throw toMediaLibraryError(error, 'Could not load the files', 'libraryError.loadFailed');
|
|
82
|
+
}
|
|
83
|
+
}, request.signal, callTimeoutMs);
|
|
84
|
+
return normalizeMediaLibraryPage(raw, normalizeOptions);
|
|
163
85
|
}
|
|
164
86
|
};
|
|
165
87
|
if (capabilities.upload && typeof library.upload === 'function') {
|
|
166
|
-
resolved.upload =
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
throw toMediaLibraryError(error_2, 'The upload failed', 'libraryError.uploadFailed');
|
|
179
|
-
case 3:
|
|
180
|
-
// An upload the library accepted but described badly is reported, not shown: the visitor must not believe a
|
|
181
|
-
// file is there when the grid cannot show it.
|
|
182
|
-
return [2 /*return*/, normalizeMediaLibraryFile(raw, normalizeOptions)];
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
}); };
|
|
88
|
+
resolved.upload = async (request) => {
|
|
89
|
+
let raw;
|
|
90
|
+
try {
|
|
91
|
+
raw = await library.upload(request);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
throw toMediaLibraryError(error, 'The upload failed', 'libraryError.uploadFailed');
|
|
95
|
+
}
|
|
96
|
+
// An upload the library accepted but described badly is reported, not shown: the visitor must not believe a
|
|
97
|
+
// file is there when the grid cannot show it.
|
|
98
|
+
return normalizeMediaLibraryFile(raw, normalizeOptions);
|
|
99
|
+
};
|
|
186
100
|
}
|
|
187
101
|
if (capabilities.rename && typeof library.rename === 'function') {
|
|
188
|
-
resolved.rename =
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
switch (_a.label) {
|
|
193
|
-
case 0: return [4 /*yield*/, callWithTimeout(function (signal) { return __awaiter(_this, void 0, void 0, function () {
|
|
194
|
-
var error_3;
|
|
195
|
-
return __generator(this, function (_a) {
|
|
196
|
-
switch (_a.label) {
|
|
197
|
-
case 0:
|
|
198
|
-
_a.trys.push([0, 2, , 3]);
|
|
199
|
-
return [4 /*yield*/, library.rename(__assign(__assign({}, request), { signal: signal }))];
|
|
200
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
201
|
-
case 2:
|
|
202
|
-
error_3 = _a.sent();
|
|
203
|
-
throw toMediaLibraryError(error_3, 'Could not rename the file', 'libraryError.renameFailed');
|
|
204
|
-
case 3: return [2 /*return*/];
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
}); }, request.signal, callTimeoutMs)];
|
|
208
|
-
case 1:
|
|
209
|
-
raw = _a.sent();
|
|
210
|
-
if (raw === undefined || raw === null)
|
|
211
|
-
return [2 /*return*/, null];
|
|
212
|
-
try {
|
|
213
|
-
return [2 /*return*/, normalizeMediaLibraryFile(raw, normalizeOptions)];
|
|
214
|
-
}
|
|
215
|
-
catch (error) {
|
|
216
|
-
// The rename itself worked; only the description of the result is wrong, so the File Browser keeps the name
|
|
217
|
-
// the visitor typed.
|
|
218
|
-
console.warn("[FileBrowser] The media library \"".concat(id, "\" renamed the file but described the result badly:"), error);
|
|
219
|
-
return [2 /*return*/, null];
|
|
220
|
-
}
|
|
221
|
-
return [2 /*return*/];
|
|
102
|
+
resolved.rename = async (request) => {
|
|
103
|
+
const raw = await callWithTimeout(async (signal) => {
|
|
104
|
+
try {
|
|
105
|
+
return await library.rename({ ...request, signal });
|
|
222
106
|
}
|
|
223
|
-
|
|
224
|
-
|
|
107
|
+
catch (error) {
|
|
108
|
+
throw toMediaLibraryError(error, 'Could not rename the file', 'libraryError.renameFailed');
|
|
109
|
+
}
|
|
110
|
+
}, request.signal, callTimeoutMs);
|
|
111
|
+
if (raw === undefined || raw === null)
|
|
112
|
+
return null;
|
|
113
|
+
try {
|
|
114
|
+
return normalizeMediaLibraryFile(raw, normalizeOptions);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
// The rename itself worked; only the description of the result is wrong, so the File Browser keeps the name
|
|
118
|
+
// the visitor typed.
|
|
119
|
+
console.warn(`[FileBrowser] The media library "${id}" renamed the file but described the result badly:`, error);
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
225
123
|
}
|
|
226
124
|
if (capabilities.delete && typeof library.delete === 'function') {
|
|
227
|
-
resolved.remove =
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
switch (_a.label) {
|
|
235
|
-
case 0:
|
|
236
|
-
_a.trys.push([0, 2, , 3]);
|
|
237
|
-
return [4 /*yield*/, library.delete(__assign(__assign({}, request), { signal: signal }))];
|
|
238
|
-
case 1:
|
|
239
|
-
_a.sent();
|
|
240
|
-
return [3 /*break*/, 3];
|
|
241
|
-
case 2:
|
|
242
|
-
error_4 = _a.sent();
|
|
243
|
-
throw toMediaLibraryError(error_4, 'Could not delete the file', 'libraryError.deleteFailed');
|
|
244
|
-
case 3: return [2 /*return*/];
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
}); }, request.signal, callTimeoutMs)];
|
|
248
|
-
case 1:
|
|
249
|
-
_a.sent();
|
|
250
|
-
return [2 /*return*/];
|
|
125
|
+
resolved.remove = async (request) => {
|
|
126
|
+
await callWithTimeout(async (signal) => {
|
|
127
|
+
try {
|
|
128
|
+
await library.delete({ ...request, signal });
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
throw toMediaLibraryError(error, 'Could not delete the file', 'libraryError.deleteFailed');
|
|
251
132
|
}
|
|
252
|
-
});
|
|
253
|
-
}
|
|
133
|
+
}, request.signal, callTimeoutMs);
|
|
134
|
+
};
|
|
254
135
|
}
|
|
255
136
|
return resolved;
|
|
256
137
|
}
|
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
-
if (ar || !(i in from)) {
|
|
15
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
-
ar[i] = from[i];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
-
};
|
|
21
1
|
/**
|
|
22
2
|
* A media library is one flat list of files, so the File Browser's tree for it is a root folder whose children are
|
|
23
3
|
* the files. These helpers change that list the way the library's own answers do (a file arrives, is renamed, is
|
|
@@ -29,15 +9,13 @@ export function createLibraryRoot(files) {
|
|
|
29
9
|
return { id: 'root', name: 'Root', type: 'folder', children: files };
|
|
30
10
|
}
|
|
31
11
|
function childrenOf(root) {
|
|
32
|
-
|
|
33
|
-
return (_a = root.children) !== null && _a !== void 0 ? _a : [];
|
|
12
|
+
return root.children ?? [];
|
|
34
13
|
}
|
|
35
14
|
/** Adds the files whose id is not in the list yet. A file already in the list is left exactly as it is. */
|
|
36
15
|
export function appendNewFiles(root, files) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
for (
|
|
40
|
-
var file = files_1[_i];
|
|
16
|
+
const knownIds = new Set(childrenOf(root).map((item) => item.id));
|
|
17
|
+
const newFiles = [];
|
|
18
|
+
for (const file of files) {
|
|
41
19
|
if (knownIds.has(file.id))
|
|
42
20
|
continue;
|
|
43
21
|
knownIds.add(file.id);
|
|
@@ -45,18 +23,21 @@ export function appendNewFiles(root, files) {
|
|
|
45
23
|
}
|
|
46
24
|
if (newFiles.length === 0)
|
|
47
25
|
return root;
|
|
48
|
-
return
|
|
26
|
+
return { ...root, children: [...childrenOf(root), ...newFiles] };
|
|
49
27
|
}
|
|
50
28
|
/**
|
|
51
29
|
* Puts a file in the list: replaces the file with the same id (a library may answer an upload with a file it
|
|
52
30
|
* already had), or adds it when it is new.
|
|
53
31
|
*/
|
|
54
32
|
export function upsertFile(root, file) {
|
|
55
|
-
|
|
56
|
-
|
|
33
|
+
const children = childrenOf(root);
|
|
34
|
+
const index = children.findIndex((item) => item.id === file.id);
|
|
57
35
|
if (index === -1)
|
|
58
|
-
return
|
|
59
|
-
return
|
|
36
|
+
return { ...root, children: [...children, file] };
|
|
37
|
+
return {
|
|
38
|
+
...root,
|
|
39
|
+
children: children.map((item, position) => (position === index ? file : item))
|
|
40
|
+
};
|
|
60
41
|
}
|
|
61
42
|
/**
|
|
62
43
|
* Replaces the file `id` with `file`. The new file may have another id (a library can name files by their path, and
|
|
@@ -64,24 +45,23 @@ export function upsertFile(root, file) {
|
|
|
64
45
|
* says the id is now this file, and the list never holds two files with one id. An unknown `id` changes nothing.
|
|
65
46
|
*/
|
|
66
47
|
export function replaceFile(root, id, file) {
|
|
67
|
-
|
|
68
|
-
if (!children.some(
|
|
48
|
+
const children = childrenOf(root);
|
|
49
|
+
if (!children.some((item) => item.id === id))
|
|
69
50
|
return root;
|
|
70
|
-
|
|
71
|
-
for (
|
|
72
|
-
var item = children_1[_i];
|
|
51
|
+
const replaced = [];
|
|
52
|
+
for (const item of children) {
|
|
73
53
|
if (item.id === id)
|
|
74
54
|
replaced.push(file);
|
|
75
55
|
else if (item.id !== file.id)
|
|
76
56
|
replaced.push(item);
|
|
77
57
|
}
|
|
78
|
-
return
|
|
58
|
+
return { ...root, children: replaced };
|
|
79
59
|
}
|
|
80
60
|
/** Takes the files with these ids out of the list. */
|
|
81
61
|
export function removeFiles(root, ids) {
|
|
82
|
-
|
|
83
|
-
|
|
62
|
+
const children = childrenOf(root);
|
|
63
|
+
const kept = children.filter((item) => !ids.has(item.id));
|
|
84
64
|
if (kept.length === children.length)
|
|
85
65
|
return root;
|
|
86
|
-
return
|
|
66
|
+
return { ...root, children: kept };
|
|
87
67
|
}
|
|
@@ -6,17 +6,17 @@
|
|
|
6
6
|
* visitor clicks Download, so only addresses that fetch something are accepted.
|
|
7
7
|
*/
|
|
8
8
|
/** The longest address taken as a file's address or thumbnail address. */
|
|
9
|
-
export
|
|
9
|
+
export const MAX_URL_LENGTH = 8192;
|
|
10
10
|
/** The longest `data:` picture taken as a thumbnail (about 220 KB of image). */
|
|
11
|
-
export
|
|
11
|
+
export const MAX_DATA_THUMBNAIL_LENGTH = 300_000;
|
|
12
12
|
/** `data:` addresses are only accepted for pictures; they can hold a small preview but never a script or a page. */
|
|
13
|
-
|
|
13
|
+
const DATA_IMAGE_PATTERN = /^data:image\/(?:png|jpe?g|gif|webp|avif|svg\+xml)[;,]/i;
|
|
14
14
|
/** The address of the page the File Browser is on, to turn a path like `/media/1.png` into a full address. */
|
|
15
15
|
export function currentPageHref() {
|
|
16
16
|
try {
|
|
17
17
|
return typeof location !== 'undefined' ? location.href : undefined;
|
|
18
18
|
}
|
|
19
|
-
catch
|
|
19
|
+
catch {
|
|
20
20
|
return undefined;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -27,25 +27,23 @@ export function currentPageHref() {
|
|
|
27
27
|
* partner's own page created; for thumbnails also small `data:` pictures. Everything else (`javascript:`, `file:`,
|
|
28
28
|
* `ftp:`, `vbscript:`, `data:text/html` ...) is refused.
|
|
29
29
|
*/
|
|
30
|
-
export function toSafeMediaUrl(raw, options) {
|
|
31
|
-
var _a;
|
|
32
|
-
if (options === void 0) { options = {}; }
|
|
30
|
+
export function toSafeMediaUrl(raw, options = {}) {
|
|
33
31
|
if (typeof raw !== 'string')
|
|
34
32
|
return null;
|
|
35
|
-
|
|
33
|
+
const trimmed = raw.trim();
|
|
36
34
|
if (trimmed === '')
|
|
37
35
|
return null;
|
|
38
|
-
|
|
36
|
+
const isDataPicture = DATA_IMAGE_PATTERN.test(trimmed);
|
|
39
37
|
if (trimmed.length > (isDataPicture ? MAX_DATA_THUMBNAIL_LENGTH : MAX_URL_LENGTH))
|
|
40
38
|
return null;
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
const baseHref = options.baseHref ?? currentPageHref();
|
|
40
|
+
let parsed;
|
|
43
41
|
try {
|
|
44
42
|
// A base is only needed for paths; a full address ignores it. The browser's parser also strips the tabs and
|
|
45
43
|
// line breaks that `java\nscript:` tricks rely on, so the protocol checked here is the one the browser sees.
|
|
46
44
|
parsed = baseHref ? new URL(trimmed, baseHref) : new URL(trimmed);
|
|
47
45
|
}
|
|
48
|
-
catch
|
|
46
|
+
catch {
|
|
49
47
|
return null;
|
|
50
48
|
}
|
|
51
49
|
switch (parsed.protocol) {
|