@emailmaker/filemanager 0.10.103 → 1.1.69
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/.build-meta.json +5 -0
- package/assets/image-editor/fonts/Rubik-Black.woff2 +0 -0
- package/assets/image-editor/fonts/Rubik-Bold.woff2 +0 -0
- package/assets/image-editor/fonts/Rubik-Light.woff2 +0 -0
- package/assets/image-editor/fonts/Rubik-Regular.woff2 +0 -0
- package/assets/image-editor/fonts/caveat-v23-cyrillic_latin-regular.woff2 +0 -0
- package/assets/image-editor/fonts/commissioner-v24-cyrillic_latin-regular.woff2 +0 -0
- package/assets/image-editor/fonts/inter-v20-cyrillic_latin-regular.woff2 +0 -0
- package/assets/image-editor/fonts/oswald-v57-cyrillic_latin-regular.woff2 +0 -0
- package/assets/image-editor/fonts/pacifico-v23-cyrillic_latin-regular.woff2 +0 -0
- package/assets/image-editor/fonts/playfair-display-v40-cyrillic_latin-regular.woff2 +0 -0
- package/components/PixieEditor/PixieEditor.d.ts +1 -2
- package/components/PixieEditor/index.d.ts +4 -1
- package/core.d.ts +21 -0
- package/core.esm.js +2690 -0
- package/core.js +2 -0
- package/{file-manager-IconsTab-Cv51TWYV.js → file-manager-IconsTab-BPDaI1rw.js} +526 -518
- package/{file-manager-ImageCodeGenerator-DroVucLL.js → file-manager-ImageCodeGenerator-Bfcf-n-G.js} +14 -14
- package/{file-manager-JsBarcode-Cji_rnaG.js → file-manager-JsBarcode-CyaffT5b.js} +28 -29
- package/file-manager-PixieEditor-BRUKJkjp.js +597 -0
- package/{file-manager-browser-CweGvoKm.js → file-manager-browser-DDyRNDQk.js} +4 -4
- package/{file-manager-hooks-Dg-OcR_x.js → file-manager-hooks-aNT0w8kI.js} +2527 -2364
- package/{file-manager-rolldown-runtime-DtPi1Y-2.js → file-manager-rolldown-runtime-DAVfCfog.js} +11 -4
- package/file-manager-urls-DN9gaYil.js +37 -0
- package/{file-manager-useMediaListEngine-ByGmaaib.js → file-manager-useMediaListEngine-zkDk3m1H.js} +6 -6
- package/file-manager.css +1 -1
- package/file-manager.esm.js +2930 -3609
- package/file-manager.js +11 -11
- package/package.json +24 -1
- package/utils/iconCssVars.d.ts +12 -0
- package/utils/svgToPng.test.d.ts +1 -0
package/core.esm.js
ADDED
|
@@ -0,0 +1,2690 @@
|
|
|
1
|
+
//#region packages/file-manager/src/shared/fileManagerApiError.ts
|
|
2
|
+
var e = class e extends Error {
|
|
3
|
+
constructor(t, n, r, i) {
|
|
4
|
+
super(t), this.code = n, this.status = r, this.details = i, this.name = "FileManagerApiError", Error.captureStackTrace && Error.captureStackTrace(this, e);
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region packages/file-manager/src/shared/mapHttpStatusToErrorCode.ts
|
|
9
|
+
function t(e, t = "BackendError") {
|
|
10
|
+
switch (e) {
|
|
11
|
+
case 400: return "ValidationError";
|
|
12
|
+
case 401: return "AuthenticationFailed";
|
|
13
|
+
case 403: return "AuthorizationFailed";
|
|
14
|
+
case 404: return "FileNotFound";
|
|
15
|
+
case 413: return "PayloadTooLarge";
|
|
16
|
+
case 415: return "UnsupportedMediaType";
|
|
17
|
+
case 429: return "RateLimitExceeded";
|
|
18
|
+
case 500: return "BackendError";
|
|
19
|
+
case 503: return "ServiceUnavailable";
|
|
20
|
+
case 504: return "Timeout";
|
|
21
|
+
default: return t;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region packages/file-manager/src/helpers/urls.ts
|
|
26
|
+
function n(e, t) {
|
|
27
|
+
return e ? t ? `${e.replace(/\/+$/, "")}/${t.replace(/^\/+/, "")}` : e : t;
|
|
28
|
+
}
|
|
29
|
+
function r(e) {
|
|
30
|
+
let t = typeof __webpack_public_path__ < "u" ? __webpack_public_path__ : "";
|
|
31
|
+
if (e && /^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(e)) return e;
|
|
32
|
+
let r = n(t, e || "");
|
|
33
|
+
return r && !r.startsWith("/") && !/^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(r) && (r = "/" + r), r;
|
|
34
|
+
}
|
|
35
|
+
function i(e, t) {
|
|
36
|
+
if (/^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(t)) return t;
|
|
37
|
+
let i = n(r(e), t || "");
|
|
38
|
+
return i && !i.startsWith("/") && !/^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(i) ? "/" + i : i;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region packages/file-manager/src/adapters/FailedRequestCache.ts
|
|
42
|
+
var a = "", o = class {
|
|
43
|
+
constructor() {
|
|
44
|
+
this.map = /* @__PURE__ */ new Map();
|
|
45
|
+
}
|
|
46
|
+
static childrenViewKey(e, t) {
|
|
47
|
+
return `v${a}${e}${a}${t}`;
|
|
48
|
+
}
|
|
49
|
+
static childrenCountKey(e) {
|
|
50
|
+
return `c${a}${e}`;
|
|
51
|
+
}
|
|
52
|
+
getFreshError(e, t) {
|
|
53
|
+
let n = this.map.get(e);
|
|
54
|
+
return n ? t !== Infinity && Date.now() - n.updatedAt > t ? (this.map.delete(e), null) : n.error : null;
|
|
55
|
+
}
|
|
56
|
+
setError(e, t) {
|
|
57
|
+
this.map.set(e, {
|
|
58
|
+
error: t,
|
|
59
|
+
updatedAt: Date.now()
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
delete(e) {
|
|
63
|
+
this.map.delete(e);
|
|
64
|
+
}
|
|
65
|
+
clearChildrenViewErrorsForParent(e) {
|
|
66
|
+
let t = `v${a}${e}${a}`;
|
|
67
|
+
for (let e of [...this.map.keys()]) e.startsWith(t) && this.map.delete(e);
|
|
68
|
+
}
|
|
69
|
+
clearAll() {
|
|
70
|
+
this.map.clear();
|
|
71
|
+
}
|
|
72
|
+
}, s = class {
|
|
73
|
+
constructor() {
|
|
74
|
+
this.deletingIds = /* @__PURE__ */ new Set();
|
|
75
|
+
}
|
|
76
|
+
beginDeleting(e) {
|
|
77
|
+
for (let t of e) t && this.deletingIds.add(t);
|
|
78
|
+
}
|
|
79
|
+
endDeleting(e) {
|
|
80
|
+
for (let t of e) t && this.deletingIds.delete(t);
|
|
81
|
+
}
|
|
82
|
+
isDeleting(e) {
|
|
83
|
+
return !!e && this.deletingIds.has(e);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region packages/file-manager/src/adapters/cacheViewStrategy.ts
|
|
88
|
+
function c(e) {
|
|
89
|
+
return {
|
|
90
|
+
sortBy: e?.sortBy ?? "name",
|
|
91
|
+
sortOrder: e?.sortOrder == null ? e?.sortBy != null && e.sortBy !== "" ? "desc" : "asc" : e.sortOrder === "desc" ? "desc" : "asc"
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function l(e, t, n) {
|
|
95
|
+
let { sortBy: r, sortOrder: i } = c(n), a = 0;
|
|
96
|
+
switch (r) {
|
|
97
|
+
case "name":
|
|
98
|
+
a = (e.name || "").localeCompare(t.name || "");
|
|
99
|
+
break;
|
|
100
|
+
case "date":
|
|
101
|
+
a = new Date(e.date || 0).getTime() - new Date(t.date || 0).getTime();
|
|
102
|
+
break;
|
|
103
|
+
case "size":
|
|
104
|
+
a = (Number(e.size) || 0) - (Number(t.size) || 0);
|
|
105
|
+
break;
|
|
106
|
+
case "type":
|
|
107
|
+
a = (e.extension || e.type || "").toLowerCase().localeCompare((t.extension || t.type || "").toLowerCase());
|
|
108
|
+
break;
|
|
109
|
+
default: a = (e.name || "").localeCompare(t.name || "");
|
|
110
|
+
}
|
|
111
|
+
return i === "desc" ? -a : a;
|
|
112
|
+
}
|
|
113
|
+
function u(e) {
|
|
114
|
+
return e != null && String(e).trim() !== "";
|
|
115
|
+
}
|
|
116
|
+
function d(e, t) {
|
|
117
|
+
let { sortBy: n } = c(t);
|
|
118
|
+
switch (n) {
|
|
119
|
+
case "date": return u(e.date) ? !Number.isNaN(new Date(e.date).getTime()) : !1;
|
|
120
|
+
case "size": return e.size != null && Number.isFinite(Number(e.size));
|
|
121
|
+
case "type": return u(e.extension) || u(e.type);
|
|
122
|
+
default: return u(e.name);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function f(e, t) {
|
|
126
|
+
let n = typeof t?.search == "string" ? t.search.trim() : "";
|
|
127
|
+
if (!n) return !0;
|
|
128
|
+
let r = n.toLowerCase();
|
|
129
|
+
return (e.name?.toLowerCase().includes(r) ?? !1) || (e.type?.toLowerCase().includes(r) ?? !1) || (e.extension?.toLowerCase().includes(r) ?? !1);
|
|
130
|
+
}
|
|
131
|
+
var p = l, m = f, h = d;
|
|
132
|
+
function g(e = {}) {
|
|
133
|
+
return {
|
|
134
|
+
...e,
|
|
135
|
+
comparator: e.comparator ?? p,
|
|
136
|
+
filterMatch: e.filterMatch ?? m,
|
|
137
|
+
hasSortValue: e.hasSortValue ?? h
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region packages/file-manager/src/adapters/systemFolderPath.ts
|
|
142
|
+
var _ = "Trash";
|
|
143
|
+
function v(e) {
|
|
144
|
+
return e.replace(/\\/g, "/").replace(/^\/+|\/+$/g, "");
|
|
145
|
+
}
|
|
146
|
+
function y(e, t, n = _) {
|
|
147
|
+
let r = v(e);
|
|
148
|
+
if (!r) return [];
|
|
149
|
+
let i = [e, r];
|
|
150
|
+
if (r === v(t)) {
|
|
151
|
+
i.push(t);
|
|
152
|
+
let e = v(t);
|
|
153
|
+
e === "Trash" || e.toLowerCase() === "trash" ? i.push(n, _, _.toLowerCase()) : n !== "Trash" && v(n) !== e && i.push(n);
|
|
154
|
+
}
|
|
155
|
+
return Array.from(new Set(i.map(v).filter(Boolean)));
|
|
156
|
+
}
|
|
157
|
+
function b(e) {
|
|
158
|
+
let t = /* @__PURE__ */ new Map();
|
|
159
|
+
for (let [n, r] of Object.entries(e)) r.id && t.set(v(n), r);
|
|
160
|
+
return (e) => {
|
|
161
|
+
let n = t.get(v(e));
|
|
162
|
+
if (n) return {
|
|
163
|
+
id: n.id,
|
|
164
|
+
name: n.name ?? n.id,
|
|
165
|
+
folderId: n.folderId ?? null,
|
|
166
|
+
isFolder: !0
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region packages/file-manager/src/adapters/TreeCache.ts
|
|
172
|
+
var x = "", S = 1800 * 1e3;
|
|
173
|
+
function C(e) {
|
|
174
|
+
return e == null || e === "" ? x : e;
|
|
175
|
+
}
|
|
176
|
+
function w(e) {
|
|
177
|
+
if (e == null) return Infinity;
|
|
178
|
+
let t = Number(e);
|
|
179
|
+
return Number.isFinite(t) && t >= 0 ? t : Infinity;
|
|
180
|
+
}
|
|
181
|
+
function T(e) {
|
|
182
|
+
return !e || typeof e.search != "string" ? !1 : e.search.trim().length > 0;
|
|
183
|
+
}
|
|
184
|
+
function E(e) {
|
|
185
|
+
if (!e) return null;
|
|
186
|
+
let t = e.folderId;
|
|
187
|
+
return t == null ? null : String(t);
|
|
188
|
+
}
|
|
189
|
+
function D(e) {
|
|
190
|
+
return !!e && !!e.isFolder;
|
|
191
|
+
}
|
|
192
|
+
function O() {
|
|
193
|
+
if (typeof globalThis?.crypto?.randomUUID == "function") return globalThis.crypto.randomUUID();
|
|
194
|
+
try {
|
|
195
|
+
let e = globalThis.crypto || globalThis.msCrypto;
|
|
196
|
+
if (e && typeof e.getRandomValues == "function") {
|
|
197
|
+
let t = /* @__PURE__ */ new Uint8Array(16);
|
|
198
|
+
e.getRandomValues(t);
|
|
199
|
+
let n = "";
|
|
200
|
+
for (let e = 0; e < t.length; e++) n += t[e].toString(16).padStart(2, "0");
|
|
201
|
+
return `id_${n}`;
|
|
202
|
+
}
|
|
203
|
+
} catch {}
|
|
204
|
+
return `id_fallback_${Date.now().toString(36)}_${Math.floor(Math.random() * (2 ** 53 - 1)).toString(36).slice(0, 8)}`;
|
|
205
|
+
}
|
|
206
|
+
function k(e) {
|
|
207
|
+
if (!e || typeof e != "object") return !1;
|
|
208
|
+
let t = e;
|
|
209
|
+
return t.code === "path_folder_not_found" || t.code === "folder_not_found" || t.code === "FolderNotFound" || t.data?.code === "path_folder_not_found" || t.data?.code === "folder_not_found" || t.status === 404 || t.data?.data?.status === 404;
|
|
210
|
+
}
|
|
211
|
+
function A(e) {
|
|
212
|
+
let t = 2166136261;
|
|
213
|
+
for (let n = 0; n < e.length; n++) t ^= e.charCodeAt(n), t = t + ((t << 1) + (t << 4) + (t << 7) + (t << 8) + (t << 24)) >>> 0;
|
|
214
|
+
return t.toString(36);
|
|
215
|
+
}
|
|
216
|
+
function j(e) {
|
|
217
|
+
if (!e || typeof e != "object") return String(e ?? "");
|
|
218
|
+
let t = e, n = [], r = {}, i = [
|
|
219
|
+
"page",
|
|
220
|
+
"pageSize",
|
|
221
|
+
"sortBy",
|
|
222
|
+
"sortOrder",
|
|
223
|
+
"search",
|
|
224
|
+
"itemType",
|
|
225
|
+
"limit"
|
|
226
|
+
];
|
|
227
|
+
for (let e of Object.keys(t).sort()) {
|
|
228
|
+
let a = t[e];
|
|
229
|
+
i.includes(e) ? n.push(`${e}=${String(a ?? "")}`) : r[e] = a;
|
|
230
|
+
}
|
|
231
|
+
let a = Object.keys(r).length ? JSON.stringify(r) : "", o = n.join("|"), s = a ? A(a) : "";
|
|
232
|
+
return `${o}${s ? `|${s}` : ""}`;
|
|
233
|
+
}
|
|
234
|
+
var M = class e {
|
|
235
|
+
constructor() {
|
|
236
|
+
this.entities = /* @__PURE__ */ new Map(), this.childrenByParent = /* @__PURE__ */ new Map(), this.maxCacheSize = 1e4;
|
|
237
|
+
}
|
|
238
|
+
now() {
|
|
239
|
+
return Date.now();
|
|
240
|
+
}
|
|
241
|
+
checkCacheSize() {
|
|
242
|
+
if (this.entities.size > this.maxCacheSize) {
|
|
243
|
+
let e = Array.from(this.entities.entries()).sort((e, t) => e[1].updatedAt - t[1].updatedAt), t = Math.floor(this.maxCacheSize * .1);
|
|
244
|
+
for (let n = 0; n < t && n < e.length; n++) {
|
|
245
|
+
let [t, r] = e[n];
|
|
246
|
+
this.deleteEntityById(t);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
getEntity(e) {
|
|
251
|
+
return this.entities.get(e)?.value;
|
|
252
|
+
}
|
|
253
|
+
getRecord(e) {
|
|
254
|
+
return this.entities.get(e);
|
|
255
|
+
}
|
|
256
|
+
getFileSystemItem(e) {
|
|
257
|
+
let t = this.getEntity(e);
|
|
258
|
+
return t && !D(t) ? t : void 0;
|
|
259
|
+
}
|
|
260
|
+
getFolder(e) {
|
|
261
|
+
let t = this.getEntity(e);
|
|
262
|
+
return t && D(t) ? t : void 0;
|
|
263
|
+
}
|
|
264
|
+
getChildrenIds(e, t = {}) {
|
|
265
|
+
let n = C(e), r = this.childrenByParent.get(n);
|
|
266
|
+
return r ? t.onlyFileSystemItems ? Array.from(r.files) : t.onlyFolders ? Array.from(r.folders) : [...Array.from(r.folders), ...Array.from(r.files)] : [];
|
|
267
|
+
}
|
|
268
|
+
searchByUrl(e) {
|
|
269
|
+
for (let t of this.entities.values()) if (t.value.url === e) return t.value;
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
upsertEntity(e) {
|
|
273
|
+
let t = this.entities.get(e.id) ?? null, n = t ? t.value : null, r = n ? E(n) : null, i = E(e), a = n ? D(n) : !1, o = D(e), s;
|
|
274
|
+
if (n && D(n) && o) {
|
|
275
|
+
let t = n.childrenCount, r = e.childrenCount;
|
|
276
|
+
t !== void 0 && r === void 0 && (s = t);
|
|
277
|
+
}
|
|
278
|
+
if (n && (r !== i || a !== o)) {
|
|
279
|
+
let t = C(r), n = this.childrenByParent.get(t);
|
|
280
|
+
n && (a ? n.folders.delete(e.id) : n.files.delete(e.id), n.files.size === 0 && n.folders.size === 0 && this.childrenByParent.delete(t));
|
|
281
|
+
}
|
|
282
|
+
let c = e;
|
|
283
|
+
s !== void 0 && (c = {
|
|
284
|
+
...e,
|
|
285
|
+
childrenCount: s
|
|
286
|
+
}), this.entities.set(e.id, {
|
|
287
|
+
value: { ...c },
|
|
288
|
+
updatedAt: this.now()
|
|
289
|
+
}), this.checkCacheSize();
|
|
290
|
+
let l = C(i), u = this.childrenByParent.get(l);
|
|
291
|
+
u || (u = {
|
|
292
|
+
files: /* @__PURE__ */ new Set(),
|
|
293
|
+
folders: /* @__PURE__ */ new Set()
|
|
294
|
+
}, this.childrenByParent.set(l, u)), o ? u.folders.add(e.id) : u.files.add(e.id);
|
|
295
|
+
}
|
|
296
|
+
updateServerChildrenCount(e, t) {
|
|
297
|
+
if (e == null || t == null || Number.isNaN(t)) return;
|
|
298
|
+
let n = this.entities.get(e);
|
|
299
|
+
if (!n || !D(n.value)) return;
|
|
300
|
+
let r = {
|
|
301
|
+
...n.value,
|
|
302
|
+
childrenCount: t
|
|
303
|
+
};
|
|
304
|
+
this.entities.set(e, {
|
|
305
|
+
value: r,
|
|
306
|
+
updatedAt: this.now()
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
deleteEntityById(e) {
|
|
310
|
+
let t = this.entities.get(e) ?? null;
|
|
311
|
+
if (!t) return {
|
|
312
|
+
entity: null,
|
|
313
|
+
parentId: null
|
|
314
|
+
};
|
|
315
|
+
let n = t.value, r = E(n), i = C(r), a = this.childrenByParent.get(i);
|
|
316
|
+
return a && (D(n) ? a.folders.delete(e) : a.files.delete(e), a.files.size === 0 && a.folders.size === 0 && this.childrenByParent.delete(i)), this.entities.delete(e), {
|
|
317
|
+
entity: { ...n },
|
|
318
|
+
parentId: r
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
deleteFolderRecursive(e) {
|
|
322
|
+
let t = this.entities.get(e);
|
|
323
|
+
if (!t || !D(t.value)) return {
|
|
324
|
+
deletedFolderRecords: [],
|
|
325
|
+
deletedFileSystemItemRecords: []
|
|
326
|
+
};
|
|
327
|
+
let n = [{
|
|
328
|
+
id: e,
|
|
329
|
+
parentId: E(t.value)
|
|
330
|
+
}], r = [], i = [];
|
|
331
|
+
for (; n.length;) {
|
|
332
|
+
let e = n.shift();
|
|
333
|
+
r.push(e);
|
|
334
|
+
let t = this.childrenByParent.get(C(e.id));
|
|
335
|
+
if (t) {
|
|
336
|
+
for (let e of Array.from(t.folders)) {
|
|
337
|
+
let t = this.entities.get(e);
|
|
338
|
+
t && n.push({
|
|
339
|
+
id: e,
|
|
340
|
+
parentId: E(t.value)
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
for (let e of Array.from(t.files)) i.push(e);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
let a = [];
|
|
347
|
+
for (let e of i) {
|
|
348
|
+
let t = this.entities.get(e);
|
|
349
|
+
if (!t) continue;
|
|
350
|
+
let n = t.value, r = C(E(n)), i = this.childrenByParent.get(r);
|
|
351
|
+
i && (i.files.delete(e), i.files.size === 0 && i.folders.size === 0 && this.childrenByParent.delete(r)), this.entities.delete(e), a.push({ ...n });
|
|
352
|
+
}
|
|
353
|
+
let o = [];
|
|
354
|
+
for (let e = r.length - 1; e >= 0; e--) {
|
|
355
|
+
let { id: t, parentId: n } = r[e], i = this.entities.get(t);
|
|
356
|
+
if (!i) continue;
|
|
357
|
+
let a = i.value, s = C(a.id);
|
|
358
|
+
this.childrenByParent.delete(s);
|
|
359
|
+
let c = C(n), l = this.childrenByParent.get(c);
|
|
360
|
+
l && (l.folders.delete(t), l.files.size === 0 && l.folders.size === 0 && this.childrenByParent.delete(c)), this.entities.delete(t), o.push({ ...a });
|
|
361
|
+
}
|
|
362
|
+
return {
|
|
363
|
+
deletedFolderRecords: o,
|
|
364
|
+
deletedFileSystemItemRecords: a
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
moveEntityById(e, t) {
|
|
368
|
+
let n = this.entities.get(e) ?? null;
|
|
369
|
+
if (!n) return null;
|
|
370
|
+
let r = n.value, i = C(E(r)), a = this.childrenByParent.get(i);
|
|
371
|
+
a && (D(r) ? a.folders.delete(e) : a.files.delete(e), a.files.size === 0 && a.folders.size === 0 && this.childrenByParent.delete(i));
|
|
372
|
+
let o = {
|
|
373
|
+
...r,
|
|
374
|
+
folderId: t
|
|
375
|
+
};
|
|
376
|
+
if (D(r) && D(o)) {
|
|
377
|
+
let e = r.childrenCount;
|
|
378
|
+
e !== void 0 && (o.childrenCount = e);
|
|
379
|
+
}
|
|
380
|
+
this.entities.set(e, {
|
|
381
|
+
value: o,
|
|
382
|
+
updatedAt: this.now()
|
|
383
|
+
});
|
|
384
|
+
let s = C(t), c = this.childrenByParent.get(s);
|
|
385
|
+
return c || (c = {
|
|
386
|
+
files: /* @__PURE__ */ new Set(),
|
|
387
|
+
folders: /* @__PURE__ */ new Set()
|
|
388
|
+
}, this.childrenByParent.set(s, c)), D(o) ? c.folders.add(e) : c.files.add(e), { ...o };
|
|
389
|
+
}
|
|
390
|
+
copyFileSystemItem(e, t, n) {
|
|
391
|
+
let r = this.entities.get(e) ?? null;
|
|
392
|
+
if (!r || D(r.value)) return null;
|
|
393
|
+
let i = {
|
|
394
|
+
...r.value,
|
|
395
|
+
id: t,
|
|
396
|
+
folderId: n
|
|
397
|
+
};
|
|
398
|
+
return this.upsertEntity(i), { ...i };
|
|
399
|
+
}
|
|
400
|
+
copyFolderShallow(e, t, n) {
|
|
401
|
+
let r = this.entities.get(e) ?? null;
|
|
402
|
+
if (!r || !D(r.value)) return null;
|
|
403
|
+
let i = {
|
|
404
|
+
...r.value,
|
|
405
|
+
id: t,
|
|
406
|
+
folderId: n
|
|
407
|
+
};
|
|
408
|
+
return this.upsertEntity(i), { ...i };
|
|
409
|
+
}
|
|
410
|
+
isEntityStale(e, t) {
|
|
411
|
+
let n = this.entities.get(e) ?? null;
|
|
412
|
+
return !n || t !== Infinity && this.now() - n.updatedAt > t;
|
|
413
|
+
}
|
|
414
|
+
touch(e, t) {
|
|
415
|
+
let n = this.entities.get(e);
|
|
416
|
+
n && (n.updatedAt = t ?? this.now());
|
|
417
|
+
}
|
|
418
|
+
getEntitiesByIds(e) {
|
|
419
|
+
return e.map((e) => this.entities.get(e)?.value ?? null);
|
|
420
|
+
}
|
|
421
|
+
searchByName(e, t) {
|
|
422
|
+
if (!e || e.trim() === "") return [];
|
|
423
|
+
let n = t?.parentId, r = t?.recursive ?? !1, i = t?.itemType ?? "all", a = t?.caseSensitive ?? !1, o = t?.limit ?? Infinity, s = a ? e.trim() : e.trim().toLowerCase(), c = [], l = null;
|
|
424
|
+
if (n !== void 0) {
|
|
425
|
+
l = /* @__PURE__ */ new Set();
|
|
426
|
+
let e = C(n);
|
|
427
|
+
if (l.add(e), r) {
|
|
428
|
+
let t = [e], n = /* @__PURE__ */ new Set();
|
|
429
|
+
for (; t.length > 0;) {
|
|
430
|
+
let e = t.shift();
|
|
431
|
+
if (n.has(e)) continue;
|
|
432
|
+
n.add(e);
|
|
433
|
+
let r = this.childrenByParent.get(e);
|
|
434
|
+
if (r) for (let e of r.folders) l.add(e), t.push(e);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
for (let [, e] of this.entities) {
|
|
439
|
+
if (c.length >= o) break;
|
|
440
|
+
let t = e.value;
|
|
441
|
+
if (l !== null) {
|
|
442
|
+
let e = C(E(t));
|
|
443
|
+
if (!l.has(e)) continue;
|
|
444
|
+
}
|
|
445
|
+
if (i === "file" && D(t) || i === "folder" && !D(t)) continue;
|
|
446
|
+
let n = t.name ?? "";
|
|
447
|
+
(a ? n : n.toLowerCase()).includes(s) && c.push({ ...t });
|
|
448
|
+
}
|
|
449
|
+
return c;
|
|
450
|
+
}
|
|
451
|
+
toJSON() {
|
|
452
|
+
return {
|
|
453
|
+
entities: Array.from(this.entities.entries()),
|
|
454
|
+
childrenByParent: Array.from(this.childrenByParent.entries()).map(([e, t]) => [e, {
|
|
455
|
+
files: Array.from(t.files),
|
|
456
|
+
folders: Array.from(t.folders)
|
|
457
|
+
}])
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
static fromJSON(t) {
|
|
461
|
+
let n = new e();
|
|
462
|
+
for (let [e, r] of t.entities ?? []) n.entities.set(e, {
|
|
463
|
+
value: r.value,
|
|
464
|
+
updatedAt: r.updatedAt
|
|
465
|
+
});
|
|
466
|
+
for (let [e, r] of t.childrenByParent ?? []) n.childrenByParent.set(e, {
|
|
467
|
+
files: new Set(r.files),
|
|
468
|
+
folders: new Set(r.folders)
|
|
469
|
+
});
|
|
470
|
+
return n;
|
|
471
|
+
}
|
|
472
|
+
}, N = class e {
|
|
473
|
+
constructor(e = {}, t = S, n, r, i = new o(), a = k) {
|
|
474
|
+
this.views = /* @__PURE__ */ new Map(), this.maxViewsPerParent = 50;
|
|
475
|
+
let s = g(e);
|
|
476
|
+
this.strategy = {
|
|
477
|
+
allowSortedInsert: s.allowSortedInsert ?? !0,
|
|
478
|
+
allowSearchInsert: s.allowSearchInsert ?? !0,
|
|
479
|
+
invalidateOnPaginationFull: s.invalidateOnPaginationFull ?? !0,
|
|
480
|
+
preloadPagesBefore: s.preloadPagesBefore ?? 0,
|
|
481
|
+
preloadPagesAfter: s.preloadPagesAfter ?? 1,
|
|
482
|
+
comparator: s.comparator,
|
|
483
|
+
filterMatch: s.filterMatch,
|
|
484
|
+
hasSortValue: s.hasSortValue
|
|
485
|
+
}, this.ttl = t, this.errorTtl = n ?? t, this.entityTtl = r ?? t, this.failedRequests = i, this.isFolderNotFoundError = a;
|
|
486
|
+
}
|
|
487
|
+
setServerChildrenCountHandler(e) {
|
|
488
|
+
this.serverChildrenCountHandler = e;
|
|
489
|
+
}
|
|
490
|
+
setChildrenCountInvalidator(e) {
|
|
491
|
+
this.childrenCountInvalidator = e;
|
|
492
|
+
}
|
|
493
|
+
now() {
|
|
494
|
+
return Date.now();
|
|
495
|
+
}
|
|
496
|
+
parentKey(e) {
|
|
497
|
+
return C(e ?? null);
|
|
498
|
+
}
|
|
499
|
+
isExpired(e) {
|
|
500
|
+
return e == null || this.ttl !== Infinity && this.now() - e > this.ttl;
|
|
501
|
+
}
|
|
502
|
+
areEntitiesStale(e, t) {
|
|
503
|
+
return !e || e.some((e) => !t.getEntity(e) || t.isEntityStale(e, this.entityTtl));
|
|
504
|
+
}
|
|
505
|
+
isEntityTypeCompatible(e, t) {
|
|
506
|
+
return !!(!t || t === "all" || t === "file" && !D(e) || t === "folder" && D(e));
|
|
507
|
+
}
|
|
508
|
+
markViewStaleForReload(e) {
|
|
509
|
+
e.view.meta = {
|
|
510
|
+
...e.view.meta ?? {},
|
|
511
|
+
stale: !0
|
|
512
|
+
}, e.view.updatedAt = this.now(), e.view.loadId = O(), e.view.abortController && (e.view.abortController.abort(), e.view.abortController = void 0);
|
|
513
|
+
}
|
|
514
|
+
cleanupOldViews(e) {
|
|
515
|
+
if (e.size <= this.maxViewsPerParent) return;
|
|
516
|
+
let t = Array.from(e.entries()).sort((e, t) => (t[1].view.updatedAt || 0) - (e[1].view.updatedAt || 0));
|
|
517
|
+
for (; e.size > this.maxViewsPerParent && t.length > 0;) {
|
|
518
|
+
let [n] = t.pop();
|
|
519
|
+
e.delete(n);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
async getOrCreateChildren(e, t, n, r) {
|
|
523
|
+
let i = this.parentKey(e), a = j(t ?? {}), s = this.views.get(i);
|
|
524
|
+
s || (s = /* @__PURE__ */ new Map(), this.views.set(i, s));
|
|
525
|
+
let c = o.childrenViewKey(i, a), l = s.get(a);
|
|
526
|
+
l || (l = {
|
|
527
|
+
params: t,
|
|
528
|
+
view: {
|
|
529
|
+
promise: null,
|
|
530
|
+
value: void 0,
|
|
531
|
+
meta: void 0,
|
|
532
|
+
updatedAt: 0,
|
|
533
|
+
loadId: null
|
|
534
|
+
}
|
|
535
|
+
}, s.set(a, l), this.cleanupOldViews(s));
|
|
536
|
+
let u = this.failedRequests.getFreshError(c, this.errorTtl);
|
|
537
|
+
if (u != null) throw u;
|
|
538
|
+
if (l.view.value && !this.isExpired(l.view.updatedAt) && !this.areEntitiesStale(l.view.value, r) && !l.view.meta?.stale) {
|
|
539
|
+
let e = l.view.value.map((e) => r.getEntity(e)).filter(Boolean), t = l.params?.itemType || "all";
|
|
540
|
+
return {
|
|
541
|
+
items: e.filter((e) => this.isEntityTypeCompatible(e, t)),
|
|
542
|
+
...l.view.meta ?? {}
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
if (l.view.promise) return l.view.promise;
|
|
546
|
+
let d = O();
|
|
547
|
+
l.view.loadId = d;
|
|
548
|
+
let f = (async () => {
|
|
549
|
+
try {
|
|
550
|
+
let a = await n(e, t), o = T(t), s = o ? {
|
|
551
|
+
...a,
|
|
552
|
+
total: void 0
|
|
553
|
+
} : a, u = this.views.get(i)?.get(j(t));
|
|
554
|
+
if (!u || u.view.loadId !== d) {
|
|
555
|
+
let e = /* @__PURE__ */ Error("StaleLoad");
|
|
556
|
+
throw e.name = "StaleLoad", e;
|
|
557
|
+
}
|
|
558
|
+
for (let e of s.items) r.upsertEntity(e);
|
|
559
|
+
l.view.value = s.items.map((e) => e.id);
|
|
560
|
+
let { items: f, ...p } = s, m = { ...p };
|
|
561
|
+
l.view.meta = m, l.view.meta && (l.view.meta.stale = !1), this.failedRequests.delete(c), l.view.updatedAt = this.now(), !o && typeof m.total == "number" && (this.serverChildrenCountHandler ? this.serverChildrenCountHandler(e ?? null, m.total, r) : r.updateServerChildrenCount(e, m.total));
|
|
562
|
+
let h = this.strategy.preloadPagesAfter ?? 0, g = this.strategy.preloadPagesBefore ?? 0, _ = w(t?.pageSize);
|
|
563
|
+
if ((h > 0 || g > 0) && Number.isFinite(_)) {
|
|
564
|
+
let i = e, a = { ...t }, o = typeof m.totalPages == "number" ? m.totalPages : 1, s = t?.page ?? 1, c = _, l = n, u = d;
|
|
565
|
+
setTimeout(() => {
|
|
566
|
+
this.preloadPagesAsync(i, a, s, o, c, h, g, r, m, l, u);
|
|
567
|
+
}, 0);
|
|
568
|
+
}
|
|
569
|
+
return s;
|
|
570
|
+
} catch (e) {
|
|
571
|
+
if (e?.name === "StaleLoad") throw this.failedRequests.delete(c), l.view.value = void 0, l.view.updatedAt = this.now(), e;
|
|
572
|
+
if (this.isFolderNotFoundError(e)) return this.failedRequests.delete(c), l.view.value = [], l.view.meta = {
|
|
573
|
+
total: 0,
|
|
574
|
+
totalPages: 0
|
|
575
|
+
}, l.view.updatedAt = this.now(), {
|
|
576
|
+
items: [],
|
|
577
|
+
total: 0,
|
|
578
|
+
totalPages: 0
|
|
579
|
+
};
|
|
580
|
+
throw this.failedRequests.setError(c, e), l.view.value = void 0, l.view.updatedAt = this.now(), e;
|
|
581
|
+
} finally {
|
|
582
|
+
l.view.promise = null;
|
|
583
|
+
}
|
|
584
|
+
})();
|
|
585
|
+
return l.view.promise = f, f;
|
|
586
|
+
}
|
|
587
|
+
async preloadPagesAsync(e, t, n, r, i, a, o, s, c, l, u) {
|
|
588
|
+
try {
|
|
589
|
+
let i = this.parentKey(e), c = this.views.get(i);
|
|
590
|
+
if (!c) return;
|
|
591
|
+
let d = c.get(j(t));
|
|
592
|
+
if (!d || u != null && d.view.loadId !== u) return;
|
|
593
|
+
let f = c.get(j(t));
|
|
594
|
+
if (!f?.view.meta) return;
|
|
595
|
+
let p = typeof f.view.meta.totalPages == "number" ? f.view.meta.totalPages : 1;
|
|
596
|
+
if (p !== r) return;
|
|
597
|
+
let m = async (n) => {
|
|
598
|
+
let r = {
|
|
599
|
+
...t,
|
|
600
|
+
page: n
|
|
601
|
+
};
|
|
602
|
+
try {
|
|
603
|
+
let a = await l(e, r), o = this.views.get(i);
|
|
604
|
+
if (!o) return;
|
|
605
|
+
let c = o.get(j(t));
|
|
606
|
+
if (!c || u != null && c.view.loadId !== u || c.view.loadId !== u) return;
|
|
607
|
+
for (let e of a.items) s.upsertEntity(e);
|
|
608
|
+
let d = j(r), f = o.get(d);
|
|
609
|
+
if (f || (f = {
|
|
610
|
+
params: r,
|
|
611
|
+
view: {
|
|
612
|
+
promise: null,
|
|
613
|
+
value: void 0,
|
|
614
|
+
meta: void 0,
|
|
615
|
+
updatedAt: 0,
|
|
616
|
+
loadId: c.view.loadId
|
|
617
|
+
}
|
|
618
|
+
}, o.set(d, f), this.cleanupOldViews(o)), !f.view.value || this.isExpired(f.view.updatedAt)) {
|
|
619
|
+
f.view.value = a.items.map((e) => e.id);
|
|
620
|
+
let { items: e, ...t } = a;
|
|
621
|
+
f.view.meta = {
|
|
622
|
+
...t,
|
|
623
|
+
page: n,
|
|
624
|
+
totalPages: p
|
|
625
|
+
}, f.view.updatedAt = this.now();
|
|
626
|
+
}
|
|
627
|
+
} catch (e) {
|
|
628
|
+
console.debug("Preload failed silently:", e);
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
if (a > 0 && n < p) for (let e = 1; e <= Math.min(a, p - n); e++) {
|
|
632
|
+
let r = n + e, i = j({
|
|
633
|
+
...t,
|
|
634
|
+
page: r
|
|
635
|
+
}), a = c.get(i);
|
|
636
|
+
(!a?.view.value || this.isExpired(a.view.updatedAt)) && m(r);
|
|
637
|
+
}
|
|
638
|
+
if (o > 0 && n > 1) for (let e = 1; e <= Math.min(o, n - 1); e++) {
|
|
639
|
+
let r = n - e, i = j({
|
|
640
|
+
...t,
|
|
641
|
+
page: r
|
|
642
|
+
}), a = c.get(i);
|
|
643
|
+
(!a?.view.value || this.isExpired(a.view.updatedAt)) && m(r);
|
|
644
|
+
}
|
|
645
|
+
} catch (e) {
|
|
646
|
+
console.debug("Preload process failed:", e);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
removeEmptyPageIfNeeded(e, t, n, r, i) {
|
|
650
|
+
if (t.view.value && t.view.value.length === 0 && n < r) {
|
|
651
|
+
let t = j({
|
|
652
|
+
...i,
|
|
653
|
+
page: n
|
|
654
|
+
});
|
|
655
|
+
e.delete(t);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
updateTotalPagesForAllViews(e, t) {
|
|
659
|
+
for (let [, n] of e) n.view.meta && (n.view.meta.totalPages = t);
|
|
660
|
+
}
|
|
661
|
+
isParamsSame(e, t) {
|
|
662
|
+
let n = Object.keys(e ?? {}).filter((e) => e !== "page").sort(), r = Object.keys(t ?? {}).filter((e) => e !== "page").sort();
|
|
663
|
+
if (n.length !== r.length) return !1;
|
|
664
|
+
for (let i = 0; i < n.length; i++) {
|
|
665
|
+
let a = n[i];
|
|
666
|
+
if (a !== r[i] || e[a] !== t[a]) return !1;
|
|
667
|
+
}
|
|
668
|
+
return !0;
|
|
669
|
+
}
|
|
670
|
+
syncTotalsInSameViews(e, t) {
|
|
671
|
+
let n = t.view.meta;
|
|
672
|
+
if (!n || typeof n.total != "number") return;
|
|
673
|
+
let r = Number(n.total), i = w(t.params?.pageSize), a = Number.isFinite(i) && i > 0 ? Math.max(1, Math.ceil(r / i)) : void 0;
|
|
674
|
+
for (let [, n] of e) this.isParamsSame(n.params ?? {}, t.params ?? {}) && (n.view.meta || (n.view.meta = {}), n.view.meta.total = r, a !== void 0 && (n.view.meta.totalPages = a));
|
|
675
|
+
}
|
|
676
|
+
cascadeShiftPages(e, t, n, r, i, a, o) {
|
|
677
|
+
let s = t, c = n, l = !1, u = 0;
|
|
678
|
+
for (; s.view.value && s.view.value.length < r && c < i && u < 100;) {
|
|
679
|
+
u++;
|
|
680
|
+
let t = j({
|
|
681
|
+
...o,
|
|
682
|
+
page: c + 1
|
|
683
|
+
}), n = e.get(t);
|
|
684
|
+
if (!n?.view.value || this.isExpired(n.view.updatedAt)) {
|
|
685
|
+
s.view.meta = {
|
|
686
|
+
...s.view.meta ?? {},
|
|
687
|
+
stale: !0
|
|
688
|
+
};
|
|
689
|
+
break;
|
|
690
|
+
}
|
|
691
|
+
let i = r - s.view.value.length, d = n.view.value.slice(0, i).filter((e) => a.getEntity(e));
|
|
692
|
+
if (d.length === 0) {
|
|
693
|
+
s.view.meta = {
|
|
694
|
+
...s.view.meta ?? {},
|
|
695
|
+
stale: !0
|
|
696
|
+
};
|
|
697
|
+
break;
|
|
698
|
+
}
|
|
699
|
+
if (s.view.value = [...s.view.value, ...d], s.view.updatedAt = Date.now(), n.view.value = n.view.value.slice(d.length), n.view.updatedAt = Date.now(), n.view.value.length === 0) {
|
|
700
|
+
let t = c + 1, r = n.view.meta;
|
|
701
|
+
if (t < (r && typeof r.totalPages == "number" ? r.totalPages : 1)) {
|
|
702
|
+
let n = j({
|
|
703
|
+
...o,
|
|
704
|
+
page: t
|
|
705
|
+
});
|
|
706
|
+
e.delete(n), l = !0;
|
|
707
|
+
}
|
|
708
|
+
break;
|
|
709
|
+
}
|
|
710
|
+
s = n, c++;
|
|
711
|
+
}
|
|
712
|
+
return (!s.view.value || s.view.value.length < r) && c >= i && (s.view.meta = {
|
|
713
|
+
...s.view.meta ?? {},
|
|
714
|
+
stale: !0
|
|
715
|
+
}), l;
|
|
716
|
+
}
|
|
717
|
+
cascadeShiftToNextPage(e, t, n, r, i, a, o) {
|
|
718
|
+
if (!t.view.value || t.view.value.length <= r) return !1;
|
|
719
|
+
if (n - (o.page || 1) >= 10) return t.view.meta = {
|
|
720
|
+
...t.view.meta ?? {},
|
|
721
|
+
stale: !0
|
|
722
|
+
}, !1;
|
|
723
|
+
let s = {
|
|
724
|
+
...o,
|
|
725
|
+
page: n + 1
|
|
726
|
+
}, c = j(s), l = e.get(c), u = !1;
|
|
727
|
+
if (!l?.view.value || this.isExpired(l.view.updatedAt)) if (n >= i) {
|
|
728
|
+
l = {
|
|
729
|
+
params: s,
|
|
730
|
+
view: {
|
|
731
|
+
promise: null,
|
|
732
|
+
value: void 0,
|
|
733
|
+
meta: void 0,
|
|
734
|
+
updatedAt: 0,
|
|
735
|
+
loadId: null
|
|
736
|
+
}
|
|
737
|
+
}, e.set(c, l), this.cleanupOldViews(e);
|
|
738
|
+
let r = t.view.meta;
|
|
739
|
+
r && (l.view.meta = {
|
|
740
|
+
...r,
|
|
741
|
+
page: n + 1
|
|
742
|
+
}), u = !0;
|
|
743
|
+
} else return t.view.meta = {
|
|
744
|
+
...t.view.meta ?? {},
|
|
745
|
+
stale: !0
|
|
746
|
+
}, !1;
|
|
747
|
+
let d = t.view.value.slice(r).filter((e) => a.getEntity(e));
|
|
748
|
+
if (d.length === 0) return u && e.delete(c), !1;
|
|
749
|
+
t.view.value = t.view.value.slice(0, r), t.view.updatedAt = Date.now(), l.view.value = [...d, ...l.view.value ?? []], l.view.updatedAt = Date.now();
|
|
750
|
+
let f = l.view.meta && typeof l.view.meta.totalPages == "number" ? l.view.meta.totalPages : i;
|
|
751
|
+
if (!u && this.cascadeShiftToNextPage(e, l, n + 1, r, f, a, o)) return !0;
|
|
752
|
+
if (!l.view.value || l.view.value.length === 0) {
|
|
753
|
+
let t = n + 1, r = l.view.meta, i = r && typeof r.totalPages == "number" ? r.totalPages : 1;
|
|
754
|
+
this.removeEmptyPageIfNeeded(e, l, t, i, o);
|
|
755
|
+
}
|
|
756
|
+
return u;
|
|
757
|
+
}
|
|
758
|
+
canCompareInSortedView(e, t) {
|
|
759
|
+
let n = e.params ?? {};
|
|
760
|
+
return !n.sortBy && !n.sortOrder || !this.strategy.hasSortValue || this.strategy.hasSortValue(t, e.params);
|
|
761
|
+
}
|
|
762
|
+
tryInsertSorted(e, t, n) {
|
|
763
|
+
let r = this.strategy.comparator;
|
|
764
|
+
if (!r || !e.view.value) return !1;
|
|
765
|
+
let i = e.params?.itemType || "all";
|
|
766
|
+
if (!this.isEntityTypeCompatible(t, i) || !this.canCompareInSortedView(e, t)) return !1;
|
|
767
|
+
let a = e.view.value.map((e) => n.getEntity(e));
|
|
768
|
+
if (a.some((e) => !e)) return !1;
|
|
769
|
+
if (a.length === 0) {
|
|
770
|
+
let n = e.params ?? {};
|
|
771
|
+
if (n.sortBy || n.sortOrder) {
|
|
772
|
+
let n = r(t, t, e.params);
|
|
773
|
+
if (typeof n != "number" || Number.isNaN(n)) return !1;
|
|
774
|
+
}
|
|
775
|
+
return e.view.value.includes(t.id) ? (e.view.updatedAt = this.now(), !0) : (e.view.value = [t.id], e.view.updatedAt = this.now(), !0);
|
|
776
|
+
}
|
|
777
|
+
let o = 0, s = a.length;
|
|
778
|
+
for (; o < s;) {
|
|
779
|
+
let n = Math.floor((o + s) / 2), i = r(t, a[n], e.params);
|
|
780
|
+
if (typeof i != "number" || Number.isNaN(i)) return !1;
|
|
781
|
+
i >= 0 ? o = n + 1 : s = n;
|
|
782
|
+
}
|
|
783
|
+
return e.view.value.includes(t.id) ? (e.view.updatedAt = this.now(), !0) : (e.view.value = [
|
|
784
|
+
...e.view.value.slice(0, o),
|
|
785
|
+
t.id,
|
|
786
|
+
...e.view.value.slice(o)
|
|
787
|
+
], e.view.updatedAt = this.now(), !0);
|
|
788
|
+
}
|
|
789
|
+
updateChildrenCountForOperation(e, t, n, r) {
|
|
790
|
+
let i = E(t);
|
|
791
|
+
switch (e) {
|
|
792
|
+
case "delete":
|
|
793
|
+
this.adjustChildrenCount(r, i, -1), this.childrenCountInvalidator?.(i);
|
|
794
|
+
break;
|
|
795
|
+
case "insert":
|
|
796
|
+
case "copy":
|
|
797
|
+
this.adjustChildrenCount(r, i, 1), this.childrenCountInvalidator?.(i);
|
|
798
|
+
break;
|
|
799
|
+
case "move":
|
|
800
|
+
this.adjustChildrenCount(r, n ?? null, -1), this.adjustChildrenCount(r, i, 1), this.childrenCountInvalidator?.(n ?? null), this.childrenCountInvalidator?.(i);
|
|
801
|
+
break;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
adjustChildrenCount(e, t, n) {
|
|
805
|
+
if (!t) return;
|
|
806
|
+
let r = e.getFolder(t);
|
|
807
|
+
if (r && typeof r.childrenCount == "number") {
|
|
808
|
+
let i = Math.max(0, r.childrenCount + n);
|
|
809
|
+
e.updateServerChildrenCount(t, i);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
smartInvalidateChildrenViews(e, t, n, r, i, a) {
|
|
813
|
+
if (!t) return;
|
|
814
|
+
this.updateChildrenCountForOperation(n, t, i, r);
|
|
815
|
+
let o = this.parentKey(e), s = this.views.get(o);
|
|
816
|
+
if (s) for (let [, e] of s) {
|
|
817
|
+
let a = e.params ?? {}, o = a?.page ?? 1, c = w(a?.pageSize), l = Number.isFinite(c), u = !!(a?.sortBy || a?.sortOrder), d = !!a?.search, f = a?.itemType || "all";
|
|
818
|
+
if (this.isEntityTypeCompatible(t, f)) {
|
|
819
|
+
if (d && this.strategy.filterMatch && !this.strategy.filterMatch(t, e.params)) {
|
|
820
|
+
e.view.value?.includes(t.id) && (e.view.value = e.view.value.filter((e) => e !== t.id), e.view.meta && typeof e.view.meta.total == "number" && (e.view.meta.total = Math.max(0, e.view.meta.total - 1)), this.markViewStaleForReload(e));
|
|
821
|
+
continue;
|
|
822
|
+
}
|
|
823
|
+
if (!e.view.value) {
|
|
824
|
+
e.view.meta && (e.view.meta.stale = !0), e.view.loadId = O(), e.view.abortController && (e.view.abortController.abort(), e.view.abortController = void 0);
|
|
825
|
+
continue;
|
|
826
|
+
}
|
|
827
|
+
if (e.view.value.includes(t.id), this.shouldInvalidateCompletely(e, n, t, u, l, o)) {
|
|
828
|
+
this.markViewStaleForReload(e);
|
|
829
|
+
continue;
|
|
830
|
+
}
|
|
831
|
+
switch (n) {
|
|
832
|
+
case "delete":
|
|
833
|
+
this.handleDelete(s, e, o, c, l, t, r);
|
|
834
|
+
break;
|
|
835
|
+
case "insert":
|
|
836
|
+
case "copy":
|
|
837
|
+
this.handleInsert(s, e, o, c, l, u, t, r);
|
|
838
|
+
break;
|
|
839
|
+
case "update":
|
|
840
|
+
this.handleUpdate(s, e, o, c, l, u, d, t, r);
|
|
841
|
+
break;
|
|
842
|
+
case "move":
|
|
843
|
+
this.handleMove(s, e, o, c, l, u, t, i, r);
|
|
844
|
+
break;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
shouldInvalidateCompletely(e, t, n, r, i, a) {
|
|
850
|
+
return !!(i && a > 1 && (t === "insert" || t === "delete" || t === "move") || this.isExpired(e.view.updatedAt));
|
|
851
|
+
}
|
|
852
|
+
tryReinsertEntity(e, t, n, r, i) {
|
|
853
|
+
let a = e.params?.itemType || "all";
|
|
854
|
+
if (!this.isEntityTypeCompatible(t, a)) return !1;
|
|
855
|
+
let o = e.params ?? {};
|
|
856
|
+
return this.strategy.filterMatch(t, o) ? this.tryInsertSorted(e, t, n) ? !0 : o.sortBy || o.sortOrder ? !1 : !r || e.view.value.length < i ? (e.view.value.push(t.id), !0) : !1 : !1;
|
|
857
|
+
}
|
|
858
|
+
handleDelete(e, t, n, r, i, a, o) {
|
|
859
|
+
let s = t.view.value.includes(a.id);
|
|
860
|
+
if (s && (t.view.value = t.view.value.filter((e) => e !== a.id)), t.view.meta && typeof t.view.meta.total == "number") {
|
|
861
|
+
if (t.view.meta.total = Math.max(0, t.view.meta.total - 1), i && Number.isFinite(r) && typeof t.view.meta.total == "number") {
|
|
862
|
+
let e = r;
|
|
863
|
+
e > 0 && (t.view.meta.totalPages = Math.max(1, Math.ceil(t.view.meta.total / e)));
|
|
864
|
+
}
|
|
865
|
+
this.syncTotalsInSameViews(e, t);
|
|
866
|
+
}
|
|
867
|
+
if (t.view.updatedAt = Date.now(), s && i && t.view.value.length < r && o) {
|
|
868
|
+
let i = t.view.meta, a = i && typeof i.totalPages == "number" ? i.totalPages : 1;
|
|
869
|
+
if (this.cascadeShiftPages(e, t, n, r, a, o, t.params ?? {}) && t.view.meta && typeof t.view.meta.totalPages == "number") {
|
|
870
|
+
let n = Math.max(1, t.view.meta.totalPages - 1);
|
|
871
|
+
t.view.meta.totalPages = n, this.updateTotalPagesForAllViews(e, n);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
t.view.loadId = O(), t.view.abortController && (t.view.abortController.abort(), t.view.abortController = void 0);
|
|
875
|
+
}
|
|
876
|
+
handleInsert(e, t, n, r, i, a, o, s) {
|
|
877
|
+
if (!t.view.value.includes(o.id)) {
|
|
878
|
+
if (a && this.strategy.allowSortedInsert && this.strategy.comparator && s) if (this.tryInsertSorted(t, o, s)) {
|
|
879
|
+
if (t.view.meta && typeof t.view.meta.total == "number") {
|
|
880
|
+
if (t.view.meta.total += 1, i && Number.isFinite(r)) {
|
|
881
|
+
let e = r;
|
|
882
|
+
e > 0 && (t.view.meta.totalPages = Math.max(1, Math.ceil(t.view.meta.total / e)));
|
|
883
|
+
}
|
|
884
|
+
this.syncTotalsInSameViews(e, t);
|
|
885
|
+
}
|
|
886
|
+
if (t.view.updatedAt = Date.now(), i && (t.view.value?.length ?? 0) > r && s) {
|
|
887
|
+
let i = t.view.meta, a = i && typeof i.totalPages == "number" ? i.totalPages : 1;
|
|
888
|
+
if (this.cascadeShiftToNextPage(e, t, n, r, a, s, t.params ?? {}) && t.view.meta && typeof t.view.meta.totalPages == "number") {
|
|
889
|
+
let n = t.view.meta.totalPages + 1;
|
|
890
|
+
t.view.meta.totalPages = n, this.updateTotalPagesForAllViews(e, n);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
} else this.markViewStaleForReload(t);
|
|
894
|
+
else if (!i || t.view.value.length < r) {
|
|
895
|
+
if (t.view.value.push(o.id), t.view.meta && typeof t.view.meta.total == "number") {
|
|
896
|
+
if (t.view.meta.total += 1, i && Number.isFinite(r)) {
|
|
897
|
+
let e = r;
|
|
898
|
+
e > 0 && (t.view.meta.totalPages = Math.max(1, Math.ceil(t.view.meta.total / e)));
|
|
899
|
+
}
|
|
900
|
+
this.syncTotalsInSameViews(e, t);
|
|
901
|
+
}
|
|
902
|
+
t.view.updatedAt = Date.now();
|
|
903
|
+
} else this.markViewStaleForReload(t);
|
|
904
|
+
t.view.loadId = O(), t.view.abortController && (t.view.abortController.abort(), t.view.abortController = void 0);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
handleUpdate(e, t, n, r, i, a, o, s, c) {
|
|
908
|
+
let l = t.view.value.includes(s.id), u = this.isEntityTypeCompatible(s, t.params?.itemType || "all");
|
|
909
|
+
if (l && !u) {
|
|
910
|
+
if (t.view.value = t.view.value.filter((e) => e !== s.id), t.view.meta && typeof t.view.meta.total == "number" && (t.view.meta.total = Math.max(0, t.view.meta.total - 1), i && Number.isFinite(r) && typeof t.view.meta.total == "number")) {
|
|
911
|
+
let e = r;
|
|
912
|
+
e > 0 && (t.view.meta.totalPages = Math.max(1, Math.ceil(t.view.meta.total / e)));
|
|
913
|
+
}
|
|
914
|
+
if (t.view.updatedAt = Date.now(), i && t.view.value.length < r && c) {
|
|
915
|
+
let i = t.view.meta, a = i && typeof i.totalPages == "number" ? i.totalPages : 1;
|
|
916
|
+
if (this.cascadeShiftPages(e, t, n, r, a, c, t.params ?? {}) && t.view.meta && typeof t.view.meta.totalPages == "number") {
|
|
917
|
+
let n = Math.max(1, t.view.meta.totalPages - 1);
|
|
918
|
+
t.view.meta.totalPages = n, this.updateTotalPagesForAllViews(e, n);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
t.view.loadId = O(), t.view.abortController && (t.view.abortController.abort(), t.view.abortController = void 0);
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
if (l && (a || o)) {
|
|
925
|
+
t.view.value = t.view.value.filter((e) => e !== s.id), this.tryReinsertEntity(t, s, c, i, r) ? (t.view.updatedAt = Date.now(), t.view.loadId = O(), t.view.abortController && (t.view.abortController.abort(), t.view.abortController = void 0)) : this.markViewStaleForReload(t);
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
if (l) {
|
|
929
|
+
t.view.updatedAt = Date.now(), t.view.loadId = O(), t.view.abortController && (t.view.abortController.abort(), t.view.abortController = void 0);
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
if (u && !o) {
|
|
933
|
+
if (a && this.strategy.allowSortedInsert && this.strategy.comparator && c) if (this.tryInsertSorted(t, s, c)) {
|
|
934
|
+
if (t.view.meta && typeof t.view.meta.total == "number") {
|
|
935
|
+
if (t.view.meta.total += 1, i && Number.isFinite(r)) {
|
|
936
|
+
let e = r;
|
|
937
|
+
e > 0 && (t.view.meta.totalPages = Math.max(1, Math.ceil(t.view.meta.total / e)));
|
|
938
|
+
}
|
|
939
|
+
this.syncTotalsInSameViews(e, t);
|
|
940
|
+
}
|
|
941
|
+
t.view.updatedAt = Date.now();
|
|
942
|
+
} else this.markViewStaleForReload(t);
|
|
943
|
+
else if (!i || t.view.value.length < r) {
|
|
944
|
+
if (t.view.value.push(s.id), t.view.meta && typeof t.view.meta.total == "number") {
|
|
945
|
+
if (t.view.meta.total += 1, i && Number.isFinite(r)) {
|
|
946
|
+
let e = r;
|
|
947
|
+
e > 0 && (t.view.meta.totalPages = Math.max(1, Math.ceil(t.view.meta.total / e)));
|
|
948
|
+
}
|
|
949
|
+
this.syncTotalsInSameViews(e, t);
|
|
950
|
+
}
|
|
951
|
+
t.view.updatedAt = Date.now();
|
|
952
|
+
} else this.markViewStaleForReload(t);
|
|
953
|
+
t.view.loadId = O(), t.view.abortController && (t.view.abortController.abort(), t.view.abortController = void 0);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
handleMove(e, t, n, r, i, a, o, s, c) {
|
|
957
|
+
if (t.view.value.includes(o.id)) {
|
|
958
|
+
if (t.view.value = t.view.value.filter((e) => e !== o.id), t.view.meta && typeof t.view.meta.total == "number" && (t.view.meta.total = Math.max(0, t.view.meta.total - 1), i && Number.isFinite(r) && typeof t.view.meta.total == "number")) {
|
|
959
|
+
let e = r;
|
|
960
|
+
e > 0 && (t.view.meta.totalPages = Math.max(1, Math.ceil(t.view.meta.total / e)));
|
|
961
|
+
}
|
|
962
|
+
if (t.view.updatedAt = Date.now(), i && t.view.value.length < r && c) {
|
|
963
|
+
let i = t.view.meta, a = i && typeof i.totalPages == "number" ? i.totalPages : 1;
|
|
964
|
+
if (this.cascadeShiftPages(e, t, n, r, a, c, t.params ?? {}) && t.view.meta && typeof t.view.meta.totalPages == "number") {
|
|
965
|
+
let n = Math.max(1, t.view.meta.totalPages - 1);
|
|
966
|
+
t.view.meta.totalPages = n, this.updateTotalPagesForAllViews(e, n);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
this.syncTotalsInSameViews(e, t);
|
|
970
|
+
}
|
|
971
|
+
t.view.loadId = O(), t.view.abortController && (t.view.abortController.abort(), t.view.abortController = void 0);
|
|
972
|
+
}
|
|
973
|
+
forceInvalidateChildrenViews(e) {
|
|
974
|
+
let t = this.parentKey(e ?? null);
|
|
975
|
+
this.failedRequests.clearChildrenViewErrorsForParent(t);
|
|
976
|
+
let n = this.views.get(t);
|
|
977
|
+
if (n) for (let [, e] of n) e.view.value = void 0, e.view.meta = void 0, e.view.promise = null, e.view.updatedAt = 0, e.view.loadId = O(), e.view.abortController && (e.view.abortController.abort(), e.view.abortController = void 0);
|
|
978
|
+
}
|
|
979
|
+
getKnownTotal(e) {
|
|
980
|
+
let t = this.parentKey(e ?? null), n = this.views.get(t);
|
|
981
|
+
if (!n) return;
|
|
982
|
+
let r = null;
|
|
983
|
+
for (let [, e] of n) {
|
|
984
|
+
let t = e.view.meta;
|
|
985
|
+
t && typeof t.total == "number" && (!r || (e.view.updatedAt ?? 0) > r.updatedAt) && (r = {
|
|
986
|
+
total: Number(t.total),
|
|
987
|
+
updatedAt: e.view.updatedAt ?? 0
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
return r ? r.total : void 0;
|
|
991
|
+
}
|
|
992
|
+
toJSON() {
|
|
993
|
+
return {
|
|
994
|
+
views: Array.from(this.views.entries()).map(([e, t]) => [e, Array.from(t.entries())]),
|
|
995
|
+
ttl: this.ttl,
|
|
996
|
+
errorTtl: this.errorTtl,
|
|
997
|
+
entityTtl: this.entityTtl,
|
|
998
|
+
strategy: {
|
|
999
|
+
allowSortedInsert: this.strategy.allowSortedInsert,
|
|
1000
|
+
allowSearchInsert: this.strategy.allowSearchInsert,
|
|
1001
|
+
invalidateOnPaginationFull: this.strategy.invalidateOnPaginationFull,
|
|
1002
|
+
preloadPagesBefore: this.strategy.preloadPagesBefore,
|
|
1003
|
+
preloadPagesAfter: this.strategy.preloadPagesAfter
|
|
1004
|
+
}
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
static fromJSON(t, n) {
|
|
1008
|
+
let r = n?.ttl ?? t?.ttl ?? 18e5, i = n?.errorTtl ?? t?.errorTtl ?? r, a = n?.failedRequests ?? new o(), s = new e({}, r, i, void 0, a, n?.isFolderNotFoundError);
|
|
1009
|
+
for (let [e, n] of t.views ?? []) {
|
|
1010
|
+
let t = /* @__PURE__ */ new Map();
|
|
1011
|
+
for (let [e, r] of n) {
|
|
1012
|
+
let n = r;
|
|
1013
|
+
n?.view && "error" in n.view && delete n.view.error, t.set(e, n);
|
|
1014
|
+
}
|
|
1015
|
+
s.views.set(e, t);
|
|
1016
|
+
}
|
|
1017
|
+
return s;
|
|
1018
|
+
}
|
|
1019
|
+
}, P = class e {
|
|
1020
|
+
invalidateChildrenCountCache(e) {
|
|
1021
|
+
let t = C(e ?? "");
|
|
1022
|
+
this.childrenCountPromises.delete(t), this.failedRequests.delete(o.childrenCountKey(t));
|
|
1023
|
+
}
|
|
1024
|
+
constructor(e = {}, t = S, n, r) {
|
|
1025
|
+
this.childrenCountPromises = /* @__PURE__ */ new Map(), this.isFolderNotFoundError = r?.isFolderNotFoundError ?? k, this.failedRequests = new o(), this.ttl = r?.ttl ?? t, this.errorTtl = r?.errorTtl ?? n ?? this.ttl, this.entities = new M(), this.views = new N(e, this.ttl, this.errorTtl, void 0, this.failedRequests, this.isFolderNotFoundError), this.views.setServerChildrenCountHandler((e, t, n) => {
|
|
1026
|
+
this.handleServerReportedChildrenCount(e, t, n ?? this.entities);
|
|
1027
|
+
}), this.views.setChildrenCountInvalidator((e) => {
|
|
1028
|
+
this.invalidateChildrenCountCache(e);
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
getEntity(e) {
|
|
1032
|
+
return this.entities.getEntity(e) ?? null;
|
|
1033
|
+
}
|
|
1034
|
+
getFileSystemItem(e) {
|
|
1035
|
+
return this.entities.getFileSystemItem(e) ?? null;
|
|
1036
|
+
}
|
|
1037
|
+
getFolder(e) {
|
|
1038
|
+
return this.entities.getFolder(e) ?? null;
|
|
1039
|
+
}
|
|
1040
|
+
async getOrCreateChildren(e, t, n) {
|
|
1041
|
+
return this.views.getOrCreateChildren(e, t, n, this.entities);
|
|
1042
|
+
}
|
|
1043
|
+
upsertEntity(e) {
|
|
1044
|
+
let t = this.entities.getEntity(e.id), n = t ? E(t) : null, r = E(e), i = t ? D(t) : !1, a = D(e);
|
|
1045
|
+
if (this.entities.upsertEntity(e), t) {
|
|
1046
|
+
if (n !== r || i !== a) {
|
|
1047
|
+
this.views.smartInvalidateChildrenViews(n, t, "delete", this.entities), this.views.smartInvalidateChildrenViews(r, e, "insert", this.entities);
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1050
|
+
this.views.smartInvalidateChildrenViews(r, e, "update", this.entities, void 0, t);
|
|
1051
|
+
} else this.views.smartInvalidateChildrenViews(r, e, "insert", this.entities);
|
|
1052
|
+
}
|
|
1053
|
+
isAncestor(e, t) {
|
|
1054
|
+
let n = t, r = /* @__PURE__ */ new Set();
|
|
1055
|
+
for (; n && !r.has(n);) {
|
|
1056
|
+
if (r.add(n), C(n) === C(e)) return !0;
|
|
1057
|
+
let t = this.entities.getEntity(n);
|
|
1058
|
+
if (!t) break;
|
|
1059
|
+
n = E(t), n === null && (n = x);
|
|
1060
|
+
}
|
|
1061
|
+
return !1;
|
|
1062
|
+
}
|
|
1063
|
+
moveEntity(e, t) {
|
|
1064
|
+
let n = this.entities.getEntity(e);
|
|
1065
|
+
if (!n || D(n) && t !== null && this.isAncestor(e, t)) return null;
|
|
1066
|
+
let r = E(n), i = this.entities.moveEntityById(e, t);
|
|
1067
|
+
return i ? (this.views.smartInvalidateChildrenViews(r, n, "delete", this.entities), this.views.smartInvalidateChildrenViews(t, i, "insert", this.entities), i) : null;
|
|
1068
|
+
}
|
|
1069
|
+
copyEntity(e, t, n, r) {
|
|
1070
|
+
let i = this.entities.getEntity(e);
|
|
1071
|
+
if (!i) return null;
|
|
1072
|
+
let a = null;
|
|
1073
|
+
if (D(i)) {
|
|
1074
|
+
let n = [e], i = [];
|
|
1075
|
+
for (; n.length;) {
|
|
1076
|
+
let e = n.shift();
|
|
1077
|
+
i.push(e);
|
|
1078
|
+
let t = this.entities.getChildrenIds(e, { onlyFolders: !0 });
|
|
1079
|
+
for (let e of t) n.push(e);
|
|
1080
|
+
}
|
|
1081
|
+
let o = /* @__PURE__ */ new Map();
|
|
1082
|
+
for (let e of i) o.set(e, O());
|
|
1083
|
+
for (let n of i) {
|
|
1084
|
+
let i = this.entities.getFolder(n), a = o.get(n), s = E(i), c = s === null ? t : o.get(s) ?? null, l = {
|
|
1085
|
+
...i,
|
|
1086
|
+
...n === e ? r : void 0,
|
|
1087
|
+
id: a,
|
|
1088
|
+
folderId: (n === e ? r?.folderId : void 0) ?? c
|
|
1089
|
+
};
|
|
1090
|
+
this.entities.upsertEntity(l);
|
|
1091
|
+
}
|
|
1092
|
+
for (let e of i) {
|
|
1093
|
+
let t = o.get(e), n = this.entities.getChildrenIds(e, { onlyFileSystemItems: !0 });
|
|
1094
|
+
for (let e of n) {
|
|
1095
|
+
let n = this.entities.getFileSystemItem(e);
|
|
1096
|
+
if (!n) continue;
|
|
1097
|
+
let r = O(), i = {
|
|
1098
|
+
...n,
|
|
1099
|
+
id: r,
|
|
1100
|
+
folderId: t
|
|
1101
|
+
};
|
|
1102
|
+
this.entities.upsertEntity(i);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
a = this.entities.getEntity(o.get(e)) ?? null;
|
|
1106
|
+
} else {
|
|
1107
|
+
let i = n ?? O();
|
|
1108
|
+
if (a = this.entities.copyFileSystemItem(e, i, t ?? null), a && r) {
|
|
1109
|
+
let e = {
|
|
1110
|
+
...a,
|
|
1111
|
+
...r,
|
|
1112
|
+
id: i,
|
|
1113
|
+
folderId: r.folderId ?? t ?? null
|
|
1114
|
+
};
|
|
1115
|
+
this.entities.upsertEntity(e), a = e;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
return a && this.views.smartInvalidateChildrenViews(t, a, "copy", this.entities), a;
|
|
1119
|
+
}
|
|
1120
|
+
searchByUrl(e) {
|
|
1121
|
+
return this.entities.searchByUrl(e) ?? null;
|
|
1122
|
+
}
|
|
1123
|
+
deleteEntity(e) {
|
|
1124
|
+
let t = this.entities.getEntity(e);
|
|
1125
|
+
if (!t) return null;
|
|
1126
|
+
if (D(t)) {
|
|
1127
|
+
let { deletedFolderRecords: n, deletedFileSystemItemRecords: r } = this.entities.deleteFolderRecursive(e);
|
|
1128
|
+
for (let e of r) this.views.smartInvalidateChildrenViews(e.folderId, e, "delete", this.entities);
|
|
1129
|
+
for (let e of n) this.views.smartInvalidateChildrenViews(e.folderId, e, "delete", this.entities);
|
|
1130
|
+
for (let e of n) this.views.forceInvalidateChildrenViews(e.id);
|
|
1131
|
+
return t;
|
|
1132
|
+
} else {
|
|
1133
|
+
let { entity: t, parentId: n } = this.entities.deleteEntityById(e);
|
|
1134
|
+
return t && this.views.smartInvalidateChildrenViews(n, t, "delete", this.entities), t;
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
deleteFolderRecursive(e) {
|
|
1138
|
+
let { deletedFolderRecords: t, deletedFileSystemItemRecords: n } = this.entities.deleteFolderRecursive(e);
|
|
1139
|
+
for (let e of n) this.views.smartInvalidateChildrenViews(e.folderId, e, "delete", this.entities);
|
|
1140
|
+
for (let e of t) this.views.smartInvalidateChildrenViews(e.folderId, e, "delete", this.entities);
|
|
1141
|
+
for (let e of t) this.views.forceInvalidateChildrenViews(e.id);
|
|
1142
|
+
return {
|
|
1143
|
+
deletedFileSystemItemIds: n.map((e) => e.id),
|
|
1144
|
+
deletedFolderIds: t.map((e) => e.id)
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
forceInvalidate(e) {
|
|
1148
|
+
let t = this.entities.getEntity(e);
|
|
1149
|
+
if (!t) {
|
|
1150
|
+
this.views.forceInvalidateChildrenViews(e ?? null), this.invalidateChildrenCountCache(e);
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
let n = /* @__PURE__ */ new Set();
|
|
1154
|
+
if (D(t)) {
|
|
1155
|
+
let t = [e];
|
|
1156
|
+
for (; t.length;) {
|
|
1157
|
+
let e = t.pop();
|
|
1158
|
+
if (n.has(e)) continue;
|
|
1159
|
+
n.add(e), this.views.forceInvalidateChildrenViews(e), this.invalidateChildrenCountCache(e);
|
|
1160
|
+
let r = this.entities.getChildrenIds(e, { onlyFolders: !0 });
|
|
1161
|
+
for (let e of r) t.push(e);
|
|
1162
|
+
}
|
|
1163
|
+
} else {
|
|
1164
|
+
let e = t.folderId ?? null;
|
|
1165
|
+
this.views.forceInvalidateChildrenViews(e), this.invalidateChildrenCountCache(e);
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
invalidateListingViews(e) {
|
|
1169
|
+
this.views.forceInvalidateChildrenViews(e ?? null);
|
|
1170
|
+
}
|
|
1171
|
+
getChildrenIds(e) {
|
|
1172
|
+
return this.entities.getChildrenIds(e);
|
|
1173
|
+
}
|
|
1174
|
+
searchByName(e, t) {
|
|
1175
|
+
return this.entities.searchByName(e, t);
|
|
1176
|
+
}
|
|
1177
|
+
async getChildrenCount(e = "", t) {
|
|
1178
|
+
let n = C(e), r = o.childrenCountKey(n), i = this.failedRequests.getFreshError(r, this.errorTtl);
|
|
1179
|
+
if (i != null) return Promise.reject(i);
|
|
1180
|
+
let a = this.childrenCountPromises.get(n);
|
|
1181
|
+
if (a) return a;
|
|
1182
|
+
let s = (async () => {
|
|
1183
|
+
try {
|
|
1184
|
+
let n = this.entities.getFolder(e);
|
|
1185
|
+
if (n && typeof n.childrenCount == "number") return this.failedRequests.delete(r), n.childrenCount;
|
|
1186
|
+
let i = this.views.getKnownTotal(e);
|
|
1187
|
+
if (typeof i == "number") return n && this.handleServerReportedChildrenCount(e, i, this.entities), this.failedRequests.delete(r), i;
|
|
1188
|
+
if (t) {
|
|
1189
|
+
let n = await t(e);
|
|
1190
|
+
return this.entities.getFolder(e) && this.handleServerReportedChildrenCount(e, n, this.entities), this.failedRequests.delete(r), n;
|
|
1191
|
+
}
|
|
1192
|
+
return this.failedRequests.delete(r), this.entities.getChildrenIds(e).length;
|
|
1193
|
+
} catch (e) {
|
|
1194
|
+
if (this.childrenCountPromises.delete(n), this.isFolderNotFoundError(e)) return this.failedRequests.delete(r), 0;
|
|
1195
|
+
throw this.failedRequests.setError(r, e), e;
|
|
1196
|
+
} finally {
|
|
1197
|
+
this.childrenCountPromises.delete(n);
|
|
1198
|
+
}
|
|
1199
|
+
})();
|
|
1200
|
+
return this.childrenCountPromises.set(n, s), s;
|
|
1201
|
+
}
|
|
1202
|
+
toJSON() {
|
|
1203
|
+
return {
|
|
1204
|
+
entities: this.entities.toJSON(),
|
|
1205
|
+
views: this.views.toJSON(),
|
|
1206
|
+
ttl: this.ttl,
|
|
1207
|
+
errorTtl: this.errorTtl
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
static fromJSON(t, n, r) {
|
|
1211
|
+
let i = r?.ttl ?? t?.ttl ?? 18e5, a = r?.errorTtl ?? t?.errorTtl ?? i, o = new e(n ?? {}, i, a, r), s = M.fromJSON(t?.entities ?? {}), c = N.fromJSON(t?.views ?? {}, {
|
|
1212
|
+
failedRequests: o.failedRequests,
|
|
1213
|
+
ttl: i,
|
|
1214
|
+
errorTtl: a,
|
|
1215
|
+
isFolderNotFoundError: r?.isFolderNotFoundError
|
|
1216
|
+
});
|
|
1217
|
+
if (n) {
|
|
1218
|
+
let e = g(n);
|
|
1219
|
+
c.strategy = {
|
|
1220
|
+
allowSortedInsert: e.allowSortedInsert ?? !0,
|
|
1221
|
+
allowSearchInsert: e.allowSearchInsert ?? !0,
|
|
1222
|
+
invalidateOnPaginationFull: e.invalidateOnPaginationFull ?? !0,
|
|
1223
|
+
preloadPagesBefore: e.preloadPagesBefore ?? 0,
|
|
1224
|
+
preloadPagesAfter: e.preloadPagesAfter ?? 1,
|
|
1225
|
+
comparator: e.comparator,
|
|
1226
|
+
filterMatch: e.filterMatch
|
|
1227
|
+
};
|
|
1228
|
+
}
|
|
1229
|
+
return o.entities = s, o.views = c, c.setServerChildrenCountHandler((e, t, n) => {
|
|
1230
|
+
o.handleServerReportedChildrenCount(e, t, n ?? s);
|
|
1231
|
+
}), c.setChildrenCountInvalidator((e) => {
|
|
1232
|
+
o.invalidateChildrenCountCache(e);
|
|
1233
|
+
}), o;
|
|
1234
|
+
}
|
|
1235
|
+
handleServerReportedChildrenCount(e, t, n) {
|
|
1236
|
+
this.checkAndResolveChildrenCountConflict(e, t, n), this.invalidateChildrenCountCache(e);
|
|
1237
|
+
}
|
|
1238
|
+
checkAndResolveChildrenCountConflict(e, t, n) {
|
|
1239
|
+
if (!n || t === void 0) return;
|
|
1240
|
+
let r = e ?? null;
|
|
1241
|
+
if (!r) {
|
|
1242
|
+
n.updateServerChildrenCount(r, t);
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1245
|
+
let i = n.getFolder(r)?.childrenCount;
|
|
1246
|
+
i !== void 0 && i !== t && (console.warn(`Conflict: folder "${r}" has childrenCount=${i} but server says total=${t}`), this.views.forceInvalidateChildrenViews(r)), n.updateServerChildrenCount(r, t);
|
|
1247
|
+
}
|
|
1248
|
+
}, F = "", I = "Trash", L = "Edited", R = 1e4, z = 1e4, B = 25, V = 10;
|
|
1249
|
+
function H(e, t) {
|
|
1250
|
+
let n = e ?? {}, r = Array.isArray(n.detailed) ? n.detailed.map((e) => ({
|
|
1251
|
+
requestId: e.requestId ?? e.id,
|
|
1252
|
+
success: !!e.success,
|
|
1253
|
+
data: t(e.data),
|
|
1254
|
+
error: e.error
|
|
1255
|
+
})) : void 0;
|
|
1256
|
+
return {
|
|
1257
|
+
success: !!n.success,
|
|
1258
|
+
error: n.error,
|
|
1259
|
+
detailed: r
|
|
1260
|
+
};
|
|
1261
|
+
}
|
|
1262
|
+
function U(e) {
|
|
1263
|
+
return e == null ? "" : String(e);
|
|
1264
|
+
}
|
|
1265
|
+
function W(e) {
|
|
1266
|
+
return {
|
|
1267
|
+
...e,
|
|
1268
|
+
name: U(e.name)
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
function G(e) {
|
|
1272
|
+
return (e ?? []).map(W);
|
|
1273
|
+
}
|
|
1274
|
+
function K(e) {
|
|
1275
|
+
return !e || typeof e != "object" || !("name" in e) ? e : {
|
|
1276
|
+
...e,
|
|
1277
|
+
name: U(e.name)
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
function q(e) {
|
|
1281
|
+
return e ? e.replaceAll("\\", "/").split("/").filter(Boolean) : [];
|
|
1282
|
+
}
|
|
1283
|
+
for (var J = class {
|
|
1284
|
+
_getTrashPath() {
|
|
1285
|
+
return this._pathOptions.trashPath || I;
|
|
1286
|
+
}
|
|
1287
|
+
_getPathLookupCandidates(e) {
|
|
1288
|
+
return y(e, this._getTrashPath(), _);
|
|
1289
|
+
}
|
|
1290
|
+
_folderFromResolvedPath(t, n) {
|
|
1291
|
+
if (t.isFolder !== !0) throw new e(t.isFolder === !1 ? "Path '%s' resolves to a file, not a folder".replace("%s", n) : "Path '%s' resolved to an item that is not marked as a folder".replace("%s", n), "ValidationError");
|
|
1292
|
+
if (!t.id) throw new e("Path '%s' resolved to a folder without id".replace("%s", n), "ValidationError");
|
|
1293
|
+
let r = {
|
|
1294
|
+
id: t.id,
|
|
1295
|
+
name: t.name || t.id,
|
|
1296
|
+
parentId: t.folderId
|
|
1297
|
+
};
|
|
1298
|
+
return this._cache.upsertEntity(W({
|
|
1299
|
+
id: r.id,
|
|
1300
|
+
name: r.name,
|
|
1301
|
+
folderId: r.parentId ?? null,
|
|
1302
|
+
isFolder: !0
|
|
1303
|
+
})), r;
|
|
1304
|
+
}
|
|
1305
|
+
async _resolveFolderByPath(e) {
|
|
1306
|
+
if (typeof this._dataProvider.findItemByPath == "function") for (let t of this._getPathLookupCandidates(e)) {
|
|
1307
|
+
let e = await this._dataProvider.findItemByPath(t);
|
|
1308
|
+
if (e) return this._folderFromResolvedPath(e, t);
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
async _findOrCreateFolderByPath(t) {
|
|
1312
|
+
let n = q(t);
|
|
1313
|
+
if (n.length > V) throw new e("Path depth exceeds maximum limit of %s".replace("%s", String(V)), "ValidationError");
|
|
1314
|
+
let r = await this._resolveFolderByPath(t);
|
|
1315
|
+
if (r) return r;
|
|
1316
|
+
let i;
|
|
1317
|
+
for (let r of n) {
|
|
1318
|
+
let { files: n } = await this.getFiles({
|
|
1319
|
+
folderId: i?.id || "",
|
|
1320
|
+
itemType: "folder"
|
|
1321
|
+
}), a = n.find((e) => e.name === r);
|
|
1322
|
+
if (a) {
|
|
1323
|
+
if (!a.isFolder) throw new e("Path component '%s' in '%s' is not a folder".replace("%s", r).replace("%s", t), "ValidationError");
|
|
1324
|
+
i = {
|
|
1325
|
+
id: a.id,
|
|
1326
|
+
name: a.name,
|
|
1327
|
+
parentId: a.folderId
|
|
1328
|
+
};
|
|
1329
|
+
} else {
|
|
1330
|
+
if (typeof this._dataProvider.createFolder != "function") throw new e("Create folder operation is not supported by data provider", "UnsupportedOperation");
|
|
1331
|
+
i = await this.createFolder({
|
|
1332
|
+
name: r,
|
|
1333
|
+
parentId: i?.id
|
|
1334
|
+
});
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
return i;
|
|
1338
|
+
}
|
|
1339
|
+
async getTrashFolder() {
|
|
1340
|
+
let t = await this._findOrCreateFolderByPath(this._getTrashPath());
|
|
1341
|
+
if (!t) throw new e("Trash folder path '%s' could not be resolved".replace("%s", this._getTrashPath()), "FolderNotFound");
|
|
1342
|
+
return t;
|
|
1343
|
+
}
|
|
1344
|
+
async getTempFolder() {
|
|
1345
|
+
let t = this._pathOptions.tempPath ?? L;
|
|
1346
|
+
if (t) try {
|
|
1347
|
+
return await this._findOrCreateFolderByPath(t);
|
|
1348
|
+
} catch (t) {
|
|
1349
|
+
if (t instanceof e && t.code === "ValidationError") throw t;
|
|
1350
|
+
console.warn("getTempFolder: temp folder unavailable, falling back to root", t);
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
constructor(e, t = {}, n, r = {}) {
|
|
1355
|
+
this._dataProvider = e, this._options = t, this._pathOptions = n, this._blobFetchForceReloadOnceIds = /* @__PURE__ */ new Set(), this._mutationRegistry = new s(), this._mapItem = async ({ childrenCount: e, ...t }) => {
|
|
1356
|
+
let n = W(t);
|
|
1357
|
+
if (n.isFolder) return {
|
|
1358
|
+
...n,
|
|
1359
|
+
childCount: e,
|
|
1360
|
+
url: "",
|
|
1361
|
+
thumbnailUrl: ""
|
|
1362
|
+
};
|
|
1363
|
+
let [r, i] = await Promise.all([this._getUrl(n), this._getThumbnailUrl(n)]);
|
|
1364
|
+
return {
|
|
1365
|
+
...n,
|
|
1366
|
+
childCount: 0,
|
|
1367
|
+
url: r,
|
|
1368
|
+
thumbnailUrl: i
|
|
1369
|
+
};
|
|
1370
|
+
}, this._config = r, this._useSoftDelete = this._pathOptions.useSoftDelete, this._rootId = this._pathOptions.rootId || F, this._enableTrash = this._options.enableTrash === void 0 || this._options.enableTrash, this._validateDuplicates = this._dataProvider.validateDuplicates, this._cache = new P(t.cacheStrategy || {}, t.cacheStrategy?.ttl, t.cacheStrategy?.errorTtl), this.setController({
|
|
1371
|
+
invalidateItemCache: (e) => {
|
|
1372
|
+
this._cache.forceInvalidate(e);
|
|
1373
|
+
},
|
|
1374
|
+
getCachedItem: (e) => this._cache.getEntity(e)
|
|
1375
|
+
});
|
|
1376
|
+
let i = Object.getPrototypeOf(this);
|
|
1377
|
+
for (let e of Object.getOwnPropertyNames(i)) {
|
|
1378
|
+
let t = Object.getOwnPropertyDescriptor(i, e);
|
|
1379
|
+
e !== "constructor" && typeof t?.value == "function" && (this[e] = t.value.bind(this));
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
setController(e) {
|
|
1383
|
+
typeof this._dataProvider.setController == "function" && this._dataProvider.setController(e);
|
|
1384
|
+
}
|
|
1385
|
+
async clearCache(e) {
|
|
1386
|
+
let t = e ?? this._rootId;
|
|
1387
|
+
this._cache.forceInvalidate(t), this._cache.invalidateListingViews(t), typeof this._dataProvider.clearCache == "function" && await this._dataProvider.clearCache(e);
|
|
1388
|
+
}
|
|
1389
|
+
markNextFileBlobFetchBypassHttpCache(e) {
|
|
1390
|
+
this._blobFetchForceReloadOnceIds.add(this.normalizeId(e));
|
|
1391
|
+
}
|
|
1392
|
+
normalizeId(e) {
|
|
1393
|
+
return !e || e === "root" || e === "folders" ? this._rootId : e;
|
|
1394
|
+
}
|
|
1395
|
+
_isDeletingId(e) {
|
|
1396
|
+
return this._mutationRegistry.isDeleting(this.normalizeId(e));
|
|
1397
|
+
}
|
|
1398
|
+
_collectDeletingIds(e) {
|
|
1399
|
+
let t = this.normalizeId(e), n = /* @__PURE__ */ new Set([t]);
|
|
1400
|
+
if (!this._cache.getEntity(t)?.isFolder) return Array.from(n);
|
|
1401
|
+
let r = [t];
|
|
1402
|
+
for (; r.length > 0;) {
|
|
1403
|
+
let e = r.pop(), t = this._cache.getChildrenIds(e);
|
|
1404
|
+
for (let e of t) n.has(e) || (n.add(e), this._cache.getEntity(e)?.isFolder && r.push(e));
|
|
1405
|
+
}
|
|
1406
|
+
return Array.from(n);
|
|
1407
|
+
}
|
|
1408
|
+
_emptyFilesResult(e, t) {
|
|
1409
|
+
return {
|
|
1410
|
+
files: [],
|
|
1411
|
+
pagination: {
|
|
1412
|
+
...typeof e == "number" ? { page: e } : {},
|
|
1413
|
+
...typeof t == "number" ? { limit: t } : {},
|
|
1414
|
+
total: 0,
|
|
1415
|
+
totalPages: 1,
|
|
1416
|
+
hasNext: !1,
|
|
1417
|
+
hasPrev: !1
|
|
1418
|
+
}
|
|
1419
|
+
};
|
|
1420
|
+
}
|
|
1421
|
+
_validateName(t, n = !1) {
|
|
1422
|
+
if (!t || t.trim().length === 0) throw new e(n ? "Folder name cannot be empty" : "File name cannot be empty", n ? "FolderInvalidName" : "FileInvalidName");
|
|
1423
|
+
if (/[/\\:*?"<>|]/.test(t)) {
|
|
1424
|
+
let r = n ? "FolderInvalidName" : "FileInvalidName";
|
|
1425
|
+
throw new e(n ? "Folder name contains invalid characters: %s".replace("%s", t) : "File name contains invalid characters: %s".replace("%s", t), r);
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
_validateTargetFolderType(t) {
|
|
1429
|
+
let n = this.normalizeId(t);
|
|
1430
|
+
if (n === this._rootId) return;
|
|
1431
|
+
let r = this._cache.getEntity(n);
|
|
1432
|
+
if (r && !r.isFolder) throw new e("Target item with id '%s' is not a folder".replace("%s", t), "ValidationError");
|
|
1433
|
+
}
|
|
1434
|
+
_checkNameExistsInCache(e, t, n, r) {
|
|
1435
|
+
let i = this.normalizeId(e), a = this._cache.getChildrenIds(i);
|
|
1436
|
+
for (let e of a) {
|
|
1437
|
+
let i = this._cache.getEntity(e);
|
|
1438
|
+
if (i && i.name === t && !!i.isFolder === n && (!r || i.id !== r)) return !0;
|
|
1439
|
+
}
|
|
1440
|
+
return !1;
|
|
1441
|
+
}
|
|
1442
|
+
async _getUrl(e) {
|
|
1443
|
+
if (e) {
|
|
1444
|
+
if (e.url) return e.url;
|
|
1445
|
+
try {
|
|
1446
|
+
return typeof this._dataProvider?.getUrl == "function" && this._dataProvider.getUrl(e) || void 0;
|
|
1447
|
+
} catch (e) {
|
|
1448
|
+
console.log(e);
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
async _getThumbnailUrl(e) {
|
|
1453
|
+
if (e) {
|
|
1454
|
+
if (e.thumbnailUrl) return e.thumbnailUrl;
|
|
1455
|
+
try {
|
|
1456
|
+
return typeof this._dataProvider?.getThumbnailUrl == "function" && this._dataProvider.getThumbnailUrl(e) || void 0;
|
|
1457
|
+
} catch (e) {
|
|
1458
|
+
console.log(e);
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
_isAncestor(e, t) {
|
|
1463
|
+
if (!t) return !1;
|
|
1464
|
+
let n = this.normalizeId(t), r = this.normalizeId(e);
|
|
1465
|
+
if (n === r) return !0;
|
|
1466
|
+
let i = this._cache.getEntity(n), a = /* @__PURE__ */ new Set();
|
|
1467
|
+
for (; i && i.folderId && !a.has(i.id);) {
|
|
1468
|
+
a.add(i.id);
|
|
1469
|
+
let e = this.normalizeId(i.folderId);
|
|
1470
|
+
if (e === r) return !0;
|
|
1471
|
+
if (i = this._cache.getEntity(e), !i || !i.isFolder) break;
|
|
1472
|
+
}
|
|
1473
|
+
return !1;
|
|
1474
|
+
}
|
|
1475
|
+
async getFile(e, t) {
|
|
1476
|
+
return this._isDeletingId(e) ? null : this._cache.searchByName(t, {
|
|
1477
|
+
parentId: this.normalizeId(e),
|
|
1478
|
+
caseSensitive: !0,
|
|
1479
|
+
recursive: !1,
|
|
1480
|
+
itemType: "file"
|
|
1481
|
+
})[0] || (await this.getFiles({
|
|
1482
|
+
folderId: e,
|
|
1483
|
+
itemType: "file",
|
|
1484
|
+
search: t
|
|
1485
|
+
})).files[0];
|
|
1486
|
+
}
|
|
1487
|
+
async getFileById(e) {
|
|
1488
|
+
let t = this.normalizeId(e);
|
|
1489
|
+
if (this._isDeletingId(t)) return null;
|
|
1490
|
+
let n = this._cache.getFileSystemItem(t);
|
|
1491
|
+
if (n && !n.isFolder) return await this._mapItem(n);
|
|
1492
|
+
if (!this._dataProvider.pathMode) return null;
|
|
1493
|
+
let r = await this._getFileByPathStyleId(t);
|
|
1494
|
+
if (r && !r.isFolder) {
|
|
1495
|
+
let e = W(r);
|
|
1496
|
+
return this._cache.upsertEntity(e), await this._mapItem(e);
|
|
1497
|
+
}
|
|
1498
|
+
return null;
|
|
1499
|
+
}
|
|
1500
|
+
async _getFileByPathStyleId(e) {
|
|
1501
|
+
let t = e.replace(/\\/g, "/").replace(/^\/+/, ""), n = t.lastIndexOf("/"), r = n < 0 ? "" : t.slice(0, n), i = n < 0 ? t : t.slice(n + 1);
|
|
1502
|
+
return i ? this.getFile(r, i) : null;
|
|
1503
|
+
}
|
|
1504
|
+
async getFileUrl(e, t) {
|
|
1505
|
+
let n = await this.getFile(e ?? "", t);
|
|
1506
|
+
if (n) return await this._getUrl(n) || await this._getThumbnailUrl(n) || n.thumbnail;
|
|
1507
|
+
}
|
|
1508
|
+
async getFiles({ folderId: e, search: t, sortBy: n, sortOrder: r, page: i, limit: a, itemType: o = "all", noFolder: s = !1 }) {
|
|
1509
|
+
s && (e = (await this.getTempFolder())?.id);
|
|
1510
|
+
let c = this.normalizeId(e ?? this._rootId), l = this._options.enablePagination === !1, u = l ? 1 : i, d = l ? R : a, f = this._options.clientSideFilter, p = this._options.clientSideSorting, m = this._options.clientSidePaging, h = m ? Math.max(1, i ?? 1) : void 0, g = m ? typeof a == "number" && Number.isFinite(a) && a > 0 ? a : B : void 0, _ = this._emptyFilesResult(m ? h : u, m ? g : d);
|
|
1511
|
+
if (this._isDeletingId(c)) return _;
|
|
1512
|
+
let v = this._options.unifiedCatalogFetch !== !1 && l && (o === "folder" || o === "file"), y = v ? "all" : o, b = {
|
|
1513
|
+
folderId: c,
|
|
1514
|
+
itemType: y
|
|
1515
|
+
};
|
|
1516
|
+
f || (b.search = t), p || (b.sortBy = n ?? (y === "folder" ? void 0 : "date"), b.sortOrder = r ?? (y === "folder" ? void 0 : "desc")), m || (b.page = u, b.limit = v ? z : d);
|
|
1517
|
+
let x = v ? z : m ? void 0 : d, S = {
|
|
1518
|
+
folderId: c,
|
|
1519
|
+
itemType: y,
|
|
1520
|
+
search: f ? void 0 : t,
|
|
1521
|
+
sortBy: p ? void 0 : b.sortBy,
|
|
1522
|
+
sortOrder: p ? void 0 : b.sortOrder,
|
|
1523
|
+
page: m ? void 0 : u,
|
|
1524
|
+
pageSize: x
|
|
1525
|
+
}, C;
|
|
1526
|
+
try {
|
|
1527
|
+
C = await this._cache.getOrCreateChildren(c, S, async (e, t) => {
|
|
1528
|
+
let n = t.pageSize, r = n != null && Number.isFinite(Number(n)) ? Number(n) : R, i = await this._dataProvider.getItems({
|
|
1529
|
+
...t,
|
|
1530
|
+
folderId: e,
|
|
1531
|
+
limit: r
|
|
1532
|
+
}), a = G(i.items);
|
|
1533
|
+
return m ? {
|
|
1534
|
+
items: a,
|
|
1535
|
+
total: typeof i.pagination?.total == "number" ? i.pagination.total : a.length
|
|
1536
|
+
} : {
|
|
1537
|
+
items: a,
|
|
1538
|
+
...i.pagination
|
|
1539
|
+
};
|
|
1540
|
+
});
|
|
1541
|
+
} catch (e) {
|
|
1542
|
+
if (this._isDeletingId(c)) return _;
|
|
1543
|
+
throw e;
|
|
1544
|
+
}
|
|
1545
|
+
let w = C.items;
|
|
1546
|
+
if (v && (o === "folder" ? w = w.filter((e) => e.isFolder) : o === "file" && (w = w.filter((e) => !e.isFolder))), f) {
|
|
1547
|
+
if (typeof this._options.clientSideFilter == "function") w = this._options.clientSideFilter(w, t);
|
|
1548
|
+
else if (t) {
|
|
1549
|
+
let e = t.toLowerCase();
|
|
1550
|
+
w = w.filter((t) => t.name?.toLowerCase().includes(e));
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
p && (w = typeof this._options.clientSideSorting == "function" ? this._options.clientSideSorting(w, n, r) : this._defaultClientSideSort(w, n, r));
|
|
1554
|
+
let T;
|
|
1555
|
+
T = m || f || v ? w.length : C.total ?? w.length;
|
|
1556
|
+
let E = w;
|
|
1557
|
+
if (m) if (typeof this._options.clientSidePaging == "function") E = this._options.clientSidePaging(w, h, g);
|
|
1558
|
+
else {
|
|
1559
|
+
let e = (h - 1) * g, t = e + g;
|
|
1560
|
+
E = w.slice(e, t);
|
|
1561
|
+
}
|
|
1562
|
+
if (typeof this._dataProvider.getUrl == "function" || typeof this._dataProvider.getThumbnailUrl == "function") {
|
|
1563
|
+
let e = E.map(async (e) => {
|
|
1564
|
+
if (e.isFolder) return e;
|
|
1565
|
+
let [t, n] = await Promise.all([e.url ? Promise.resolve(e.url) : typeof this._dataProvider.getUrl == "function" ? this._dataProvider.getUrl(e) : Promise.resolve(void 0), e.thumbnailUrl ? Promise.resolve(e.thumbnailUrl) : typeof this._dataProvider.getThumbnailUrl == "function" ? this._dataProvider.getThumbnailUrl(e) : Promise.resolve(void 0)]);
|
|
1566
|
+
return {
|
|
1567
|
+
...e,
|
|
1568
|
+
url: t,
|
|
1569
|
+
thumbnailUrl: n
|
|
1570
|
+
};
|
|
1571
|
+
});
|
|
1572
|
+
E = await Promise.all(e);
|
|
1573
|
+
}
|
|
1574
|
+
let D = m ? {
|
|
1575
|
+
page: h,
|
|
1576
|
+
limit: g,
|
|
1577
|
+
total: T,
|
|
1578
|
+
totalPages: Math.max(1, Math.ceil(T / g)),
|
|
1579
|
+
hasNext: h * g < T,
|
|
1580
|
+
hasPrev: h > 1
|
|
1581
|
+
} : {
|
|
1582
|
+
page: u,
|
|
1583
|
+
limit: d,
|
|
1584
|
+
total: T,
|
|
1585
|
+
...!m && C.totalPages && { totalPages: C.totalPages },
|
|
1586
|
+
...!m && C.hasNextPage && { hasNextPage: C.hasNextPage }
|
|
1587
|
+
};
|
|
1588
|
+
return {
|
|
1589
|
+
files: await Promise.all(E.map(this._mapItem)),
|
|
1590
|
+
pagination: D
|
|
1591
|
+
};
|
|
1592
|
+
}
|
|
1593
|
+
_defaultClientSideSort(e, t, n) {
|
|
1594
|
+
return e.sort((e, r) => l(e, r, {
|
|
1595
|
+
sortBy: t,
|
|
1596
|
+
sortOrder: n
|
|
1597
|
+
}));
|
|
1598
|
+
}
|
|
1599
|
+
async getFileData(t, n) {
|
|
1600
|
+
let r = this.normalizeId(typeof t == "string" ? t : t.id), i = n;
|
|
1601
|
+
this._blobFetchForceReloadOnceIds.delete(r) && (i = {
|
|
1602
|
+
...n,
|
|
1603
|
+
forceReload: !0
|
|
1604
|
+
});
|
|
1605
|
+
let a = this._cache.getEntity(r) || (typeof t == "string" ? {
|
|
1606
|
+
id: r,
|
|
1607
|
+
name: "",
|
|
1608
|
+
folderId: this._rootId,
|
|
1609
|
+
isFolder: !1
|
|
1610
|
+
} : {
|
|
1611
|
+
...t,
|
|
1612
|
+
childrenCount: t.childCount
|
|
1613
|
+
});
|
|
1614
|
+
if (typeof this._dataProvider.getFileData == "function") return await this._dataProvider.getFileData(a, i);
|
|
1615
|
+
if (!a.url && typeof this._dataProvider.getUrl != "function") throw new e("Cannot read file", "FileReadError");
|
|
1616
|
+
let o = a.url || (typeof this._dataProvider.getUrl == "function" ? await this._dataProvider.getUrl(a) : "");
|
|
1617
|
+
if (o) return (await (this._config.fetchWithProxy ?? fetch)(o, i?.forceReload ? { cache: "no-store" } : void 0)).blob();
|
|
1618
|
+
throw new e("Unable to get file data", "FileReadError");
|
|
1619
|
+
}
|
|
1620
|
+
async findFileByUrl(e) {
|
|
1621
|
+
let t = this._cache.searchByUrl(e);
|
|
1622
|
+
if (t) return t;
|
|
1623
|
+
if (typeof this._dataProvider.findFileByUrl == "function") try {
|
|
1624
|
+
let t = await this._dataProvider.findFileByUrl(e);
|
|
1625
|
+
if (t) {
|
|
1626
|
+
let e = W(t);
|
|
1627
|
+
return this._cache.upsertEntity(e), e;
|
|
1628
|
+
}
|
|
1629
|
+
} catch (e) {
|
|
1630
|
+
console.log(e);
|
|
1631
|
+
}
|
|
1632
|
+
return null;
|
|
1633
|
+
}
|
|
1634
|
+
async getChildrenCount(e) {
|
|
1635
|
+
if (!e) return 0;
|
|
1636
|
+
let t = this.normalizeId(e ?? this._rootId);
|
|
1637
|
+
return this._isDeletingId(t) ? 0 : this._cache.getChildrenCount(t, async () => {
|
|
1638
|
+
try {
|
|
1639
|
+
if (this._options.clientSidePaging) {
|
|
1640
|
+
let e = await this.getFiles({
|
|
1641
|
+
folderId: t,
|
|
1642
|
+
itemType: "all",
|
|
1643
|
+
page: 1,
|
|
1644
|
+
limit: B
|
|
1645
|
+
});
|
|
1646
|
+
return e.pagination.total ?? e.files.length;
|
|
1647
|
+
}
|
|
1648
|
+
let e = await this._dataProvider.getItems({
|
|
1649
|
+
folderId: t,
|
|
1650
|
+
limit: 0,
|
|
1651
|
+
itemType: "all"
|
|
1652
|
+
});
|
|
1653
|
+
return e.pagination === void 0 ? this._options.enablePagination === !1 ? e.items.length : 0 : e.pagination.total || 0;
|
|
1654
|
+
} catch (e) {
|
|
1655
|
+
if (this._isDeletingId(t) || this._isPathFolderNotFoundError(e)) return 0;
|
|
1656
|
+
throw e;
|
|
1657
|
+
}
|
|
1658
|
+
});
|
|
1659
|
+
}
|
|
1660
|
+
_isPathFolderNotFoundError(e) {
|
|
1661
|
+
if (!e || typeof e != "object") return !1;
|
|
1662
|
+
let t = e;
|
|
1663
|
+
return t.code === "path_folder_not_found" || t.data?.code === "path_folder_not_found" || t.status === 404 || t.data?.data?.status === 404;
|
|
1664
|
+
}
|
|
1665
|
+
async _uploadFile(t) {
|
|
1666
|
+
let n = this.normalizeId(t.folderId ?? this._rootId);
|
|
1667
|
+
if (typeof this._dataProvider.uploadFile != "function") throw new e("Upload file operation is not supported by data provider", "UnsupportedOperation");
|
|
1668
|
+
if (this._validateName(t.name, !1), this._validateDuplicates && this._checkNameExistsInCache(n, t.name, !1)) throw new e("File '%s' already exists in target folder".replace("%s", t.name), "FileAlreadyExists");
|
|
1669
|
+
let r = await this._dataProvider.uploadFile({
|
|
1670
|
+
...t,
|
|
1671
|
+
folderId: n
|
|
1672
|
+
}), i = W({
|
|
1673
|
+
name: t.name,
|
|
1674
|
+
size: t.size,
|
|
1675
|
+
...r,
|
|
1676
|
+
folderId: r.folderId ?? n
|
|
1677
|
+
});
|
|
1678
|
+
return this._cache.upsertEntity(i), i;
|
|
1679
|
+
}
|
|
1680
|
+
async uploadFiles(t) {
|
|
1681
|
+
let n = t.items.some((e) => e.noFolder) ? await this.getTempFolder() : null;
|
|
1682
|
+
t = {
|
|
1683
|
+
...t,
|
|
1684
|
+
items: t.items?.map((e) => ({
|
|
1685
|
+
...e,
|
|
1686
|
+
folderId: e.noFolder ? n?.id : e.folderId
|
|
1687
|
+
}))
|
|
1688
|
+
};
|
|
1689
|
+
for (let e of t.items) e.folderId && (t.folderId = e.folderId);
|
|
1690
|
+
let r = t.items || [], i = t.folderId ?? this._rootId, a = this.normalizeId(i);
|
|
1691
|
+
if (this._validateDuplicates) {
|
|
1692
|
+
for (let t of r) if (t.name) {
|
|
1693
|
+
this._validateName(t.name, !1);
|
|
1694
|
+
let n = this.normalizeId(t.folderId ?? a);
|
|
1695
|
+
if (this._checkNameExistsInCache(n, t.name, !1)) throw new e("File '%s' already exists in target folder".replace("%s", t.name), "FileAlreadyExists");
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
let o = {
|
|
1699
|
+
detailed: Array(r.length),
|
|
1700
|
+
success: !0
|
|
1701
|
+
};
|
|
1702
|
+
if (typeof this._dataProvider.uploadFiles == "function") {
|
|
1703
|
+
let e = r.map((e) => ({
|
|
1704
|
+
...e,
|
|
1705
|
+
folderId: this.normalizeId(e.folderId ?? a)
|
|
1706
|
+
})), t = await this._dataProvider.uploadFiles({
|
|
1707
|
+
folderId: a,
|
|
1708
|
+
items: e
|
|
1709
|
+
});
|
|
1710
|
+
o = H(t, (e) => {
|
|
1711
|
+
if (e) return {
|
|
1712
|
+
id: e.id,
|
|
1713
|
+
name: U(e.name),
|
|
1714
|
+
folderId: e.folderId,
|
|
1715
|
+
url: e.url,
|
|
1716
|
+
thumbnailUrl: e.thumbnailUrl,
|
|
1717
|
+
thumbnail: e.thumbnail
|
|
1718
|
+
};
|
|
1719
|
+
});
|
|
1720
|
+
let n = t?.detailed;
|
|
1721
|
+
if (o.detailed && o.detailed.length) {
|
|
1722
|
+
for (let e = 0; e < o.detailed.length; e++) {
|
|
1723
|
+
let t = o.detailed[e];
|
|
1724
|
+
if (t && t.success) {
|
|
1725
|
+
let r = t.data, i = r?.id ?? t.requestId, o = n?.[e]?.data, s = W({
|
|
1726
|
+
...o,
|
|
1727
|
+
...r,
|
|
1728
|
+
id: i,
|
|
1729
|
+
folderId: r?.folderId ?? o?.folderId ?? a,
|
|
1730
|
+
isFolder: !1
|
|
1731
|
+
});
|
|
1732
|
+
this._cache.upsertEntity(s), t.requestId = i;
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
o.success === void 0 && (o.success = !o.detailed.some((e) => !e.success));
|
|
1736
|
+
} else o.success = !o.error && !!o.success;
|
|
1737
|
+
} else if (typeof this._dataProvider.uploadFile == "function") o.detailed = await Promise.all(r.map(async (e) => {
|
|
1738
|
+
let t = this.normalizeId(e.folderId ?? a);
|
|
1739
|
+
try {
|
|
1740
|
+
let n = await this._uploadFile({
|
|
1741
|
+
...e,
|
|
1742
|
+
folderId: t
|
|
1743
|
+
});
|
|
1744
|
+
return {
|
|
1745
|
+
requestId: n.id,
|
|
1746
|
+
data: n,
|
|
1747
|
+
success: !0
|
|
1748
|
+
};
|
|
1749
|
+
} catch (t) {
|
|
1750
|
+
return {
|
|
1751
|
+
requestId: e?.id,
|
|
1752
|
+
success: !1,
|
|
1753
|
+
error: t
|
|
1754
|
+
};
|
|
1755
|
+
}
|
|
1756
|
+
})), o.success = !o.detailed.some((e) => !e.success);
|
|
1757
|
+
else throw new e("Upload files is not supported by data provider", "UnsupportedOperation");
|
|
1758
|
+
if (o.success && this._enableTrash) try {
|
|
1759
|
+
this._cache.forceInvalidate(a);
|
|
1760
|
+
} catch {}
|
|
1761
|
+
return o;
|
|
1762
|
+
}
|
|
1763
|
+
async deleteFile(e) {
|
|
1764
|
+
let t = this.normalizeId(e), n = [t];
|
|
1765
|
+
this._mutationRegistry.beginDeleting(n);
|
|
1766
|
+
try {
|
|
1767
|
+
if (this._useSoftDelete && this._enableTrash) {
|
|
1768
|
+
let e = await this.getTrashFolder();
|
|
1769
|
+
return await this.moveItem({
|
|
1770
|
+
itemId: t,
|
|
1771
|
+
targetFolderId: e.id,
|
|
1772
|
+
isFolder: !1
|
|
1773
|
+
});
|
|
1774
|
+
}
|
|
1775
|
+
return await this.hardDeleteItem(t);
|
|
1776
|
+
} finally {
|
|
1777
|
+
this._mutationRegistry.endDeleting(n);
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
async deleteItems(e, t) {
|
|
1781
|
+
let n = Array.from(new Set(e.flatMap((e) => this._collectDeletingIds(this.normalizeId(e)))));
|
|
1782
|
+
this._mutationRegistry.beginDeleting(n);
|
|
1783
|
+
try {
|
|
1784
|
+
if (this._useSoftDelete && this._enableTrash && t.permanent !== !0) {
|
|
1785
|
+
let t = await this.getTrashFolder();
|
|
1786
|
+
return await this.moveItems(t.id, e);
|
|
1787
|
+
}
|
|
1788
|
+
return await this.hardDeleteItems(e, t);
|
|
1789
|
+
} finally {
|
|
1790
|
+
this._mutationRegistry.endDeleting(n);
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
async hardDeleteItems(t, n) {
|
|
1794
|
+
let r = {
|
|
1795
|
+
success: !0,
|
|
1796
|
+
detailed: []
|
|
1797
|
+
}, i = n.permanent ? null : await this.getTrashFolder();
|
|
1798
|
+
if (typeof this._dataProvider.deleteItems == "function") {
|
|
1799
|
+
if (r = H(await this._dataProvider.deleteItems(t.map((e) => this._cache.getEntity(e)), n), (e) => e), r.success) {
|
|
1800
|
+
let e = r.detailed || t.map((e) => ({
|
|
1801
|
+
requestId: e,
|
|
1802
|
+
success: !0,
|
|
1803
|
+
error: void 0
|
|
1804
|
+
}));
|
|
1805
|
+
for (let t of e) t.success && (i ? this._cache.moveEntity(t.requestId, i.id) : this._cache.deleteEntity(t.requestId));
|
|
1806
|
+
}
|
|
1807
|
+
} else typeof this._dataProvider.deleteItem == "function" && (r.detailed = await Promise.all(t.map(async (t) => {
|
|
1808
|
+
let r = this._cache.getEntity(t);
|
|
1809
|
+
if (!r) return {
|
|
1810
|
+
requestId: t,
|
|
1811
|
+
success: !1,
|
|
1812
|
+
error: new e("Item with id '%s' not found".replace("%s", t), "FileNotFound")
|
|
1813
|
+
};
|
|
1814
|
+
try {
|
|
1815
|
+
return await this._dataProvider.deleteItem(r, n), i ? this._cache.moveEntity(t, i.id) : this._cache.deleteEntity(t), {
|
|
1816
|
+
requestId: t,
|
|
1817
|
+
success: !0
|
|
1818
|
+
};
|
|
1819
|
+
} catch (e) {
|
|
1820
|
+
return {
|
|
1821
|
+
requestId: t,
|
|
1822
|
+
error: e,
|
|
1823
|
+
success: !1
|
|
1824
|
+
};
|
|
1825
|
+
}
|
|
1826
|
+
})), r.success = !r.detailed.some((e) => !e.success));
|
|
1827
|
+
if (r.success && i) try {
|
|
1828
|
+
this._cache.forceInvalidate(i.id);
|
|
1829
|
+
} catch {}
|
|
1830
|
+
return r;
|
|
1831
|
+
}
|
|
1832
|
+
async hardDeleteItem(t) {
|
|
1833
|
+
let n = this._cache.getEntity(t);
|
|
1834
|
+
if (!n) throw new e("Item with id '%s' not found in cache".replace("%s", t), "FileNotFound");
|
|
1835
|
+
if (typeof this._dataProvider.deleteItem != "function") throw new e("Delete item operation is not supported by data provider", "DeleteNotAllowed");
|
|
1836
|
+
if (await this._dataProvider.deleteItem(n, { permanent: !0 }), this._cache.deleteEntity(t), this._enableTrash) try {
|
|
1837
|
+
let e = await this.getTrashFolder();
|
|
1838
|
+
e && this._cache.forceInvalidate(e.id);
|
|
1839
|
+
} catch {}
|
|
1840
|
+
return !0;
|
|
1841
|
+
}
|
|
1842
|
+
async cleanTrash() {
|
|
1843
|
+
if (!this._enableTrash) throw new e("Trash is not enabled", "UnsupportedOperation");
|
|
1844
|
+
if (typeof this._dataProvider.cleanTrash == "function") {
|
|
1845
|
+
let e = await this._dataProvider.cleanTrash();
|
|
1846
|
+
try {
|
|
1847
|
+
let e = await this.getTrashFolder();
|
|
1848
|
+
e && this._cache.forceInvalidate(e.id);
|
|
1849
|
+
} catch {}
|
|
1850
|
+
return e;
|
|
1851
|
+
}
|
|
1852
|
+
throw new e("Clean trash is not supported by data provider", "UnsupportedOperation");
|
|
1853
|
+
}
|
|
1854
|
+
async createFolder({ name: t, parentId: n, is_force_create: r }) {
|
|
1855
|
+
let i = this.normalizeId(n ?? this._rootId);
|
|
1856
|
+
if (this._validateName(t, !0), this._validateDuplicates && this._checkNameExistsInCache(i, t, !0)) throw new e("Folder '%s' already exists in parent folder".replace("%s", t), "FolderAlreadyExists");
|
|
1857
|
+
let a = await this._dataProvider.createFolder(t, i, r), o = W({
|
|
1858
|
+
id: a.id,
|
|
1859
|
+
folderId: i,
|
|
1860
|
+
name: a.name,
|
|
1861
|
+
isFolder: !0,
|
|
1862
|
+
childrenCount: a.childrenCount
|
|
1863
|
+
});
|
|
1864
|
+
return this._cache.upsertEntity(o), {
|
|
1865
|
+
...a,
|
|
1866
|
+
name: o.name
|
|
1867
|
+
};
|
|
1868
|
+
}
|
|
1869
|
+
async deleteFolder(e) {
|
|
1870
|
+
let t = this.normalizeId(e), n = this._collectDeletingIds(t);
|
|
1871
|
+
this._mutationRegistry.beginDeleting(n);
|
|
1872
|
+
try {
|
|
1873
|
+
if (this._useSoftDelete && this._enableTrash) try {
|
|
1874
|
+
let e = await this.getTrashFolder();
|
|
1875
|
+
return await this.moveItem({
|
|
1876
|
+
itemId: t,
|
|
1877
|
+
targetFolderId: e.id,
|
|
1878
|
+
isFolder: !0
|
|
1879
|
+
}) ? (this._cache.deleteFolderRecursive(t), !0) : !1;
|
|
1880
|
+
} catch (e) {
|
|
1881
|
+
return console.error("Error moving folder to trash:", e), await this.hardDeleteItem(t);
|
|
1882
|
+
}
|
|
1883
|
+
return await this.hardDeleteItem(t);
|
|
1884
|
+
} finally {
|
|
1885
|
+
this._mutationRegistry.endDeleting(n);
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
async renameFolder(t, n) {
|
|
1889
|
+
if (typeof this._dataProvider.renameItem != "function") throw new e("Rename folder is not supported", "RenameNotAllowed");
|
|
1890
|
+
let r = this.normalizeId(t), i = this._cache.getEntity(r);
|
|
1891
|
+
if (!i) throw new e("Folder with id '%s' not found in cache".replace("%s", t), "FolderNotFound");
|
|
1892
|
+
if (this._validateName(n, !0), this._validateDuplicates) {
|
|
1893
|
+
let t = this.normalizeId(i.folderId);
|
|
1894
|
+
if (this._checkNameExistsInCache(t, n, !0, r)) throw new e("Folder '%s' already exists in parent folder".replace("%s", n), "FolderAlreadyExists");
|
|
1895
|
+
}
|
|
1896
|
+
let a = K(await this._dataProvider.renameItem(i, n));
|
|
1897
|
+
return this._cache.upsertEntity(W({
|
|
1898
|
+
...this._cache.getEntity(a.id),
|
|
1899
|
+
...a
|
|
1900
|
+
})), this._cache.getEntity(a.id);
|
|
1901
|
+
}
|
|
1902
|
+
async renameFile(t, n) {
|
|
1903
|
+
if (typeof this._dataProvider.renameItem != "function") throw new e("Rename file is not supported", "RenameNotAllowed");
|
|
1904
|
+
let r = this._cache.getEntity(t);
|
|
1905
|
+
if (!r) throw new e("File with id '%s' not found in cache".replace("%s", t), "FileNotFound");
|
|
1906
|
+
let i = this.normalizeId(t);
|
|
1907
|
+
if (this._validateName(n, !1), this._validateDuplicates) {
|
|
1908
|
+
let t = this.normalizeId(r.folderId);
|
|
1909
|
+
if (this._checkNameExistsInCache(t, n, !1, i)) throw new e("File '%s' already exists in parent folder".replace("%s", n), "FileAlreadyExists");
|
|
1910
|
+
}
|
|
1911
|
+
let a = K(await this._dataProvider.renameItem(r, n));
|
|
1912
|
+
return a && this._cache.upsertEntity(W({
|
|
1913
|
+
...this._cache.getEntity(i),
|
|
1914
|
+
...a
|
|
1915
|
+
})), this._cache.getEntity(i);
|
|
1916
|
+
}
|
|
1917
|
+
async moveItem({ itemId: t, targetFolderId: n, isFolder: r }) {
|
|
1918
|
+
if (typeof this._dataProvider.moveItem != "function") throw new e("Move item operation is not supported by data provider", "MoveNotAllowed");
|
|
1919
|
+
let i = this.normalizeId(n);
|
|
1920
|
+
this._validateTargetFolderType(n);
|
|
1921
|
+
let a = this._cache.getEntity(t);
|
|
1922
|
+
if (!a) {
|
|
1923
|
+
let e = K(await this._dataProvider.moveItem({
|
|
1924
|
+
id: t,
|
|
1925
|
+
folderId: i,
|
|
1926
|
+
isFolder: r
|
|
1927
|
+
}, i));
|
|
1928
|
+
if (e.id === t) this._cache.upsertEntity(W({
|
|
1929
|
+
...e,
|
|
1930
|
+
folderId: i
|
|
1931
|
+
}));
|
|
1932
|
+
else {
|
|
1933
|
+
try {
|
|
1934
|
+
this._cache.deleteEntity(t);
|
|
1935
|
+
} catch {}
|
|
1936
|
+
this._cache.upsertEntity(W({
|
|
1937
|
+
...e,
|
|
1938
|
+
folderId: i
|
|
1939
|
+
}));
|
|
1940
|
+
}
|
|
1941
|
+
return !0;
|
|
1942
|
+
}
|
|
1943
|
+
if (a.isFolder) {
|
|
1944
|
+
if (t === i) throw new e("Cannot move folder into itself", "MoveIntoSelf");
|
|
1945
|
+
if (this._isAncestor(t, i)) throw new e("Cannot move folder into its descendant", "MoveIntoDescendant");
|
|
1946
|
+
}
|
|
1947
|
+
if (this._validateDuplicates && i !== this.normalizeId(a.folderId) && a.name && this._checkNameExistsInCache(i, a.name, !!a.isFolder, t)) {
|
|
1948
|
+
let t = a.isFolder ? "FolderAlreadyExists" : "FileAlreadyExists";
|
|
1949
|
+
throw new e(`${a.isFolder ? "Folder" : "File"} '${a.name}' already exists in target folder`, t);
|
|
1950
|
+
}
|
|
1951
|
+
let o = K(await this._dataProvider.moveItem(a, i));
|
|
1952
|
+
if (o.id === t) {
|
|
1953
|
+
let e = this._cache.moveEntity(t, i);
|
|
1954
|
+
return this._cache.upsertEntity(W({
|
|
1955
|
+
...e,
|
|
1956
|
+
...o
|
|
1957
|
+
})), !0;
|
|
1958
|
+
} else {
|
|
1959
|
+
let e = this._cache.deleteEntity(t);
|
|
1960
|
+
return this._cache.upsertEntity(W({
|
|
1961
|
+
...e,
|
|
1962
|
+
...o,
|
|
1963
|
+
folderId: i
|
|
1964
|
+
})), !0;
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
async moveItems(t, n) {
|
|
1968
|
+
let r = this.normalizeId(t);
|
|
1969
|
+
this._validateTargetFolderType(t);
|
|
1970
|
+
let i = n.map((e) => this._cache.getEntity(e));
|
|
1971
|
+
for (let t of i) if (t) {
|
|
1972
|
+
if (t.isFolder) {
|
|
1973
|
+
if (t.id === r) throw new e("Cannot move folder '%s' into itself".replace("%s", t.name), "MoveIntoSelf");
|
|
1974
|
+
if (this._isAncestor(t.id, r)) throw new e("Cannot move folder '%s' into its descendant".replace("%s", t.name), "MoveIntoDescendant");
|
|
1975
|
+
}
|
|
1976
|
+
if (this._validateDuplicates && r !== this.normalizeId(t.folderId) && t.name && this._checkNameExistsInCache(r, t.name, !!t.isFolder, t.id)) {
|
|
1977
|
+
let n = t.isFolder ? "FolderAlreadyExists" : "FileAlreadyExists";
|
|
1978
|
+
throw new e(`${t.isFolder ? "Folder" : "File"} '${t.name}' already exists in target folder`, n);
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
let a = {
|
|
1982
|
+
detailed: Array(i.length),
|
|
1983
|
+
success: !0
|
|
1984
|
+
};
|
|
1985
|
+
if (typeof this._dataProvider.moveItems == "function") a = H(await this._dataProvider.moveItems(i, r), (e) => e);
|
|
1986
|
+
else if (typeof this._dataProvider.moveItem == "function") a.detailed = await Promise.all(n.map(async (e, t) => {
|
|
1987
|
+
let n = i[t] || {
|
|
1988
|
+
id: e,
|
|
1989
|
+
folderId: null,
|
|
1990
|
+
isFolder: !1,
|
|
1991
|
+
name: e
|
|
1992
|
+
};
|
|
1993
|
+
try {
|
|
1994
|
+
return {
|
|
1995
|
+
requestId: e,
|
|
1996
|
+
data: K(await this._dataProvider.moveItem(n, r)),
|
|
1997
|
+
success: !0
|
|
1998
|
+
};
|
|
1999
|
+
} catch (t) {
|
|
2000
|
+
return {
|
|
2001
|
+
requestId: e,
|
|
2002
|
+
success: !1,
|
|
2003
|
+
error: t
|
|
2004
|
+
};
|
|
2005
|
+
}
|
|
2006
|
+
}));
|
|
2007
|
+
else throw new e("Move items is not supported", "MoveNotAllowed");
|
|
2008
|
+
if (a.success) {
|
|
2009
|
+
let e = a.detailed || n.map((e) => ({
|
|
2010
|
+
requestId: e,
|
|
2011
|
+
success: !0,
|
|
2012
|
+
data: void 0
|
|
2013
|
+
}));
|
|
2014
|
+
for (let t of e) if (t.success) if (!t.data || t.data.id === t.requestId) this._cache.moveEntity(t.requestId, r), t.data && this._cache.upsertEntity(W({
|
|
2015
|
+
...this._cache.getEntity(t.requestId),
|
|
2016
|
+
...t.data,
|
|
2017
|
+
folderId: r
|
|
2018
|
+
}));
|
|
2019
|
+
else {
|
|
2020
|
+
let e = this._cache.deleteEntity(t.requestId);
|
|
2021
|
+
this._cache.upsertEntity(W({
|
|
2022
|
+
...e,
|
|
2023
|
+
...t.data,
|
|
2024
|
+
folderId: r
|
|
2025
|
+
}));
|
|
2026
|
+
}
|
|
2027
|
+
return a;
|
|
2028
|
+
} else return {
|
|
2029
|
+
success: !1,
|
|
2030
|
+
error: a.error || new e("Move items failed", "MoveNotAllowed")
|
|
2031
|
+
};
|
|
2032
|
+
}
|
|
2033
|
+
async copyItem({ itemId: t, targetFolderId: n }) {
|
|
2034
|
+
if (typeof this._dataProvider.copyItem != "function") throw new e("Copy item is not supported", "CopyNotAllowed");
|
|
2035
|
+
let r = this.normalizeId(n);
|
|
2036
|
+
this._validateTargetFolderType(n);
|
|
2037
|
+
let i = this._cache.getEntity(t);
|
|
2038
|
+
if (!i) {
|
|
2039
|
+
let e = K(await this._dataProvider.copyItem({
|
|
2040
|
+
id: t,
|
|
2041
|
+
folderId: r
|
|
2042
|
+
}, r));
|
|
2043
|
+
return this._cache.copyEntity(t, r, e.id), this._cache.upsertEntity(W({
|
|
2044
|
+
...e,
|
|
2045
|
+
folderId: r
|
|
2046
|
+
})), !0;
|
|
2047
|
+
}
|
|
2048
|
+
if (this._validateDuplicates && i.name) {
|
|
2049
|
+
let n = r === this.normalizeId(i.folderId) ? t : void 0;
|
|
2050
|
+
if (this._checkNameExistsInCache(r, i.name, !!i.isFolder, n)) {
|
|
2051
|
+
let t = i.isFolder ? "FolderAlreadyExists" : "FileAlreadyExists";
|
|
2052
|
+
throw new e(`${i.isFolder ? "Folder" : "File"} '${i.name}' already exists in target folder`, t);
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
let a = K(await this._dataProvider.copyItem(i, r));
|
|
2056
|
+
return this._cache.copyEntity(t, r, a.id, {
|
|
2057
|
+
...a,
|
|
2058
|
+
folderId: r
|
|
2059
|
+
}) || this._cache.upsertEntity(W({
|
|
2060
|
+
...a,
|
|
2061
|
+
folderId: r
|
|
2062
|
+
})), !0;
|
|
2063
|
+
}
|
|
2064
|
+
async copyItems(t, n) {
|
|
2065
|
+
let r = this.normalizeId(t);
|
|
2066
|
+
this._validateTargetFolderType(t);
|
|
2067
|
+
let i = n.map((e) => typeof e == "string" ? { id: e } : e), a = i.map((e) => e.id), o = a.map((e, t) => {
|
|
2068
|
+
let n = this._cache.getEntity(e), r = i[t]?.newName;
|
|
2069
|
+
return n ? r ? {
|
|
2070
|
+
...n,
|
|
2071
|
+
name: r
|
|
2072
|
+
} : n : void 0;
|
|
2073
|
+
});
|
|
2074
|
+
if (this._validateDuplicates) for (let t = 0; t < o.length; t++) {
|
|
2075
|
+
let n = o[t];
|
|
2076
|
+
if (n && n.name) {
|
|
2077
|
+
let i = r === this.normalizeId(n.folderId) ? a[t] : void 0;
|
|
2078
|
+
if (this._checkNameExistsInCache(r, n.name, !!n.isFolder, i)) {
|
|
2079
|
+
let t = n.isFolder ? "FolderAlreadyExists" : "FileAlreadyExists";
|
|
2080
|
+
throw new e(`${n.isFolder ? "Folder" : "File"} '${n.name}' already exists in target folder`, t);
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
let s = {
|
|
2085
|
+
detailed: Array(o.length),
|
|
2086
|
+
success: !0
|
|
2087
|
+
};
|
|
2088
|
+
if (typeof this._dataProvider.copyItems == "function") s = H(await this._dataProvider.copyItems(o, r), (e) => e);
|
|
2089
|
+
else if (typeof this._dataProvider.copyItem == "function") s.detailed = await Promise.all(a.map(async (e, t) => {
|
|
2090
|
+
let n = o[t] || {
|
|
2091
|
+
id: e,
|
|
2092
|
+
folderId: null,
|
|
2093
|
+
isFolder: !1
|
|
2094
|
+
};
|
|
2095
|
+
try {
|
|
2096
|
+
return {
|
|
2097
|
+
requestId: e,
|
|
2098
|
+
data: K(await this._dataProvider.copyItem(n, r)),
|
|
2099
|
+
success: !0
|
|
2100
|
+
};
|
|
2101
|
+
} catch (t) {
|
|
2102
|
+
return {
|
|
2103
|
+
requestId: e,
|
|
2104
|
+
success: !1,
|
|
2105
|
+
error: t
|
|
2106
|
+
};
|
|
2107
|
+
}
|
|
2108
|
+
}));
|
|
2109
|
+
else throw new e("Copy items is not supported", "CopyNotAllowed");
|
|
2110
|
+
if (s.success && s.detailed) for (let e = 0, t = s.detailed.length; e < t; e++) {
|
|
2111
|
+
let t = s.detailed[e];
|
|
2112
|
+
if (t.success) if (t.data?.id) {
|
|
2113
|
+
let e = t.data.folderId || r;
|
|
2114
|
+
!this._cache.copyEntity(t.requestId, e, t.data.id, {
|
|
2115
|
+
...t.data,
|
|
2116
|
+
folderId: e
|
|
2117
|
+
}) && t.data && this._cache.upsertEntity(W({
|
|
2118
|
+
...t.data,
|
|
2119
|
+
folderId: e
|
|
2120
|
+
}));
|
|
2121
|
+
} else console.error("batchResult in copy method must have ids");
|
|
2122
|
+
}
|
|
2123
|
+
else if (!s.detailed) throw new e("batchResult in copy method must have detailed results", "ValidationError");
|
|
2124
|
+
return s;
|
|
2125
|
+
}
|
|
2126
|
+
async uploadFileByUrl(e) {
|
|
2127
|
+
if (e.noFolder) {
|
|
2128
|
+
let t = await this.getTempFolder();
|
|
2129
|
+
e = {
|
|
2130
|
+
...e,
|
|
2131
|
+
folderId: t?.id
|
|
2132
|
+
};
|
|
2133
|
+
}
|
|
2134
|
+
let t = this.normalizeId(e.folderId ?? this._rootId);
|
|
2135
|
+
try {
|
|
2136
|
+
let n = W({
|
|
2137
|
+
...await this._dataProvider.uploadFileByUrl(e.url, t, { eventSource: e.eventSource }),
|
|
2138
|
+
folderId: t
|
|
2139
|
+
});
|
|
2140
|
+
return this._cache.upsertEntity(n), n;
|
|
2141
|
+
} catch (e) {
|
|
2142
|
+
throw console.error("uploadFileByUrl error:", e), e;
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
async updateFile(t, n) {
|
|
2146
|
+
if (typeof this._dataProvider.updateFile != "function") throw new e("Update file is not supported", "UnsupportedOperation");
|
|
2147
|
+
let r = this.normalizeId(t), i = this._cache.getEntity(r);
|
|
2148
|
+
if (!i) throw new e("File with id '%s' not found in cache".replace("%s", t), "FileNotFound");
|
|
2149
|
+
if (n.name && n.name !== i.name && this._validateName(n.name, !1), this._validateDuplicates && n.name && n.name !== i.name) {
|
|
2150
|
+
let t = this.normalizeId(i.folderId);
|
|
2151
|
+
if (this._checkNameExistsInCache(t, n.name, !1, r)) throw new e("File '%s' already exists in parent folder".replace("%s", n.name), "FileAlreadyExists");
|
|
2152
|
+
}
|
|
2153
|
+
let a = K(await this._dataProvider.updateFile(i, { ...n }));
|
|
2154
|
+
return this._cache.upsertEntity(W({
|
|
2155
|
+
...this._cache.getEntity(r),
|
|
2156
|
+
...a,
|
|
2157
|
+
...n
|
|
2158
|
+
})), this._cache.getEntity(r);
|
|
2159
|
+
}
|
|
2160
|
+
}, Y = [], X = 0; X < 256; ++X) Y.push((X + 256).toString(16).slice(1));
|
|
2161
|
+
function ee(e, t = 0) {
|
|
2162
|
+
return (Y[e[t + 0]] + Y[e[t + 1]] + Y[e[t + 2]] + Y[e[t + 3]] + "-" + Y[e[t + 4]] + Y[e[t + 5]] + "-" + Y[e[t + 6]] + Y[e[t + 7]] + "-" + Y[e[t + 8]] + Y[e[t + 9]] + "-" + Y[e[t + 10]] + Y[e[t + 11]] + Y[e[t + 12]] + Y[e[t + 13]] + Y[e[t + 14]] + Y[e[t + 15]]).toLowerCase();
|
|
2163
|
+
}
|
|
2164
|
+
//#endregion
|
|
2165
|
+
//#region packages/file-manager/node_modules/uuid/dist/esm-browser/rng.js
|
|
2166
|
+
var Z, te = /* @__PURE__ */ new Uint8Array(16);
|
|
2167
|
+
function ne() {
|
|
2168
|
+
if (!Z && (Z = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !Z)) throw Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
2169
|
+
return Z(te);
|
|
2170
|
+
}
|
|
2171
|
+
var Q = { randomUUID: typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto) };
|
|
2172
|
+
//#endregion
|
|
2173
|
+
//#region packages/file-manager/node_modules/uuid/dist/esm-browser/v4.js
|
|
2174
|
+
function re(e, t, n) {
|
|
2175
|
+
if (Q.randomUUID && !t && !e) return Q.randomUUID();
|
|
2176
|
+
e ||= {};
|
|
2177
|
+
var r = e.random || (e.rng || ne)();
|
|
2178
|
+
if (r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, t) {
|
|
2179
|
+
n ||= 0;
|
|
2180
|
+
for (var i = 0; i < 16; ++i) t[n + i] = r[i];
|
|
2181
|
+
return t;
|
|
2182
|
+
}
|
|
2183
|
+
return ee(r);
|
|
2184
|
+
}
|
|
2185
|
+
//#endregion
|
|
2186
|
+
//#region packages/file-manager/src/adapters/PathAwareStorageAdapter.ts
|
|
2187
|
+
var ie = "", ae = "Trash", oe = class {
|
|
2188
|
+
constructor(e, t = ie, n = _, r = ae, i = !0) {
|
|
2189
|
+
this._inner = e, this.rootPath = t, this.trashId = n, this.trashPath = r, this.ensureFolderTrailingSlash = i, this._pathToId = /* @__PURE__ */ new Map(), this._idToPath = /* @__PURE__ */ new Map(), this.validateDuplicates = this._inner.validateDuplicates ?? !1, typeof e.getUrl == "function" && (this.getUrl = (t) => e.getUrl({
|
|
2190
|
+
...t,
|
|
2191
|
+
id: this.pathForId(t.id, !1),
|
|
2192
|
+
folderId: t.folderId ? this.pathForId(t.folderId, !0) : this.rootPath
|
|
2193
|
+
})), typeof e.getThumbnailUrl == "function" && (this.getThumbnailUrl = (t) => e.getThumbnailUrl({
|
|
2194
|
+
...t,
|
|
2195
|
+
id: this.pathForId(t.id, !1),
|
|
2196
|
+
folderId: t.folderId ? this.pathForId(t.folderId, !0) : this.rootPath
|
|
2197
|
+
}));
|
|
2198
|
+
let a = this;
|
|
2199
|
+
typeof this._inner.deleteItems != "function" && (a.deleteItems = void 0), typeof this._inner.deleteItem != "function" && (a.deleteItem = void 0), typeof this._inner.moveItems == "function" ? a.moveItem = void 0 : a.moveItems = void 0, typeof this._inner.copyItems == "function" ? a.copyItem = void 0 : a.copyItems = void 0, typeof this._inner.uploadFiles == "function" ? a.uploadFile = void 0 : a.uploadFiles = void 0, typeof this._inner.clearCache != "function" && (a.clearCache = void 0), this._getOrGenerateId(this.rootPath);
|
|
2200
|
+
}
|
|
2201
|
+
setController(e) {
|
|
2202
|
+
typeof this._inner.setController == "function" && this._inner.setController({
|
|
2203
|
+
invalidateItemCache: (t) => {
|
|
2204
|
+
let n = t.replace(/^\/+|\/+$/g, ""), r = this._pathToId.get(n);
|
|
2205
|
+
r && e.invalidateItemCache(r);
|
|
2206
|
+
},
|
|
2207
|
+
getCachedItem: (t) => {
|
|
2208
|
+
let n = t.replace(/^\/+|\/+$/g, ""), r = this._pathToId.get(n);
|
|
2209
|
+
if (r) {
|
|
2210
|
+
let t = e.getCachedItem(r);
|
|
2211
|
+
if (t) return {
|
|
2212
|
+
...t,
|
|
2213
|
+
id: this.pathForId(t.id, t.isFolder ?? !1),
|
|
2214
|
+
folderId: this.pathForId(t.folderId ?? "", t.isFolder ?? !1)
|
|
2215
|
+
};
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
});
|
|
2219
|
+
}
|
|
2220
|
+
clearCache(e) {
|
|
2221
|
+
if (typeof this._inner.clearCache == "function") return this._inner.clearCache(e);
|
|
2222
|
+
}
|
|
2223
|
+
findItemByPath(e) {
|
|
2224
|
+
if (typeof this._inner.findItemByPath != "function") return;
|
|
2225
|
+
let t = (e, t, n) => {
|
|
2226
|
+
if (!e) return;
|
|
2227
|
+
if (e.isFolder !== !0) return e;
|
|
2228
|
+
let r = v(v(n) === v(this.trashPath) ? this.trashPath : t), i = e.folderId != null && e.folderId !== "" ? v(e.folderId) : this.rootPath;
|
|
2229
|
+
return {
|
|
2230
|
+
...e,
|
|
2231
|
+
id: this._getOrGenerateId(r),
|
|
2232
|
+
name: e.name,
|
|
2233
|
+
folderId: i === v(this.rootPath) ? this.rootPath || "" : this._getOrGenerateId(i),
|
|
2234
|
+
isFolder: !0
|
|
2235
|
+
};
|
|
2236
|
+
}, n = y(e, this.trashPath, this.trashId);
|
|
2237
|
+
return (async () => {
|
|
2238
|
+
for (let r of n) {
|
|
2239
|
+
let n = await Promise.resolve(this._inner.findItemByPath(r)), i = t(n, r, e);
|
|
2240
|
+
if (i) return i;
|
|
2241
|
+
}
|
|
2242
|
+
})();
|
|
2243
|
+
}
|
|
2244
|
+
_getOrGenerateId(e) {
|
|
2245
|
+
if (e === this.rootPath) return "";
|
|
2246
|
+
let t = v(e);
|
|
2247
|
+
if (t === v(this.trashPath)) return this.trashId;
|
|
2248
|
+
if (this._pathToId.has(t)) return this._pathToId.get(t);
|
|
2249
|
+
let n = re();
|
|
2250
|
+
return this._pathToId.set(t, n), this._idToPath.set(n, t), n;
|
|
2251
|
+
}
|
|
2252
|
+
pathForId(t, n, r) {
|
|
2253
|
+
if (t === "" || t === void 0) return this.rootPath;
|
|
2254
|
+
if (t === this.trashId) return this.trashPath;
|
|
2255
|
+
let i = this._idToPath.get(t);
|
|
2256
|
+
if (!i) {
|
|
2257
|
+
if (r) return `unknown folder ${t}`;
|
|
2258
|
+
throw new e(`Path for id '${t}' not found in mapping`, "FileNotFound");
|
|
2259
|
+
}
|
|
2260
|
+
let a = 0;
|
|
2261
|
+
for (; a < this.rootPath.length && this.rootPath[a] === "/";) a++;
|
|
2262
|
+
if (a) {
|
|
2263
|
+
let e = 0;
|
|
2264
|
+
for (; e < i.length && i[e] === "/";) e++;
|
|
2265
|
+
let t = i.slice(e);
|
|
2266
|
+
i = "/".repeat(a) + t;
|
|
2267
|
+
}
|
|
2268
|
+
return n && this.ensureFolderTrailingSlash && !i.endsWith("/") && (i += "/"), i;
|
|
2269
|
+
}
|
|
2270
|
+
_updateIdMapping(e, t) {
|
|
2271
|
+
let n = t.replace(/^\/+|\/+$/g, ""), r = this._idToPath.get(e);
|
|
2272
|
+
r && this._pathToId.delete(r), this._idToPath.set(e, n), this._pathToId.set(n, e);
|
|
2273
|
+
}
|
|
2274
|
+
async getItems(e) {
|
|
2275
|
+
let t = e.folderId ? this.pathForId(e.folderId, !0) : this.rootPath, n = await this._inner.getItems({
|
|
2276
|
+
...e,
|
|
2277
|
+
folderId: t
|
|
2278
|
+
}), r = n.items.map((e) => {
|
|
2279
|
+
let t = this._getOrGenerateId(e.id), n = e.folderId ? this._getOrGenerateId(e.folderId) : this._getOrGenerateId(this.rootPath);
|
|
2280
|
+
return {
|
|
2281
|
+
...e,
|
|
2282
|
+
id: t,
|
|
2283
|
+
folderId: n
|
|
2284
|
+
};
|
|
2285
|
+
});
|
|
2286
|
+
return {
|
|
2287
|
+
...n,
|
|
2288
|
+
items: r
|
|
2289
|
+
};
|
|
2290
|
+
}
|
|
2291
|
+
async createFolder(e, t, n) {
|
|
2292
|
+
let r = t ? this.pathForId(t, !0) : this.rootPath, i = await this._inner.createFolder(e, r, n), a = this._getOrGenerateId(i.id), o = i.folderId ? this._getOrGenerateId(i.folderId) : this._getOrGenerateId(this.rootPath);
|
|
2293
|
+
return {
|
|
2294
|
+
...i,
|
|
2295
|
+
id: a,
|
|
2296
|
+
folderId: o
|
|
2297
|
+
};
|
|
2298
|
+
}
|
|
2299
|
+
async renameItem(t, n) {
|
|
2300
|
+
if (typeof this._inner.renameItem != "function") throw new e("Rename item is not supported by inner storage", "RenameNotAllowed");
|
|
2301
|
+
let r = this.pathForId(t.id, t.isFolder ?? !1), i = r, { ...a } = await this._inner.renameItem({
|
|
2302
|
+
...t,
|
|
2303
|
+
id: r,
|
|
2304
|
+
folderId: this.pathForId(t.folderId ?? "", !0)
|
|
2305
|
+
}, n);
|
|
2306
|
+
return this._updateIdMapping(t.id, a.id), t.isFolder && this.remapCachedFolderContents(t.id, i, a.id), a.folderId && (a = {
|
|
2307
|
+
...a,
|
|
2308
|
+
folderId: this._getOrGenerateId(a.folderId)
|
|
2309
|
+
}), {
|
|
2310
|
+
...a,
|
|
2311
|
+
id: this._getOrGenerateId(a.id)
|
|
2312
|
+
};
|
|
2313
|
+
}
|
|
2314
|
+
async deleteItem(t, n) {
|
|
2315
|
+
if (typeof this._inner.deleteItem != "function") throw new e("Delete item is not supported by inner storage", "DeleteNotAllowed");
|
|
2316
|
+
let r = this.pathForId(t.id, t.isFolder ?? !1);
|
|
2317
|
+
await this._inner.deleteItem({
|
|
2318
|
+
...t,
|
|
2319
|
+
id: r,
|
|
2320
|
+
folderId: this.pathForId(t.folderId ?? "", !0)
|
|
2321
|
+
}, n), this.recursivelyRemoveMappings(t.id, r);
|
|
2322
|
+
}
|
|
2323
|
+
async uploadFile(t) {
|
|
2324
|
+
if (typeof this._inner.uploadFile != "function") throw new e("Upload file is not supported by inner storage", "UnsupportedOperation");
|
|
2325
|
+
let n = t.folderId ? this.pathForId(t.folderId, !0) : this.rootPath, r = await this._inner.uploadFile({
|
|
2326
|
+
...t,
|
|
2327
|
+
folderId: n
|
|
2328
|
+
}), i = this._getOrGenerateId(r.id), a = r.folderId ? this._getOrGenerateId(r.folderId) : this._getOrGenerateId(this.rootPath);
|
|
2329
|
+
return {
|
|
2330
|
+
...r,
|
|
2331
|
+
id: i,
|
|
2332
|
+
folderId: a
|
|
2333
|
+
};
|
|
2334
|
+
}
|
|
2335
|
+
async uploadFiles(e) {
|
|
2336
|
+
let t = e.folderId, n = e.items?.map((e) => e.folderId) ?? [], r = e.folderId ? this.pathForId(e.folderId, !0) : this.rootPath, i = {
|
|
2337
|
+
...e,
|
|
2338
|
+
folderId: r,
|
|
2339
|
+
items: e.items?.map((e) => ({
|
|
2340
|
+
...e,
|
|
2341
|
+
folderId: e.folderId ? this.pathForId(e.folderId ?? "", !0) : r
|
|
2342
|
+
})) ?? []
|
|
2343
|
+
}, a = await this._inner.uploadFiles(i);
|
|
2344
|
+
return {
|
|
2345
|
+
...a,
|
|
2346
|
+
detailed: a.detailed?.map((e, r) => {
|
|
2347
|
+
if (!e?.data) return e;
|
|
2348
|
+
let i = e.data.id ? this._getOrGenerateId(e.data.id) : "", a = e.data.folderId ? this._getOrGenerateId(e.data.folderId) : n[r] ?? t ?? this._getOrGenerateId(this.rootPath);
|
|
2349
|
+
return {
|
|
2350
|
+
...e,
|
|
2351
|
+
data: {
|
|
2352
|
+
...e.data,
|
|
2353
|
+
id: i,
|
|
2354
|
+
folderId: a
|
|
2355
|
+
}
|
|
2356
|
+
};
|
|
2357
|
+
})
|
|
2358
|
+
};
|
|
2359
|
+
}
|
|
2360
|
+
async findFileByUrl(e, t) {
|
|
2361
|
+
let n = t ? this.pathForId(t, !0) : this.rootPath;
|
|
2362
|
+
if (typeof this._inner.findFileByUrl == "function") {
|
|
2363
|
+
let t = await this._inner.findFileByUrl(e, n);
|
|
2364
|
+
if (!t) return;
|
|
2365
|
+
let r = this._getOrGenerateId(t.id), i = t.folderId ? this._getOrGenerateId(t.folderId) : this._getOrGenerateId(this.rootPath);
|
|
2366
|
+
return {
|
|
2367
|
+
...t,
|
|
2368
|
+
id: r,
|
|
2369
|
+
folderId: i
|
|
2370
|
+
};
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
async uploadFileByUrl(e, t, n) {
|
|
2374
|
+
let r = t ? this.pathForId(t, !0) : this.rootPath, i = await this._inner.uploadFileByUrl(e, r, n), a = this._getOrGenerateId(i.id), o = i.folderId ? this._getOrGenerateId(i.folderId) : this._getOrGenerateId(this.rootPath);
|
|
2375
|
+
return {
|
|
2376
|
+
...i,
|
|
2377
|
+
id: a,
|
|
2378
|
+
folderId: o
|
|
2379
|
+
};
|
|
2380
|
+
}
|
|
2381
|
+
async moveItem(t, n) {
|
|
2382
|
+
if (typeof this._inner.moveItem != "function") throw new e("Move item is not supported by inner storage", "MoveNotAllowed");
|
|
2383
|
+
let r = this.pathForId(t.id, t.isFolder ?? !1), i = n ? this.pathForId(n, !0) : this.rootPath, a = await this._inner.moveItem({
|
|
2384
|
+
...t,
|
|
2385
|
+
id: r,
|
|
2386
|
+
folderId: this.pathForId(t.folderId ?? "", !0)
|
|
2387
|
+
}, i);
|
|
2388
|
+
this._updateIdMapping(t.id, a.id), t.isFolder && this.remapCachedFolderContents(t.id, r, a.id);
|
|
2389
|
+
let o = this._getOrGenerateId(a.id), s = a.folderId ? this._getOrGenerateId(a.folderId) : n;
|
|
2390
|
+
return {
|
|
2391
|
+
...a,
|
|
2392
|
+
id: o,
|
|
2393
|
+
folderId: s
|
|
2394
|
+
};
|
|
2395
|
+
}
|
|
2396
|
+
async moveItems(t, n) {
|
|
2397
|
+
if (typeof this._inner.moveItems != "function") throw new e("Move items is not supported by inner storage", "MoveNotAllowed");
|
|
2398
|
+
let r = n ? this.pathForId(n, !0) : this.rootPath, i = t.map((e) => ({
|
|
2399
|
+
...e,
|
|
2400
|
+
id: this.pathForId(e.id, e.isFolder ?? !1),
|
|
2401
|
+
folderId: e.folderId ? this.pathForId(e.folderId ?? "", !0) : this.rootPath
|
|
2402
|
+
})), a = await this._inner.moveItems(i, r), o = [];
|
|
2403
|
+
if (a.detailed && a.detailed.length > 0) {
|
|
2404
|
+
let e = /* @__PURE__ */ new Map();
|
|
2405
|
+
for (let n = 0; n < a.detailed.length; n++) {
|
|
2406
|
+
let r = a.detailed[n], i = r.requestId || (n < t.length ? t[n].id : void 0);
|
|
2407
|
+
i && e.set(i, r);
|
|
2408
|
+
}
|
|
2409
|
+
for (let r of t) {
|
|
2410
|
+
let i = e.get(r.id) || (a.detailed.length === t.length ? a.detailed[t.indexOf(r)] : void 0);
|
|
2411
|
+
if (i?.success && i.data) {
|
|
2412
|
+
if (this._updateIdMapping(r.id, i.data.id), r.isFolder) {
|
|
2413
|
+
let e = this.pathForId(r.id, r.isFolder ?? !1);
|
|
2414
|
+
this.remapCachedFolderContents(r.id, e, i.data.id);
|
|
2415
|
+
}
|
|
2416
|
+
o.push({
|
|
2417
|
+
requestId: r.id,
|
|
2418
|
+
success: !0,
|
|
2419
|
+
data: {
|
|
2420
|
+
...i.data,
|
|
2421
|
+
id: this._getOrGenerateId(i.data.id),
|
|
2422
|
+
folderId: i.data.folderId ? this._getOrGenerateId(i.data.folderId) : n || this._getOrGenerateId(this.rootPath)
|
|
2423
|
+
}
|
|
2424
|
+
});
|
|
2425
|
+
} else o.push({
|
|
2426
|
+
requestId: r.id,
|
|
2427
|
+
success: !1,
|
|
2428
|
+
error: i?.error || {
|
|
2429
|
+
message: "Move operation failed - no detailed result",
|
|
2430
|
+
code: "MoveNotAllowed"
|
|
2431
|
+
}
|
|
2432
|
+
});
|
|
2433
|
+
}
|
|
2434
|
+
} else for (let e of t) o.push({
|
|
2435
|
+
requestId: e.id,
|
|
2436
|
+
success: !1,
|
|
2437
|
+
error: {
|
|
2438
|
+
message: "Move operation failed - no detailed results",
|
|
2439
|
+
code: "MoveNotAllowed"
|
|
2440
|
+
}
|
|
2441
|
+
});
|
|
2442
|
+
return {
|
|
2443
|
+
success: a.success,
|
|
2444
|
+
detailed: o,
|
|
2445
|
+
error: a.error
|
|
2446
|
+
};
|
|
2447
|
+
}
|
|
2448
|
+
async copyItems(t, n) {
|
|
2449
|
+
if (typeof this._inner.copyItems != "function") throw new e("Copy items is not supported by inner storage", "CopyNotAllowed");
|
|
2450
|
+
let r = n ? this.pathForId(n, !0) : this.rootPath, i = t.map((e) => ({
|
|
2451
|
+
...e,
|
|
2452
|
+
id: this.pathForId(e.id, e.isFolder ?? !1),
|
|
2453
|
+
folderId: e.folderId ? this.pathForId(e.folderId ?? "", !0) : this.rootPath
|
|
2454
|
+
})), a = await this._inner.copyItems(i, r), o = [];
|
|
2455
|
+
if (a.detailed && a.detailed.length > 0) {
|
|
2456
|
+
let e = /* @__PURE__ */ new Map();
|
|
2457
|
+
for (let n = 0; n < a.detailed.length; n++) {
|
|
2458
|
+
let r = a.detailed[n], i = r.requestId || (n < t.length ? t[n].id : void 0);
|
|
2459
|
+
i && e.set(i, r);
|
|
2460
|
+
}
|
|
2461
|
+
for (let r of t) {
|
|
2462
|
+
let i = e.get(r.id) || (a.detailed.length === t.length ? a.detailed[t.indexOf(r)] : void 0);
|
|
2463
|
+
if (i?.success && i.data?.id) {
|
|
2464
|
+
let e = this._getOrGenerateId(i.data.id);
|
|
2465
|
+
o.push({
|
|
2466
|
+
requestId: r.id,
|
|
2467
|
+
success: !0,
|
|
2468
|
+
data: {
|
|
2469
|
+
...i.data,
|
|
2470
|
+
id: e,
|
|
2471
|
+
folderId: i.data.folderId ? this._getOrGenerateId(i.data.folderId) : n || this._getOrGenerateId(this.rootPath)
|
|
2472
|
+
}
|
|
2473
|
+
});
|
|
2474
|
+
} else {
|
|
2475
|
+
let e = i ? i.success ? i.data ? i.data.id ? {
|
|
2476
|
+
message: "Unknown copy error",
|
|
2477
|
+
code: "CopyNotAllowed"
|
|
2478
|
+
} : {
|
|
2479
|
+
message: "No ID in copied item data",
|
|
2480
|
+
code: "CopyNotAllowed"
|
|
2481
|
+
} : {
|
|
2482
|
+
message: "No data returned from copy operation",
|
|
2483
|
+
code: "CopyNotAllowed"
|
|
2484
|
+
} : i.error || {
|
|
2485
|
+
message: "Copy operation failed",
|
|
2486
|
+
code: "CopyNotAllowed"
|
|
2487
|
+
} : {
|
|
2488
|
+
message: "No detailed result from copy operation",
|
|
2489
|
+
code: "CopyNotAllowed"
|
|
2490
|
+
};
|
|
2491
|
+
o.push({
|
|
2492
|
+
requestId: r.id,
|
|
2493
|
+
success: !1,
|
|
2494
|
+
error: e
|
|
2495
|
+
});
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
} else for (let e of t) o.push({
|
|
2499
|
+
requestId: e.id,
|
|
2500
|
+
success: !1,
|
|
2501
|
+
error: {
|
|
2502
|
+
message: "No detailed results from copy operation",
|
|
2503
|
+
code: "CopyNotAllowed"
|
|
2504
|
+
}
|
|
2505
|
+
});
|
|
2506
|
+
let s = o.every((e) => e.success);
|
|
2507
|
+
return {
|
|
2508
|
+
success: s,
|
|
2509
|
+
detailed: o,
|
|
2510
|
+
error: s ? void 0 : a.error || {
|
|
2511
|
+
message: "Copy operation completed with errors",
|
|
2512
|
+
code: "CopyNotAllowed"
|
|
2513
|
+
}
|
|
2514
|
+
};
|
|
2515
|
+
}
|
|
2516
|
+
async deleteItems(t, n) {
|
|
2517
|
+
if (typeof this._inner.deleteItems != "function") throw new e("Delete items is not supported by inner storage", "DeleteNotAllowed");
|
|
2518
|
+
let r = t.map((e) => ({
|
|
2519
|
+
...e,
|
|
2520
|
+
id: this.pathForId(e.id, e.isFolder ?? !1),
|
|
2521
|
+
folderId: e.folderId ? this.pathForId(e.folderId ?? "", !0) : this.rootPath
|
|
2522
|
+
})), i = await this._inner.deleteItems(r, n), a = [];
|
|
2523
|
+
if (i.detailed && i.detailed.length > 0) {
|
|
2524
|
+
let e = /* @__PURE__ */ new Map();
|
|
2525
|
+
for (let n = 0; n < i.detailed.length; n++) {
|
|
2526
|
+
let r = i.detailed[n], a = r.requestId || (n < t.length ? t[n].id : void 0);
|
|
2527
|
+
a && e.set(a, r);
|
|
2528
|
+
}
|
|
2529
|
+
for (let r of t) {
|
|
2530
|
+
let o = e.get(r.id) || (i.detailed.length === t.length ? i.detailed[t.indexOf(r)] : void 0);
|
|
2531
|
+
if (o?.success) {
|
|
2532
|
+
let e = this.pathForId(r.id, r.isFolder ?? !1);
|
|
2533
|
+
if (n.permanent) this.recursivelyRemoveMappings(r.id, e);
|
|
2534
|
+
else if (this._updateIdMapping(r.id, this.trashPath + "/" + e + (r.isFolder ? "/" : "")), r.isFolder) {
|
|
2535
|
+
let t = this.pathForId(r.id, r.isFolder ?? !1);
|
|
2536
|
+
this.remapCachedFolderContents(r.id, t, this.trashPath + "/" + e + (r.isFolder ? "/" : ""));
|
|
2537
|
+
}
|
|
2538
|
+
a.push({
|
|
2539
|
+
requestId: r.id,
|
|
2540
|
+
success: !0
|
|
2541
|
+
});
|
|
2542
|
+
} else a.push({
|
|
2543
|
+
requestId: r.id,
|
|
2544
|
+
success: !1,
|
|
2545
|
+
error: o?.error || {
|
|
2546
|
+
message: "Delete operation failed",
|
|
2547
|
+
code: "DeleteNotAllowed"
|
|
2548
|
+
}
|
|
2549
|
+
});
|
|
2550
|
+
}
|
|
2551
|
+
} else for (let e of t) if (i.success) {
|
|
2552
|
+
let t = this.pathForId(e.id, e.isFolder ?? !1);
|
|
2553
|
+
if (n.permanent) this.recursivelyRemoveMappings(e.id, t);
|
|
2554
|
+
else if (this._updateIdMapping(e.id, this.trashPath + "/" + t + (e.isFolder ? "/" : "")), e.isFolder) {
|
|
2555
|
+
let n = this.pathForId(e.id, e.isFolder ?? !1);
|
|
2556
|
+
this.remapCachedFolderContents(e.id, n, this.trashPath + "/" + t + (e.isFolder ? "/" : ""));
|
|
2557
|
+
}
|
|
2558
|
+
a.push({
|
|
2559
|
+
requestId: e.id,
|
|
2560
|
+
success: !0
|
|
2561
|
+
});
|
|
2562
|
+
} else a.push({
|
|
2563
|
+
requestId: e.id,
|
|
2564
|
+
success: !1,
|
|
2565
|
+
error: i.error || {
|
|
2566
|
+
message: "Delete operation failed",
|
|
2567
|
+
code: "DeleteNotAllowed"
|
|
2568
|
+
}
|
|
2569
|
+
});
|
|
2570
|
+
let o = a.every((e) => e.success);
|
|
2571
|
+
return {
|
|
2572
|
+
success: o,
|
|
2573
|
+
detailed: a,
|
|
2574
|
+
error: o ? void 0 : i.error || {
|
|
2575
|
+
message: "Some items failed to delete",
|
|
2576
|
+
code: "DeleteNotAllowed"
|
|
2577
|
+
}
|
|
2578
|
+
};
|
|
2579
|
+
}
|
|
2580
|
+
remapCachedFolderContents(e, t, n) {
|
|
2581
|
+
let r = t.replace(/\/+$/, ""), i = n.replace(/\/+$/, ""), a = [];
|
|
2582
|
+
for (let [e, t] of this._idToPath.entries()) {
|
|
2583
|
+
let n = t.replace(/\/+$/, "");
|
|
2584
|
+
n !== r && n.startsWith(r + "/") && a.push({
|
|
2585
|
+
id: e,
|
|
2586
|
+
oldPath: n
|
|
2587
|
+
});
|
|
2588
|
+
}
|
|
2589
|
+
for (let { id: e, oldPath: t } of a) {
|
|
2590
|
+
let n = i + t.substring(r.length);
|
|
2591
|
+
this._updateIdMapping(e, n);
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
recursivelyRemoveMappings(e, t) {
|
|
2595
|
+
let n = t.replace(/\/+$/, ""), r = [], i = [];
|
|
2596
|
+
for (let [e, t] of this._idToPath.entries()) {
|
|
2597
|
+
let a = t.replace(/\/+$/, "");
|
|
2598
|
+
(a === n || a.startsWith(n + "/")) && (r.push(e), i.push(a));
|
|
2599
|
+
}
|
|
2600
|
+
for (let e = 0; e < r.length; e++) this._idToPath.delete(r[e]), this._pathToId.delete(i[e]);
|
|
2601
|
+
}
|
|
2602
|
+
async copyItem(t, n) {
|
|
2603
|
+
if (typeof this._inner.copyItem != "function") throw new e("Copy item is not supported by inner storage", "CopyNotAllowed");
|
|
2604
|
+
let r = this.pathForId(t.id, t.isFolder ?? !1), i = n ? this.pathForId(n, !0) : this.rootPath, a = await this._inner.copyItem({
|
|
2605
|
+
...t,
|
|
2606
|
+
id: r,
|
|
2607
|
+
folderId: this.pathForId(t.folderId ?? "", !0)
|
|
2608
|
+
}, i), o = this._getOrGenerateId(a.id), s = a.folderId ? this._getOrGenerateId(a.folderId) : n ?? "";
|
|
2609
|
+
return {
|
|
2610
|
+
...a,
|
|
2611
|
+
id: o,
|
|
2612
|
+
folderId: s
|
|
2613
|
+
};
|
|
2614
|
+
}
|
|
2615
|
+
async updateFile(t, n) {
|
|
2616
|
+
if (typeof this._inner.updateFile != "function") throw new e("Update file is not supported by inner storage", "UnsupportedOperation");
|
|
2617
|
+
let r = this.pathForId(t.id, !1), { ...i } = await this._inner.updateFile({
|
|
2618
|
+
...t,
|
|
2619
|
+
id: r,
|
|
2620
|
+
folderId: this.pathForId(t.folderId ?? "", !0)
|
|
2621
|
+
}, n);
|
|
2622
|
+
return this._updateIdMapping(t.id, i.id), i.folderId && (i = {
|
|
2623
|
+
...i,
|
|
2624
|
+
folderId: this._getOrGenerateId(i.folderId)
|
|
2625
|
+
}), {
|
|
2626
|
+
...i,
|
|
2627
|
+
id: this._getOrGenerateId(i.id)
|
|
2628
|
+
};
|
|
2629
|
+
}
|
|
2630
|
+
async getFileData(t, n) {
|
|
2631
|
+
let r = this.pathForId(t.id, !1);
|
|
2632
|
+
if (typeof this._inner.getFileData == "function") return this._inner.getFileData({
|
|
2633
|
+
...t,
|
|
2634
|
+
id: r,
|
|
2635
|
+
folderId: this.pathForId(t.folderId ?? "", !0)
|
|
2636
|
+
}, n);
|
|
2637
|
+
let i = t.url || (typeof this.getUrl == "function" ? await this.getUrl(t) : void 0);
|
|
2638
|
+
if (!i) throw new e("Cannot get file data: no url and no inner.getFileData", "FileReadError");
|
|
2639
|
+
return fetch(i, n?.forceReload ? { cache: "no-store" } : void 0).then((e) => e.blob());
|
|
2640
|
+
}
|
|
2641
|
+
async cleanTrash() {
|
|
2642
|
+
if (typeof this._inner.cleanTrash != "function") throw new e("Clean trash is not supported by inner storage", "UnsupportedOperation");
|
|
2643
|
+
return await this._inner.cleanTrash();
|
|
2644
|
+
}
|
|
2645
|
+
};
|
|
2646
|
+
//#endregion
|
|
2647
|
+
//#region packages/file-manager/src/utils/directResourceFetchError.ts
|
|
2648
|
+
function se(e) {
|
|
2649
|
+
return typeof e != "object" || !e ? !1 : "name" in e && e.name === "DirectResourceFetchError" ? !("final" in e) || e.final !== !1 : "final" in e && e.final === !0;
|
|
2650
|
+
}
|
|
2651
|
+
//#endregion
|
|
2652
|
+
//#region packages/file-manager/src/utils/remoteFileFetchPipeline.ts
|
|
2653
|
+
function $(t) {
|
|
2654
|
+
if (se(t) || t instanceof e) throw t;
|
|
2655
|
+
}
|
|
2656
|
+
async function ce(e, t, n, r, i) {
|
|
2657
|
+
let { fetchWithProxy: a, handleFileProxy: o, handleProxyUrl: s } = t, c = {
|
|
2658
|
+
mode: "cors",
|
|
2659
|
+
...i?.fetchInit
|
|
2660
|
+
}, l;
|
|
2661
|
+
if (o) try {
|
|
2662
|
+
let t = await Promise.resolve(o(e));
|
|
2663
|
+
if (t) return r(t);
|
|
2664
|
+
} catch (e) {
|
|
2665
|
+
$(e), l = e, console.warn("handleFileProxy failed, falling back to next strategy", e);
|
|
2666
|
+
}
|
|
2667
|
+
if (s) try {
|
|
2668
|
+
let t = await Promise.resolve(s(e));
|
|
2669
|
+
if (t && t !== e) return r(await n(t));
|
|
2670
|
+
} catch (e) {
|
|
2671
|
+
$(e), l = e, console.warn("handleProxyUrl fetch failed, falling back to next strategy", e);
|
|
2672
|
+
}
|
|
2673
|
+
if (a) try {
|
|
2674
|
+
let t = await Promise.resolve(a(e, c, { intent: "downloadBlob" }));
|
|
2675
|
+
if (!t.ok) throw Error(`HTTP ${t.status}`);
|
|
2676
|
+
return r(await t.blob());
|
|
2677
|
+
} catch (e) {
|
|
2678
|
+
$(e), l = e, console.warn("fetchWithProxy failed", e);
|
|
2679
|
+
}
|
|
2680
|
+
if (!a) try {
|
|
2681
|
+
return r(await n(e));
|
|
2682
|
+
} catch (e) {
|
|
2683
|
+
$(e), l = e;
|
|
2684
|
+
}
|
|
2685
|
+
throw l instanceof Error ? l : /* @__PURE__ */ Error("Failed to download file from the URL");
|
|
2686
|
+
}
|
|
2687
|
+
//#endregion
|
|
2688
|
+
export { S as DEFAULT_FILE_MANAGER_CACHE_TTL_MS, J as DataSourceProxyBase, o as FailedRequestCache, e as FileManagerApiError, s as MutationRegistry, oe as PathAwareStorageAdapter, _ as TRASH_FOLDER_ID, P as TreeCache, N as ViewCacheManager, i as buildAssetsPath, l as compareFileSystemItems, b as createSystemFolderByPathResolver, m as defaultChildrenViewFilterMatch, p as defaultFileSystemItemComparator, h as defaultHasSortValue, k as defaultIsFolderNotFoundError, ce as fetchRemoteImageBlobByUrl, r as getAssetsBase, y as getTrashFolderLookupCandidates, d as hasComparableSortValue, n as joinUrls, t as mapHttpStatusToErrorCode, f as matchesChildrenViewFilter, v as normalizeSystemFolderPath, c as resolveSortParams, g as resolveViewStrategyOptions };
|
|
2689
|
+
|
|
2690
|
+
//# sourceMappingURL=core.esm.js.map
|