@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,7 +1,18 @@
|
|
|
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
|
+
};
|
|
1
12
|
import { MediaLibraryError } from './errors';
|
|
2
13
|
import { toSafeMediaUrl } from './urls';
|
|
3
14
|
/** Limits that keep a library's data from breaking the screen. A value over its limit is cut or refused. */
|
|
4
|
-
export
|
|
15
|
+
export var LIMITS = {
|
|
5
16
|
idLength: 512,
|
|
6
17
|
nameLength: 255,
|
|
7
18
|
hashLength: 256,
|
|
@@ -9,10 +20,10 @@ export const LIMITS = {
|
|
|
9
20
|
/** More files than this in one page are ignored. */
|
|
10
21
|
itemsPerPage: 1000
|
|
11
22
|
};
|
|
12
|
-
|
|
23
|
+
var MEDIA_TYPE_PATTERN = /^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/i;
|
|
13
24
|
/** Control characters (line breaks, tabs, NUL ...) have no place in a name shown on one line. */
|
|
14
25
|
// eslint-disable-next-line no-control-regex
|
|
15
|
-
|
|
26
|
+
var CONTROL_CHARACTERS = /[\u0000-\u001f\u007f]+/g;
|
|
16
27
|
function isPlainObject(value) {
|
|
17
28
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
18
29
|
}
|
|
@@ -21,19 +32,19 @@ function toIdOrNull(value) {
|
|
|
21
32
|
return String(value);
|
|
22
33
|
if (typeof value !== 'string')
|
|
23
34
|
return null;
|
|
24
|
-
|
|
35
|
+
var trimmed = value.trim();
|
|
25
36
|
return trimmed !== '' && trimmed.length <= LIMITS.idLength ? trimmed : null;
|
|
26
37
|
}
|
|
27
38
|
function toNameOrNull(value) {
|
|
28
39
|
if (typeof value !== 'string')
|
|
29
40
|
return null;
|
|
30
|
-
|
|
41
|
+
var cleaned = value.replace(CONTROL_CHARACTERS, ' ').trim();
|
|
31
42
|
if (cleaned === '')
|
|
32
43
|
return null;
|
|
33
44
|
return cleaned.length > LIMITS.nameLength ? cleaned.slice(0, LIMITS.nameLength) : cleaned;
|
|
34
45
|
}
|
|
35
46
|
function toIsoDateOrUndefined(value) {
|
|
36
|
-
|
|
47
|
+
var date = null;
|
|
37
48
|
if (value instanceof Date)
|
|
38
49
|
date = value;
|
|
39
50
|
else if (typeof value === 'number' && Number.isFinite(value))
|
|
@@ -49,45 +60,36 @@ function toIsoDateOrUndefined(value) {
|
|
|
49
60
|
* no id, no name, or no address the browser may fetch. Optional fields that are wrong (a size of -1, a media type
|
|
50
61
|
* of `banana`) are dropped instead: the file is still usable without them.
|
|
51
62
|
*/
|
|
52
|
-
export function normalizeMediaLibraryFile(raw, options
|
|
63
|
+
export function normalizeMediaLibraryFile(raw, options) {
|
|
64
|
+
var _a;
|
|
65
|
+
if (options === void 0) { options = {}; }
|
|
53
66
|
if (!isPlainObject(raw)) {
|
|
54
67
|
throw new MediaLibraryError('INVALID_RESPONSE', 'A file in the media library is not an object');
|
|
55
68
|
}
|
|
56
|
-
|
|
69
|
+
var id = toIdOrNull(raw.id);
|
|
57
70
|
if (id === null) {
|
|
58
71
|
throw new MediaLibraryError('INVALID_RESPONSE', 'A file in the media library has no id (a non-empty string)');
|
|
59
72
|
}
|
|
60
|
-
|
|
73
|
+
var name = toNameOrNull(raw.name);
|
|
61
74
|
if (name === null) {
|
|
62
|
-
throw new MediaLibraryError('INVALID_RESPONSE',
|
|
75
|
+
throw new MediaLibraryError('INVALID_RESPONSE', "The file \"".concat(id, "\" in the media library has no name"));
|
|
63
76
|
}
|
|
64
|
-
|
|
77
|
+
var url = toSafeMediaUrl(raw.url, { baseHref: options.baseHref });
|
|
65
78
|
if (url === null) {
|
|
66
|
-
throw new MediaLibraryError('INVALID_RESPONSE',
|
|
79
|
+
throw new MediaLibraryError('INVALID_RESPONSE', "The file \"".concat(id, "\" in the media library has no usable url (it must be an http or https address, or a path on this site)"));
|
|
67
80
|
}
|
|
68
|
-
|
|
81
|
+
var mimeType = typeof raw.mimeType === 'string' && MEDIA_TYPE_PATTERN.test(raw.mimeType.trim())
|
|
69
82
|
? raw.mimeType.trim().toLowerCase()
|
|
70
83
|
: undefined;
|
|
71
|
-
|
|
84
|
+
var size = typeof raw.size === 'number' && Number.isFinite(raw.size) && raw.size >= 0
|
|
72
85
|
? raw.size
|
|
73
86
|
: undefined;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const hash = typeof raw.hash === 'string' && raw.hash !== '' && raw.hash.length <= LIMITS.hashLength
|
|
87
|
+
var thumbnail = (_a = toSafeMediaUrl(raw.thumbnail, { baseHref: options.baseHref, allowDataPicture: true })) !== null && _a !== void 0 ? _a : undefined;
|
|
88
|
+
var hash = typeof raw.hash === 'string' && raw.hash !== '' && raw.hash.length <= LIMITS.hashLength
|
|
77
89
|
? raw.hash
|
|
78
90
|
: undefined;
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
id,
|
|
82
|
-
name,
|
|
83
|
-
type: 'file',
|
|
84
|
-
url,
|
|
85
|
-
...(mimeType !== undefined && { mimeType }),
|
|
86
|
-
...(size !== undefined && { size }),
|
|
87
|
-
...(modified !== undefined && { modified }),
|
|
88
|
-
...(thumbnail !== undefined && { thumbnail }),
|
|
89
|
-
...(hash !== undefined && { hash })
|
|
90
|
-
};
|
|
91
|
+
var modified = toIsoDateOrUndefined(raw.modified);
|
|
92
|
+
return __assign(__assign(__assign(__assign(__assign({ id: id, name: name, type: 'file', url: url }, (mimeType !== undefined && { mimeType: mimeType })), (size !== undefined && { size: size })), (modified !== undefined && { modified: modified })), (thumbnail !== undefined && { thumbnail: thumbnail })), (hash !== undefined && { hash: hash }));
|
|
91
93
|
}
|
|
92
94
|
function toCursorOrNull(value) {
|
|
93
95
|
if (typeof value === 'number' && Number.isFinite(value))
|
|
@@ -102,26 +104,27 @@ function toCursorOrNull(value) {
|
|
|
102
104
|
*
|
|
103
105
|
* Throws only when the page itself is not a page: it is not `{ items: [...] }` (a bare array is accepted too).
|
|
104
106
|
*/
|
|
105
|
-
export function normalizeMediaLibraryPage(raw, options
|
|
106
|
-
|
|
107
|
+
export function normalizeMediaLibraryPage(raw, options) {
|
|
108
|
+
if (options === void 0) { options = {}; }
|
|
109
|
+
var rawItems = Array.isArray(raw) ? raw : isPlainObject(raw) ? raw.items : undefined;
|
|
107
110
|
if (!Array.isArray(rawItems)) {
|
|
108
111
|
throw new MediaLibraryError('INVALID_RESPONSE', "The media library's list must resolve to { items: [...], nextCursor? }");
|
|
109
112
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
var nextCursor = isPlainObject(raw) ? toCursorOrNull(raw.nextCursor) : null;
|
|
114
|
+
var items = [];
|
|
115
|
+
var seenIds = new Set();
|
|
116
|
+
var skippedReasons = [];
|
|
117
|
+
var skipped = 0;
|
|
118
|
+
var note = function (reason) {
|
|
116
119
|
skipped += 1;
|
|
117
120
|
if (skippedReasons.length < 3)
|
|
118
121
|
skippedReasons.push(reason);
|
|
119
122
|
};
|
|
120
|
-
rawItems.slice(0, LIMITS.itemsPerPage).forEach((rawItem)
|
|
123
|
+
rawItems.slice(0, LIMITS.itemsPerPage).forEach(function (rawItem) {
|
|
121
124
|
try {
|
|
122
|
-
|
|
125
|
+
var item = normalizeMediaLibraryFile(rawItem, options);
|
|
123
126
|
if (seenIds.has(item.id)) {
|
|
124
|
-
note(
|
|
127
|
+
note("The file id \"".concat(item.id, "\" appears twice"));
|
|
125
128
|
return;
|
|
126
129
|
}
|
|
127
130
|
seenIds.add(item.id);
|
|
@@ -133,7 +136,7 @@ export function normalizeMediaLibraryPage(raw, options = {}) {
|
|
|
133
136
|
});
|
|
134
137
|
if (rawItems.length > LIMITS.itemsPerPage) {
|
|
135
138
|
skipped += rawItems.length - LIMITS.itemsPerPage;
|
|
136
|
-
skippedReasons.push(
|
|
139
|
+
skippedReasons.push("Only the first ".concat(LIMITS.itemsPerPage, " files of a page are used"));
|
|
137
140
|
}
|
|
138
|
-
return { items, nextCursor, skipped, skippedReasons };
|
|
141
|
+
return { items: items, nextCursor: nextCursor, skipped: skipped, skippedReasons: skippedReasons };
|
|
139
142
|
}
|
|
@@ -1,13 +1,49 @@
|
|
|
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
|
+
};
|
|
1
37
|
import { MediaLibraryError, toMediaLibraryError } from './errors';
|
|
2
38
|
/** How many files the File Browser asks for per page. */
|
|
3
|
-
export
|
|
39
|
+
export var DEFAULT_PAGE_SIZE = 100;
|
|
4
40
|
/**
|
|
5
41
|
* The most files the File Browser loads. Files beyond it are not shown (search and filters only look at the files
|
|
6
42
|
* that were loaded), so a library with more files should list the ones a visitor is most likely to want first.
|
|
7
43
|
*/
|
|
8
|
-
export
|
|
44
|
+
export var DEFAULT_MAX_ITEMS = 1000;
|
|
9
45
|
/** A safety stop: no library is read for more pages than this, whatever it says about having more. */
|
|
10
|
-
export
|
|
46
|
+
export var DEFAULT_MAX_PAGES = 50;
|
|
11
47
|
/**
|
|
12
48
|
* Reads a library page by page, newest first, until it runs out or a limit is reached.
|
|
13
49
|
*
|
|
@@ -17,46 +53,65 @@ export const DEFAULT_MAX_PAGES = 50;
|
|
|
17
53
|
* The first page failing throws (there is nothing to show). A later page failing returns what was loaded with the
|
|
18
54
|
* failure attached, because most of the library is better than none of it.
|
|
19
55
|
*/
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
export function loadLibraryPages(library, options) {
|
|
57
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
58
|
+
var pageSize, maxItems, maxPages, items, seenIds, usedCursors, cursor, pageNumber, page, error_1, failure, newItems, failure;
|
|
59
|
+
var _a, _b, _c, _d;
|
|
60
|
+
return __generator(this, function (_e) {
|
|
61
|
+
switch (_e.label) {
|
|
62
|
+
case 0:
|
|
63
|
+
pageSize = (_a = options.pageSize) !== null && _a !== void 0 ? _a : DEFAULT_PAGE_SIZE;
|
|
64
|
+
maxItems = (_b = options.maxItems) !== null && _b !== void 0 ? _b : DEFAULT_MAX_ITEMS;
|
|
65
|
+
maxPages = (_c = options.maxPages) !== null && _c !== void 0 ? _c : DEFAULT_MAX_PAGES;
|
|
66
|
+
items = [];
|
|
67
|
+
seenIds = new Set();
|
|
68
|
+
usedCursors = new Set();
|
|
69
|
+
pageNumber = 1;
|
|
70
|
+
_e.label = 1;
|
|
71
|
+
case 1:
|
|
72
|
+
if (!(pageNumber <= maxPages)) return [3 /*break*/, 7];
|
|
73
|
+
page = void 0;
|
|
74
|
+
_e.label = 2;
|
|
75
|
+
case 2:
|
|
76
|
+
_e.trys.push([2, 4, , 5]);
|
|
77
|
+
return [4 /*yield*/, library.listPage({ cursor: cursor, limit: pageSize, signal: options.signal })];
|
|
78
|
+
case 3:
|
|
79
|
+
page = _e.sent();
|
|
80
|
+
return [3 /*break*/, 5];
|
|
81
|
+
case 4:
|
|
82
|
+
error_1 = _e.sent();
|
|
83
|
+
failure = toMediaLibraryError(error_1, 'Could not load the files', 'libraryError.loadFailed');
|
|
84
|
+
if (pageNumber === 1 || failure.code === 'ABORTED')
|
|
85
|
+
throw failure;
|
|
86
|
+
console.warn("[FileBrowser] Page ".concat(pageNumber, " of the media library \"").concat(library.id, "\" failed; showing the ").concat(items.length, " files already loaded:"), failure.message);
|
|
87
|
+
return [2 /*return*/, { items: items, truncated: true, failure: failure }];
|
|
88
|
+
case 5:
|
|
89
|
+
if (page.skipped > 0) {
|
|
90
|
+
console.warn("[FileBrowser] The media library \"".concat(library.id, "\" gave ").concat(page.skipped, " file(s) on page ").concat(pageNumber, " that cannot be shown:"), page.skippedReasons);
|
|
91
|
+
}
|
|
92
|
+
newItems = page.items.filter(function (item) { return !seenIds.has(item.id); });
|
|
93
|
+
newItems.forEach(function (item) { return seenIds.add(item.id); });
|
|
94
|
+
items.push.apply(items, newItems);
|
|
95
|
+
if (newItems.length > 0)
|
|
96
|
+
(_d = options.onPage) === null || _d === void 0 ? void 0 : _d.call(options, newItems, pageNumber);
|
|
97
|
+
if (page.nextCursor === null)
|
|
98
|
+
return [2 /*return*/, { items: items, truncated: false }];
|
|
99
|
+
// The library says there is more. Make sure it is not going in circles before asking again.
|
|
100
|
+
if (newItems.length === 0 || usedCursors.has(page.nextCursor) || page.nextCursor === cursor) {
|
|
101
|
+
failure = new MediaLibraryError('INVALID_RESPONSE', 'The media library keeps returning the same files, so the rest was not loaded', { messageKey: 'libraryError.repeatedPage' });
|
|
102
|
+
console.warn("[FileBrowser] The media library \"".concat(library.id, "\" returned a page with nothing new or a repeated cursor; stopping at ").concat(items.length, " files"));
|
|
103
|
+
return [2 /*return*/, { items: items, truncated: true, failure: failure }];
|
|
104
|
+
}
|
|
105
|
+
if (items.length >= maxItems)
|
|
106
|
+
return [2 /*return*/, { items: items, truncated: true }];
|
|
107
|
+
usedCursors.add(page.nextCursor);
|
|
108
|
+
cursor = page.nextCursor;
|
|
109
|
+
_e.label = 6;
|
|
110
|
+
case 6:
|
|
111
|
+
pageNumber += 1;
|
|
112
|
+
return [3 /*break*/, 1];
|
|
113
|
+
case 7: return [2 /*return*/, { items: items, truncated: true }];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
62
117
|
}
|