@widgetic/file-browser 0.5.47 → 0.5.48
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 +104 -115
- package/dist/components/FolderTree.svelte.d.ts +4 -7
- package/dist/components/core/Dropzone.svelte +42 -2
- package/dist/components/core/FileBrowser.svelte +224 -14
- package/dist/components/core/FileUploader.svelte +124 -41
- package/dist/components/core/RecentFiles.svelte +54 -16
- package/dist/components/core/SearchDropdown.svelte +6 -8
- package/dist/components/core/UploadPanel.svelte +7 -0
- package/dist/components/core/UploadPanel.svelte.d.ts +4 -0
- package/dist/components/core/UploadRow.svelte +9 -4
- package/dist/components/core/UploadRow.svelte.d.ts +2 -0
- package/dist/components/core/dropzoneClick.d.ts +28 -0
- package/dist/components/core/dropzoneClick.js +32 -0
- package/dist/components/previews/FilePreview.svelte.d.ts +2 -2
- package/dist/components/ui/DropdownMenu.svelte +1 -1
- package/dist/config.js +4 -3
- package/dist/i18n/context.js +2 -2
- package/dist/i18n/errors.js +2 -1
- package/dist/i18n/messages.d.ts +13 -0
- package/dist/i18n/messages.js +15 -2
- package/dist/i18n/text.js +2 -2
- package/dist/mediaLibrary/capabilities.js +4 -3
- package/dist/mediaLibrary/context.js +4 -3
- package/dist/mediaLibrary/errors.js +46 -35
- package/dist/mediaLibrary/normalize.js +45 -42
- package/dist/mediaLibrary/paging.js +100 -45
- package/dist/mediaLibrary/resolve.js +214 -95
- package/dist/mediaLibrary/treeOps.js +40 -20
- package/dist/mediaLibrary/urls.js +12 -10
- package/dist/mediaLibrary/widgetic.js +140 -54
- package/dist/stores/dragStore.js +1 -1
- package/dist/stores/fileStore.d.ts +3 -3
- package/dist/stores/fileStore.js +44 -37
- package/dist/stores/folderCountStore.js +12 -11
- package/dist/stores/missingFilesStore.js +3 -3
- package/dist/stores/navigationStore.d.ts +1 -1
- package/dist/stores/navigationStore.js +217 -178
- package/dist/stores/persistentSelectStore.d.ts +1 -1
- package/dist/stores/persistentSelectStore.js +117 -94
- package/dist/stores/searchStore.js +1 -1
- package/dist/stores/uploadApiStore.d.ts +10 -0
- package/dist/stores/uploadApiStore.js +7 -7
- package/dist/stores/viewportStore.js +4 -4
- package/dist/types/index.js +0 -1
- package/dist/utils/apiConfig.js +9 -9
- package/dist/utils/brandKitLibraryTree.js +57 -42
- package/dist/utils/dateUtils.js +11 -9
- package/dist/utils/deleteSelectionAction.d.ts +26 -0
- package/dist/utils/deleteSelectionAction.js +23 -0
- package/dist/utils/dragToFolder/batchMoveResult.js +114 -54
- package/dist/utils/dragToFolder/folderDropTarget.js +23 -17
- package/dist/utils/dragToFolder/springStep.js +4 -3
- package/dist/utils/fileGoneProbe.js +65 -16
- package/dist/utils/fileKinds.js +14 -13
- package/dist/utils/fileNames.js +7 -7
- package/dist/utils/fileOperations.js +440 -332
- package/dist/utils/fileTypes.js +19 -14
- package/dist/utils/fileUtils.js +85 -31
- package/dist/utils/folderUtils.js +5 -4
- package/dist/utils/gridLayout.js +7 -7
- package/dist/utils/imagePreviewCache.js +26 -15
- package/dist/utils/imagePreviewFrame.js +13 -13
- package/dist/utils/imagePreviewVisualState.js +5 -4
- package/dist/utils/imageTransform.js +27 -14
- package/dist/utils/itemMenuCapabilities.js +7 -7
- package/dist/utils/libraryTree.js +55 -39
- package/dist/utils/pendingUploadDeletes.d.ts +102 -0
- package/dist/utils/pendingUploadDeletes.js +400 -0
- package/dist/utils/previewKeys.js +1 -1
- package/dist/utils/previewListNavigation.js +13 -11
- package/dist/utils/previewNavigation.js +10 -7
- package/dist/utils/recentFiles.js +16 -6
- package/dist/utils/recentFilesLimit.js +2 -2
- package/dist/utils/removeItems.d.ts +30 -0
- package/dist/utils/removeItems.js +124 -0
- package/dist/utils/resolveFileUrl.js +6 -6
- package/dist/utils/safeText.js +14 -12
- package/dist/utils/searchDropdownPhase.d.ts +14 -3
- package/dist/utils/searchDropdownPhase.js +13 -9
- package/dist/utils/searchItems.js +30 -14
- package/dist/utils/searchNavigation.js +5 -5
- package/dist/utils/uploadAuth.d.ts +24 -0
- package/dist/utils/uploadAuth.js +140 -0
- package/dist/utils/uploadDisplayProgress.js +1 -1
- package/dist/utils/uploadLimits.d.ts +76 -0
- package/dist/utils/uploadLimits.js +242 -0
- package/dist/utils/uploadListReconcile.js +24 -11
- package/dist/utils/uploadPanelDismiss.js +1 -1
- package/dist/utils/uploadPanelProgress.js +4 -4
- package/dist/utils/uploadProgressMath.js +13 -11
- package/dist/utils/uploadRefusals.d.ts +42 -0
- package/dist/utils/uploadRefusals.js +86 -0
- package/dist/utils/uploadResponseMapping.js +9 -8
- package/dist/utils/uploadUiHelpers.js +17 -17
- package/dist/utils/userUploadsStorage.js +270 -133
- package/dist/utils/videoFrame.d.ts +23 -0
- package/dist/utils/videoFrame.js +26 -0
- package/dist/utils/widgeticDelete.js +103 -28
- package/dist/utils/widgeticTusUpload.js +189 -105
- package/dist/utils/widgeticUpload.js +133 -59
- package/dist/utils/xhrMultipartUpload.js +164 -116
- package/package.json +3 -3
|
@@ -1,43 +1,100 @@
|
|
|
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
|
+
};
|
|
1
48
|
import { capabilitiesOf } from './capabilities';
|
|
2
49
|
import { MediaLibraryError, toMediaLibraryError } from './errors';
|
|
3
50
|
import { normalizeMediaLibraryFile, normalizeMediaLibraryPage } from './normalize';
|
|
4
51
|
/** How long a library gets to answer `list`, `rename` and `delete` before the File Browser gives up on it. */
|
|
5
|
-
export
|
|
52
|
+
export var DEFAULT_CALL_TIMEOUT_MS = 30000;
|
|
6
53
|
/** The name of the folder the library's files are shown in, unless the library names it. */
|
|
7
|
-
export
|
|
54
|
+
export var DEFAULT_LIBRARY_LABEL = 'Uploads';
|
|
8
55
|
/** What the visitor is told when a library does not answer in time. */
|
|
9
|
-
|
|
56
|
+
var TIMEOUT_MESSAGE = 'The media library did not answer in time';
|
|
10
57
|
/**
|
|
11
58
|
* Runs one call of a library with a time limit. The library gets an `AbortSignal` that fires on timeout or when the
|
|
12
59
|
* caller gives up; a library that ignores it is still let go of, so the screen never waits forever.
|
|
13
60
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
61
|
+
function callWithTimeout(run, callerSignal, timeoutMs) {
|
|
62
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
63
|
+
var callController, forwardAbort, timer, timedOut, cancelled;
|
|
64
|
+
return __generator(this, function (_a) {
|
|
65
|
+
switch (_a.label) {
|
|
66
|
+
case 0:
|
|
67
|
+
if (callerSignal.aborted)
|
|
68
|
+
throw new MediaLibraryError('ABORTED', 'The request was cancelled');
|
|
69
|
+
callController = new AbortController();
|
|
70
|
+
forwardAbort = function () { return callController.abort(); };
|
|
71
|
+
callerSignal.addEventListener('abort', forwardAbort, { once: true });
|
|
72
|
+
timedOut = new Promise(function (_, reject) {
|
|
73
|
+
timer = setTimeout(function () {
|
|
74
|
+
callController.abort();
|
|
75
|
+
reject(new MediaLibraryError('NETWORK', TIMEOUT_MESSAGE, { messageKey: 'libraryError.timeout' }));
|
|
76
|
+
}, timeoutMs);
|
|
77
|
+
});
|
|
78
|
+
cancelled = new Promise(function (_, reject) {
|
|
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
|
+
});
|
|
32
97
|
});
|
|
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
|
-
}
|
|
41
98
|
}
|
|
42
99
|
function isObject(value) {
|
|
43
100
|
return value !== null && typeof value === 'object';
|
|
@@ -48,90 +105,152 @@ function isObject(value) {
|
|
|
48
105
|
* Throws a `TypeError` naming the problem when it is not a provider (no `list` function), so a partner's mistake
|
|
49
106
|
* shows up at mount time with a clear message instead of as an empty screen.
|
|
50
107
|
*/
|
|
51
|
-
export function resolveMediaLibrary(provider, options
|
|
108
|
+
export function resolveMediaLibrary(provider, options) {
|
|
109
|
+
var _this = this;
|
|
110
|
+
var _a;
|
|
111
|
+
if (options === void 0) { options = {}; }
|
|
52
112
|
if (!isObject(provider) || typeof provider.list !== 'function') {
|
|
53
113
|
throw new TypeError('mediaLibrary must be an object with a list({ cursor, limit, signal }) function');
|
|
54
114
|
}
|
|
55
|
-
for (
|
|
115
|
+
for (var _i = 0, _b = ['upload', 'rename', 'delete']; _i < _b.length; _i++) {
|
|
116
|
+
var optionalFunction = _b[_i];
|
|
56
117
|
if (provider[optionalFunction] !== undefined &&
|
|
57
118
|
typeof provider[optionalFunction] !== 'function') {
|
|
58
|
-
throw new TypeError(
|
|
119
|
+
throw new TypeError("mediaLibrary.".concat(optionalFunction, " must be a function when it is given"));
|
|
59
120
|
}
|
|
60
121
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
122
|
+
var library = provider;
|
|
123
|
+
var callTimeoutMs = (_a = options.callTimeoutMs) !== null && _a !== void 0 ? _a : DEFAULT_CALL_TIMEOUT_MS;
|
|
124
|
+
var normalizeOptions = { baseHref: options.baseHref };
|
|
125
|
+
var id = typeof library.id === 'string' && library.id.trim() !== ''
|
|
65
126
|
? library.id.trim().slice(0, 64)
|
|
66
127
|
: 'host';
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
id,
|
|
72
|
-
label,
|
|
73
|
-
hasOwnLabel,
|
|
74
|
-
capabilities,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
128
|
+
var hasOwnLabel = typeof library.label === 'string' && library.label.trim() !== '';
|
|
129
|
+
var label = hasOwnLabel ? library.label.trim().slice(0, 64) : DEFAULT_LIBRARY_LABEL;
|
|
130
|
+
var capabilities = capabilitiesOf(library);
|
|
131
|
+
var resolved = {
|
|
132
|
+
id: id,
|
|
133
|
+
label: label,
|
|
134
|
+
hasOwnLabel: hasOwnLabel,
|
|
135
|
+
capabilities: capabilities,
|
|
136
|
+
listPage: function (request) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
138
|
+
var raw;
|
|
139
|
+
var _this = this;
|
|
140
|
+
return __generator(this, function (_a) {
|
|
141
|
+
switch (_a.label) {
|
|
142
|
+
case 0: return [4 /*yield*/, callWithTimeout(function (signal) { return __awaiter(_this, void 0, void 0, function () {
|
|
143
|
+
var error_1;
|
|
144
|
+
return __generator(this, function (_a) {
|
|
145
|
+
switch (_a.label) {
|
|
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
|
+
});
|
|
85
163
|
}
|
|
86
164
|
};
|
|
87
165
|
if (capabilities.upload && typeof library.upload === 'function') {
|
|
88
|
-
resolved.upload =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
166
|
+
resolved.upload = function (request) { return __awaiter(_this, void 0, void 0, function () {
|
|
167
|
+
var raw, error_2;
|
|
168
|
+
return __generator(this, function (_a) {
|
|
169
|
+
switch (_a.label) {
|
|
170
|
+
case 0:
|
|
171
|
+
_a.trys.push([0, 2, , 3]);
|
|
172
|
+
return [4 /*yield*/, library.upload(request)];
|
|
173
|
+
case 1:
|
|
174
|
+
raw = _a.sent();
|
|
175
|
+
return [3 /*break*/, 3];
|
|
176
|
+
case 2:
|
|
177
|
+
error_2 = _a.sent();
|
|
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
|
+
}); };
|
|
100
186
|
}
|
|
101
187
|
if (capabilities.rename && typeof library.rename === 'function') {
|
|
102
|
-
resolved.rename =
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
188
|
+
resolved.rename = function (request) { return __awaiter(_this, void 0, void 0, function () {
|
|
189
|
+
var raw;
|
|
190
|
+
var _this = this;
|
|
191
|
+
return __generator(this, function (_a) {
|
|
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*/];
|
|
106
222
|
}
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
};
|
|
223
|
+
});
|
|
224
|
+
}); };
|
|
123
225
|
}
|
|
124
226
|
if (capabilities.delete && typeof library.delete === 'function') {
|
|
125
|
-
resolved.remove =
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
227
|
+
resolved.remove = function (request) { return __awaiter(_this, void 0, void 0, function () {
|
|
228
|
+
var _this = this;
|
|
229
|
+
return __generator(this, function (_a) {
|
|
230
|
+
switch (_a.label) {
|
|
231
|
+
case 0: return [4 /*yield*/, callWithTimeout(function (signal) { return __awaiter(_this, void 0, void 0, function () {
|
|
232
|
+
var error_4;
|
|
233
|
+
return __generator(this, function (_a) {
|
|
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*/];
|
|
132
251
|
}
|
|
133
|
-
}
|
|
134
|
-
};
|
|
252
|
+
});
|
|
253
|
+
}); };
|
|
135
254
|
}
|
|
136
255
|
return resolved;
|
|
137
256
|
}
|
|
@@ -1,3 +1,23 @@
|
|
|
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
|
+
};
|
|
1
21
|
/**
|
|
2
22
|
* A media library is one flat list of files, so the File Browser's tree for it is a root folder whose children are
|
|
3
23
|
* the files. These helpers change that list the way the library's own answers do (a file arrives, is renamed, is
|
|
@@ -9,13 +29,15 @@ export function createLibraryRoot(files) {
|
|
|
9
29
|
return { id: 'root', name: 'Root', type: 'folder', children: files };
|
|
10
30
|
}
|
|
11
31
|
function childrenOf(root) {
|
|
12
|
-
|
|
32
|
+
var _a;
|
|
33
|
+
return (_a = root.children) !== null && _a !== void 0 ? _a : [];
|
|
13
34
|
}
|
|
14
35
|
/** Adds the files whose id is not in the list yet. A file already in the list is left exactly as it is. */
|
|
15
36
|
export function appendNewFiles(root, files) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
for (
|
|
37
|
+
var knownIds = new Set(childrenOf(root).map(function (item) { return item.id; }));
|
|
38
|
+
var newFiles = [];
|
|
39
|
+
for (var _i = 0, files_1 = files; _i < files_1.length; _i++) {
|
|
40
|
+
var file = files_1[_i];
|
|
19
41
|
if (knownIds.has(file.id))
|
|
20
42
|
continue;
|
|
21
43
|
knownIds.add(file.id);
|
|
@@ -23,21 +45,18 @@ export function appendNewFiles(root, files) {
|
|
|
23
45
|
}
|
|
24
46
|
if (newFiles.length === 0)
|
|
25
47
|
return root;
|
|
26
|
-
return {
|
|
48
|
+
return __assign(__assign({}, root), { children: __spreadArray(__spreadArray([], childrenOf(root), true), newFiles, true) });
|
|
27
49
|
}
|
|
28
50
|
/**
|
|
29
51
|
* Puts a file in the list: replaces the file with the same id (a library may answer an upload with a file it
|
|
30
52
|
* already had), or adds it when it is new.
|
|
31
53
|
*/
|
|
32
54
|
export function upsertFile(root, file) {
|
|
33
|
-
|
|
34
|
-
|
|
55
|
+
var children = childrenOf(root);
|
|
56
|
+
var index = children.findIndex(function (item) { return item.id === file.id; });
|
|
35
57
|
if (index === -1)
|
|
36
|
-
return {
|
|
37
|
-
return {
|
|
38
|
-
...root,
|
|
39
|
-
children: children.map((item, position) => (position === index ? file : item))
|
|
40
|
-
};
|
|
58
|
+
return __assign(__assign({}, root), { children: __spreadArray(__spreadArray([], children, true), [file], false) });
|
|
59
|
+
return __assign(__assign({}, root), { children: children.map(function (item, position) { return (position === index ? file : item); }) });
|
|
41
60
|
}
|
|
42
61
|
/**
|
|
43
62
|
* Replaces the file `id` with `file`. The new file may have another id (a library can name files by their path, and
|
|
@@ -45,23 +64,24 @@ export function upsertFile(root, file) {
|
|
|
45
64
|
* says the id is now this file, and the list never holds two files with one id. An unknown `id` changes nothing.
|
|
46
65
|
*/
|
|
47
66
|
export function replaceFile(root, id, file) {
|
|
48
|
-
|
|
49
|
-
if (!children.some((item)
|
|
67
|
+
var children = childrenOf(root);
|
|
68
|
+
if (!children.some(function (item) { return item.id === id; }))
|
|
50
69
|
return root;
|
|
51
|
-
|
|
52
|
-
for (
|
|
70
|
+
var replaced = [];
|
|
71
|
+
for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
|
|
72
|
+
var item = children_1[_i];
|
|
53
73
|
if (item.id === id)
|
|
54
74
|
replaced.push(file);
|
|
55
75
|
else if (item.id !== file.id)
|
|
56
76
|
replaced.push(item);
|
|
57
77
|
}
|
|
58
|
-
return {
|
|
78
|
+
return __assign(__assign({}, root), { children: replaced });
|
|
59
79
|
}
|
|
60
80
|
/** Takes the files with these ids out of the list. */
|
|
61
81
|
export function removeFiles(root, ids) {
|
|
62
|
-
|
|
63
|
-
|
|
82
|
+
var children = childrenOf(root);
|
|
83
|
+
var kept = children.filter(function (item) { return !ids.has(item.id); });
|
|
64
84
|
if (kept.length === children.length)
|
|
65
85
|
return root;
|
|
66
|
-
return {
|
|
86
|
+
return __assign(__assign({}, root), { children: kept });
|
|
67
87
|
}
|
|
@@ -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 var MAX_URL_LENGTH = 8192;
|
|
10
10
|
/** The longest `data:` picture taken as a thumbnail (about 220 KB of image). */
|
|
11
|
-
export
|
|
11
|
+
export var MAX_DATA_THUMBNAIL_LENGTH = 300000;
|
|
12
12
|
/** `data:` addresses are only accepted for pictures; they can hold a small preview but never a script or a page. */
|
|
13
|
-
|
|
13
|
+
var 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 (_a) {
|
|
20
20
|
return undefined;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -27,23 +27,25 @@ 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
|
|
30
|
+
export function toSafeMediaUrl(raw, options) {
|
|
31
|
+
var _a;
|
|
32
|
+
if (options === void 0) { options = {}; }
|
|
31
33
|
if (typeof raw !== 'string')
|
|
32
34
|
return null;
|
|
33
|
-
|
|
35
|
+
var trimmed = raw.trim();
|
|
34
36
|
if (trimmed === '')
|
|
35
37
|
return null;
|
|
36
|
-
|
|
38
|
+
var isDataPicture = DATA_IMAGE_PATTERN.test(trimmed);
|
|
37
39
|
if (trimmed.length > (isDataPicture ? MAX_DATA_THUMBNAIL_LENGTH : MAX_URL_LENGTH))
|
|
38
40
|
return null;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
var baseHref = (_a = options.baseHref) !== null && _a !== void 0 ? _a : currentPageHref();
|
|
42
|
+
var parsed;
|
|
41
43
|
try {
|
|
42
44
|
// A base is only needed for paths; a full address ignores it. The browser's parser also strips the tabs and
|
|
43
45
|
// line breaks that `java\nscript:` tricks rely on, so the protocol checked here is the one the browser sees.
|
|
44
46
|
parsed = baseHref ? new URL(trimmed, baseHref) : new URL(trimmed);
|
|
45
47
|
}
|
|
46
|
-
catch {
|
|
48
|
+
catch (_b) {
|
|
47
49
|
return null;
|
|
48
50
|
}
|
|
49
51
|
switch (parsed.protocol) {
|