@scaleflex/dam-core 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/files.service.d.ts +12 -1
- package/dist/api/files.service.d.ts.map +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +377 -361
- package/dist/index.js.map +1 -1
- package/dist/store/browse-store.d.ts +4 -2
- package/dist/store/browse-store.d.ts.map +1 -1
- package/dist/types/api.types.d.ts +4 -1
- package/dist/types/api.types.d.ts.map +1 -1
- package/dist/types/asset.types.d.ts +2 -0
- package/dist/types/asset.types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
const N = "https://api.filerobot.com";
|
|
2
|
-
function B(
|
|
3
|
-
return
|
|
2
|
+
function B(t) {
|
|
3
|
+
return t === 404 || t === 408 || t === 429 || t >= 500;
|
|
4
4
|
}
|
|
5
|
-
const G = (
|
|
6
|
-
function M(
|
|
7
|
-
return `${(e || N).replace(/\/+$/, "")}/${
|
|
5
|
+
const G = (t) => new Promise((e) => setTimeout(e, t));
|
|
6
|
+
function M(t, e) {
|
|
7
|
+
return `${(e || N).replace(/\/+$/, "")}/${t}`;
|
|
8
8
|
}
|
|
9
|
-
async function W(
|
|
10
|
-
const r = `${M(
|
|
9
|
+
async function W(t, e, s, i = {}) {
|
|
10
|
+
const r = `${M(t, s)}/key/${encodeURIComponent(e)}`, o = i.retries ?? 2, l = i.retryDelayMs ?? 400;
|
|
11
11
|
let a = new Error("SASS key exchange failed");
|
|
12
12
|
for (let c = 0; c <= o; c++) {
|
|
13
13
|
c > 0 && await G(l * c);
|
|
@@ -34,71 +34,71 @@ async function W(s, e, t, i = {}) {
|
|
|
34
34
|
}
|
|
35
35
|
throw a;
|
|
36
36
|
}
|
|
37
|
-
function T(
|
|
38
|
-
const
|
|
39
|
-
switch (
|
|
37
|
+
function T(t, e) {
|
|
38
|
+
const s = {};
|
|
39
|
+
switch (t.mode) {
|
|
40
40
|
case "security-template":
|
|
41
41
|
if (!e)
|
|
42
42
|
throw new Error(
|
|
43
43
|
"[dam-core] Cannot build auth headers for security-template mode: SASS key exchange has not been performed. Call resolveAuth() first, or use sass-key mode."
|
|
44
44
|
);
|
|
45
|
-
|
|
45
|
+
s["X-Filerobot-Key"] = e;
|
|
46
46
|
break;
|
|
47
47
|
case "sass-key":
|
|
48
|
-
|
|
48
|
+
s["X-Filerobot-Key"] = t.sassKey;
|
|
49
49
|
break;
|
|
50
50
|
}
|
|
51
|
-
return
|
|
51
|
+
return t.airboxPuid && (s["X-Filerobot-Airbox-Puid"] = t.airboxPuid), s;
|
|
52
52
|
}
|
|
53
|
-
function X(
|
|
54
|
-
return
|
|
53
|
+
function X(t) {
|
|
54
|
+
return t.mode === "securityTemplate" || t.mode === "sassKey";
|
|
55
55
|
}
|
|
56
|
-
function V(
|
|
57
|
-
return X(
|
|
56
|
+
function V(t) {
|
|
57
|
+
return X(t) ? t.mode === "securityTemplate" ? {
|
|
58
58
|
mode: "security-template",
|
|
59
|
-
container:
|
|
60
|
-
securityTemplateId:
|
|
61
|
-
airboxPuid:
|
|
59
|
+
container: t.projectToken,
|
|
60
|
+
securityTemplateId: t.securityTemplateKey,
|
|
61
|
+
airboxPuid: t.airboxPuid
|
|
62
62
|
} : {
|
|
63
63
|
mode: "sass-key",
|
|
64
|
-
container:
|
|
65
|
-
sassKey:
|
|
66
|
-
airboxPuid:
|
|
67
|
-
} :
|
|
64
|
+
container: t.projectToken,
|
|
65
|
+
sassKey: t.sassKey,
|
|
66
|
+
airboxPuid: t.airboxPuid
|
|
67
|
+
} : t;
|
|
68
68
|
}
|
|
69
|
-
async function I(
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
72
|
-
const r = await W(
|
|
73
|
-
return { apiBase: i, headers: T(
|
|
69
|
+
async function I(t, e) {
|
|
70
|
+
const s = V(t), i = M(s.container, e);
|
|
71
|
+
if (s.mode === "security-template") {
|
|
72
|
+
const r = await W(s.container, s.securityTemplateId, e);
|
|
73
|
+
return { apiBase: i, headers: T(s, r), sassKey: r };
|
|
74
74
|
}
|
|
75
|
-
return { apiBase: i, headers: T(
|
|
75
|
+
return { apiBase: i, headers: T(s) };
|
|
76
76
|
}
|
|
77
77
|
const H = 3e4;
|
|
78
|
-
class
|
|
79
|
-
constructor(e,
|
|
80
|
-
this.baseUrl = `${e.apiBase}/v5`, this.headers = e.headers, this.auth =
|
|
78
|
+
class R {
|
|
79
|
+
constructor(e, s, i) {
|
|
80
|
+
this.baseUrl = `${e.apiBase}/v5`, this.headers = e.headers, this.auth = s, this.apiDomain = i;
|
|
81
81
|
}
|
|
82
82
|
/** Resolve an AuthConfig (performing key exchange if needed) and build a client. */
|
|
83
|
-
static async create(e,
|
|
84
|
-
const i = await I(e,
|
|
85
|
-
return new
|
|
83
|
+
static async create(e, s) {
|
|
84
|
+
const i = await I(e, s);
|
|
85
|
+
return new R(i, e, s);
|
|
86
86
|
}
|
|
87
|
-
get(e,
|
|
87
|
+
get(e, s) {
|
|
88
88
|
const i = new URL(`${this.baseUrl}${e}`);
|
|
89
|
-
if (
|
|
90
|
-
for (const [r, o] of Object.entries(
|
|
89
|
+
if (s)
|
|
90
|
+
for (const [r, o] of Object.entries(s))
|
|
91
91
|
o != null && i.searchParams.set(r, Array.isArray(o) ? o.join(",") : String(o));
|
|
92
92
|
return this.send(i, { method: "GET" });
|
|
93
93
|
}
|
|
94
|
-
post(e,
|
|
95
|
-
return this.sendJson("POST", e,
|
|
94
|
+
post(e, s) {
|
|
95
|
+
return this.sendJson("POST", e, s);
|
|
96
96
|
}
|
|
97
|
-
put(e,
|
|
98
|
-
return this.sendJson("PUT", e,
|
|
97
|
+
put(e, s) {
|
|
98
|
+
return this.sendJson("PUT", e, s);
|
|
99
99
|
}
|
|
100
|
-
delete(e,
|
|
101
|
-
return this.sendJson("DELETE", e,
|
|
100
|
+
delete(e, s) {
|
|
101
|
+
return this.sendJson("DELETE", e, s);
|
|
102
102
|
}
|
|
103
103
|
/**
|
|
104
104
|
* Absolute REST URL (incl. the `/v5` base) for a path — for building direct
|
|
@@ -111,25 +111,25 @@ class O {
|
|
|
111
111
|
get authKey() {
|
|
112
112
|
return this.headers["X-Filerobot-Key"];
|
|
113
113
|
}
|
|
114
|
-
sendJson(e,
|
|
115
|
-
return this.send(new URL(`${this.baseUrl}${
|
|
114
|
+
sendJson(e, s, i) {
|
|
115
|
+
return this.send(new URL(`${this.baseUrl}${s}`), {
|
|
116
116
|
method: e,
|
|
117
117
|
headers: { "Content-Type": "application/json" },
|
|
118
118
|
body: i === void 0 ? void 0 : JSON.stringify(i)
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
|
-
async send(e,
|
|
121
|
+
async send(e, s, i = !1) {
|
|
122
122
|
var l;
|
|
123
123
|
const r = new AbortController(), o = setTimeout(() => r.abort(), H);
|
|
124
124
|
try {
|
|
125
125
|
const a = await fetch(e.toString(), {
|
|
126
|
-
...
|
|
127
|
-
headers: { ...this.headers, ...
|
|
126
|
+
...s,
|
|
127
|
+
headers: { ...this.headers, ...s.headers },
|
|
128
128
|
signal: r.signal
|
|
129
129
|
});
|
|
130
130
|
if (clearTimeout(o), a.status === 401 && !i && ((l = this.auth) == null ? void 0 : l.mode) === "security-template") {
|
|
131
131
|
const h = await I(this.auth, this.apiDomain);
|
|
132
|
-
return this.headers = h.headers, this.send(e,
|
|
132
|
+
return this.headers = h.headers, this.send(e, s, !0);
|
|
133
133
|
}
|
|
134
134
|
if (!a.ok) {
|
|
135
135
|
let h = `API error: ${a.status} ${a.statusText}`;
|
|
@@ -152,50 +152,50 @@ class O {
|
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
|
-
function J(
|
|
156
|
-
const e =
|
|
155
|
+
function J(t) {
|
|
156
|
+
const e = t.path ?? t.name, s = e.replace(/\/[^/]*$/, "") || "/";
|
|
157
157
|
return {
|
|
158
|
-
uuid:
|
|
159
|
-
name:
|
|
158
|
+
uuid: t.uuid,
|
|
159
|
+
name: t.name.split("/").pop() || t.name,
|
|
160
160
|
path: e,
|
|
161
|
-
parentPath:
|
|
162
|
-
createdAt:
|
|
163
|
-
modifiedAt:
|
|
161
|
+
parentPath: s,
|
|
162
|
+
createdAt: t.created_at,
|
|
163
|
+
modifiedAt: t.modified_at
|
|
164
164
|
};
|
|
165
165
|
}
|
|
166
|
-
async function b(
|
|
167
|
-
const
|
|
168
|
-
return ((await
|
|
166
|
+
async function b(t, e = {}) {
|
|
167
|
+
const s = e.sortBy ?? "name", i = e.sortDirection ?? "asc";
|
|
168
|
+
return ((await t.get("/folders", {
|
|
169
169
|
folder: e.folderPath ?? "/",
|
|
170
170
|
recursive: e.recursive ?? 0,
|
|
171
171
|
limit: e.limit ?? 1e3,
|
|
172
172
|
offset: e.offset ?? 0,
|
|
173
173
|
q: e.q,
|
|
174
|
-
sort: `${
|
|
174
|
+
sort: `${s}:${i}`
|
|
175
175
|
})).folders ?? []).map(J);
|
|
176
176
|
}
|
|
177
|
-
async function K(
|
|
178
|
-
const i =
|
|
177
|
+
async function K(t, e, s) {
|
|
178
|
+
const i = s.replace(/\/+$/, ""), r = i ? `${i}/${e}` : `/${e}`, o = await t.post("/folders", { name: r });
|
|
179
179
|
if (o.status !== "success") throw new Error(o.msg || "Failed to create folder");
|
|
180
180
|
}
|
|
181
|
-
async function Y(
|
|
182
|
-
const i = await
|
|
183
|
-
name:
|
|
181
|
+
async function Y(t, e, s) {
|
|
182
|
+
const i = await t.put(`/folder/${encodeURIComponent(e)}/name`, {
|
|
183
|
+
name: s
|
|
184
184
|
});
|
|
185
185
|
if ((i == null ? void 0 : i.status) === "error") throw new Error(i.msg || "Failed to rename folder");
|
|
186
186
|
}
|
|
187
|
-
async function Z(
|
|
188
|
-
const
|
|
189
|
-
if ((
|
|
187
|
+
async function Z(t, e) {
|
|
188
|
+
const s = await t.delete("/folders", { folders_uuids: e });
|
|
189
|
+
if ((s == null ? void 0 : s.status) === "error") throw new Error(s.msg || "Failed to delete folders");
|
|
190
190
|
}
|
|
191
|
-
async function Q(
|
|
192
|
-
const i = await
|
|
191
|
+
async function Q(t, e, s) {
|
|
192
|
+
const i = await t.post("/folders", {
|
|
193
193
|
folders_uuids: e,
|
|
194
|
-
new_folder_name:
|
|
194
|
+
new_folder_name: s
|
|
195
195
|
});
|
|
196
196
|
if ((i == null ? void 0 : i.status) === "error") throw new Error(i.msg || "Failed to move folders");
|
|
197
197
|
}
|
|
198
|
-
const
|
|
198
|
+
const O = {
|
|
199
199
|
small: [null, 1048576],
|
|
200
200
|
// < 1 MB
|
|
201
201
|
medium: [1048576, 10485760],
|
|
@@ -210,67 +210,72 @@ const R = {
|
|
|
210
210
|
month: 30,
|
|
211
211
|
year: 365
|
|
212
212
|
};
|
|
213
|
-
function y(
|
|
214
|
-
const
|
|
215
|
-
return
|
|
213
|
+
function y(t, e) {
|
|
214
|
+
const s = new Date(e);
|
|
215
|
+
return s.setUTCHours(0, 0, 0, 0), s.setUTCDate(s.getUTCDate() - ee[t]), s;
|
|
216
216
|
}
|
|
217
|
-
const L = ["cdn_permalink"], F = {}, m = (
|
|
217
|
+
const L = ["cdn_permalink"], F = {}, m = (t, e) => e.split(" ").forEach((s) => F[s] = t);
|
|
218
218
|
m("image", "jpg jpeg png gif webp svg avif bmp tif tiff heic ico");
|
|
219
219
|
m("video", "mp4 webm mov m4v avi mkv ogv");
|
|
220
220
|
m("audio", "mp3 wav ogg oga m4a aac flac");
|
|
221
221
|
m("document", "pdf doc docx xls xlsx ppt pptx txt csv rtf md");
|
|
222
222
|
m("model", "glb gltf obj fbx stl usdz ply 3ds dae");
|
|
223
|
-
function te(
|
|
224
|
-
const e = (
|
|
223
|
+
function te(t) {
|
|
224
|
+
const e = (t.name.split(".").pop() || "").toLowerCase();
|
|
225
225
|
if (F[e] === "model") return "model";
|
|
226
|
-
const
|
|
227
|
-
return
|
|
226
|
+
const s = (t.file_type || t.type || "").toLowerCase();
|
|
227
|
+
return s.startsWith("image") ? "image" : s.startsWith("video") ? "video" : s.startsWith("audio") ? "audio" : s.includes("pdf") || s.includes("document") || s.includes("text") ? "document" : F[e] ?? "other";
|
|
228
228
|
}
|
|
229
|
-
function z(
|
|
230
|
-
var e,
|
|
229
|
+
function z(t) {
|
|
230
|
+
var e, s, i, r, o, l, a;
|
|
231
231
|
return {
|
|
232
|
-
uuid:
|
|
233
|
-
name:
|
|
234
|
-
folder:
|
|
235
|
-
type: te(
|
|
236
|
-
fileType:
|
|
237
|
-
cdnUrl:
|
|
238
|
-
thumbnailUrl: ((e =
|
|
232
|
+
uuid: t.uuid,
|
|
233
|
+
name: t.name,
|
|
234
|
+
folder: t.folder ?? "/",
|
|
235
|
+
type: te(t),
|
|
236
|
+
fileType: t.file_type ?? t.type,
|
|
237
|
+
cdnUrl: t.cdn_permalink ?? t.cdn_url,
|
|
238
|
+
thumbnailUrl: ((e = t.info) == null ? void 0 : e.video_thumbnail) ?? ((s = t.info) == null ? void 0 : s.image_thumbnail) ?? ((i = t.info) == null ? void 0 : i.thumbnail) ?? ((r = t.info) == null ? void 0 : r.preview),
|
|
239
239
|
// Live API returns `size: { bytes, pretty }`; tolerate a plain number too.
|
|
240
|
-
size: typeof
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
240
|
+
size: typeof t.size == "object" ? (o = t.size) == null ? void 0 : o.bytes : t.size,
|
|
241
|
+
duration: ((l = t.info) == null ? void 0 : l.video_duration) ?? ((a = t.info) == null ? void 0 : a.duration),
|
|
242
|
+
width: t.width,
|
|
243
|
+
height: t.height,
|
|
244
|
+
createdAt: t.created_at,
|
|
245
|
+
modifiedAt: t.modified_at
|
|
245
246
|
};
|
|
246
247
|
}
|
|
247
|
-
function se(
|
|
248
|
+
function se(t) {
|
|
248
249
|
var l;
|
|
249
|
-
const e =
|
|
250
|
-
if (
|
|
251
|
-
const [a, c] =
|
|
250
|
+
const e = t.fields ?? L, s = t.sortBy ?? "created_at", i = t.sortDirection ?? "desc", r = [];
|
|
251
|
+
if (t.search && r.push(t.search), t.q && r.push(t.q), (l = t.types) != null && l.length && r.push(`type:${t.types.map((a) => `"${a}"`).join(",")}`), t.sizeBucket) {
|
|
252
|
+
const [a, c] = O[t.sizeBucket];
|
|
252
253
|
r.push(`size:"${a ?? ""}..${c ?? ""}"`);
|
|
253
254
|
}
|
|
255
|
+
if (t.durationRange) {
|
|
256
|
+
const { min: a, max: c } = t.durationRange;
|
|
257
|
+
(a != null || c != null) && r.push(`video_duration:"${a ?? ""}..${c ?? ""}"`);
|
|
258
|
+
}
|
|
254
259
|
const o = Date.now();
|
|
255
|
-
return
|
|
256
|
-
offset:
|
|
257
|
-
limit:
|
|
260
|
+
return t.createdWithin && r.push(`created>"${y(t.createdWithin, o).toISOString()}"`), t.updatedWithin && r.push(`updated>"${y(t.updatedWithin, o).toISOString()}"`), {
|
|
261
|
+
offset: t.offset ?? 0,
|
|
262
|
+
limit: t.limit ?? 100,
|
|
258
263
|
format: "json,regvar:api,select:internal",
|
|
259
264
|
preview: 2301,
|
|
260
265
|
// Filerobot preview-size preset for thumbnails
|
|
261
|
-
recursive:
|
|
266
|
+
recursive: t.recursive ?? 1,
|
|
262
267
|
fields: e.length ? e : void 0,
|
|
263
|
-
sort: `${
|
|
264
|
-
folder:
|
|
268
|
+
sort: `${s}:${i}`,
|
|
269
|
+
folder: t.folder,
|
|
265
270
|
q: r.length ? r.join(" ") : void 0
|
|
266
271
|
};
|
|
267
272
|
}
|
|
268
|
-
async function w(
|
|
269
|
-
const
|
|
273
|
+
async function w(t, e = {}) {
|
|
274
|
+
const s = se(e), i = await t.get("/files", s), r = (i.files ?? []).map(z), o = typeof i.total == "number" ? i.total : i.count ?? r.length;
|
|
270
275
|
return { assets: r, total: o };
|
|
271
276
|
}
|
|
272
|
-
async function $e(
|
|
273
|
-
return (await w(
|
|
277
|
+
async function $e(t, e = {}) {
|
|
278
|
+
return (await w(t, e)).assets;
|
|
274
279
|
}
|
|
275
280
|
const ie = {
|
|
276
281
|
image: "image",
|
|
@@ -283,17 +288,21 @@ const ie = {
|
|
|
283
288
|
font: "other",
|
|
284
289
|
other: "other"
|
|
285
290
|
};
|
|
286
|
-
function re(
|
|
291
|
+
function re(t, e, s) {
|
|
287
292
|
var i;
|
|
288
|
-
if ((i = e.types) != null && i.length && !e.types.includes(ie[
|
|
293
|
+
if ((i = e.types) != null && i.length && !e.types.includes(ie[t.type])) return !1;
|
|
289
294
|
if (e.sizeBucket) {
|
|
290
|
-
const [r, o] =
|
|
291
|
-
if (
|
|
295
|
+
const [r, o] = O[e.sizeBucket];
|
|
296
|
+
if (t.size == null || r != null && t.size < r || o != null && t.size >= o) return !1;
|
|
297
|
+
}
|
|
298
|
+
if (e.durationRange) {
|
|
299
|
+
const { min: r, max: o } = e.durationRange;
|
|
300
|
+
if (t.duration == null || r != null && t.duration < r || o != null && t.duration > o) return !1;
|
|
292
301
|
}
|
|
293
|
-
return !(e.createdWithin && !((
|
|
302
|
+
return !(e.createdWithin && !((t.createdAt ? Date.parse(t.createdAt) : NaN) >= y(e.createdWithin, s).getTime()) || e.updatedWithin && !((t.modifiedAt ? Date.parse(t.modifiedAt) : NaN) >= y(e.updatedWithin, s).getTime()));
|
|
294
303
|
}
|
|
295
|
-
function ne(
|
|
296
|
-
const i =
|
|
304
|
+
function ne(t, e, s) {
|
|
305
|
+
const i = s === "asc" ? 1 : -1, r = (o) => {
|
|
297
306
|
var l;
|
|
298
307
|
switch (e) {
|
|
299
308
|
case "name":
|
|
@@ -308,19 +317,19 @@ function ne(s, e, t) {
|
|
|
308
317
|
return o.createdAt ? Date.parse(o.createdAt) : 0;
|
|
309
318
|
}
|
|
310
319
|
};
|
|
311
|
-
return [...
|
|
320
|
+
return [...t].sort((o, l) => {
|
|
312
321
|
const a = r(o), c = r(l);
|
|
313
322
|
return a < c ? -i : a > c ? i : 0;
|
|
314
323
|
});
|
|
315
324
|
}
|
|
316
|
-
async function oe(
|
|
317
|
-
const i =
|
|
325
|
+
async function oe(t, e, s = {}) {
|
|
326
|
+
const i = s.fields ?? L, r = new Array(e.length);
|
|
318
327
|
let o = 0;
|
|
319
328
|
const l = async () => {
|
|
320
329
|
for (; o < e.length; ) {
|
|
321
330
|
const c = o++;
|
|
322
331
|
try {
|
|
323
|
-
const f = await
|
|
332
|
+
const f = await t.get(`/file/${encodeURIComponent(e[c])}`, {
|
|
324
333
|
format: "json,regvar:api,select:internal",
|
|
325
334
|
preview: 2301,
|
|
326
335
|
fields: i.length ? i : void 0
|
|
@@ -329,152 +338,152 @@ async function oe(s, e, t = {}) {
|
|
|
329
338
|
} catch {
|
|
330
339
|
}
|
|
331
340
|
}
|
|
332
|
-
}, a = Math.min(
|
|
341
|
+
}, a = Math.min(s.concurrency ?? 8, e.length);
|
|
333
342
|
return await Promise.all(Array.from({ length: a }, l)), r.filter((c) => c !== void 0);
|
|
334
343
|
}
|
|
335
|
-
async function ae(
|
|
336
|
-
const i = await
|
|
337
|
-
name:
|
|
344
|
+
async function ae(t, e, s) {
|
|
345
|
+
const i = await t.put(`/file/${encodeURIComponent(e)}/name`, {
|
|
346
|
+
name: s
|
|
338
347
|
});
|
|
339
348
|
if ((i == null ? void 0 : i.status) === "error") throw new Error(i.msg || "Failed to rename file");
|
|
340
349
|
}
|
|
341
|
-
async function ce(
|
|
342
|
-
const
|
|
343
|
-
if ((
|
|
350
|
+
async function ce(t, e) {
|
|
351
|
+
const s = await t.delete("/files", { files_uuids: e });
|
|
352
|
+
if ((s == null ? void 0 : s.status) === "error") throw new Error(s.msg || "Failed to delete files");
|
|
344
353
|
}
|
|
345
|
-
async function le(
|
|
346
|
-
const i = await
|
|
354
|
+
async function le(t, e, s) {
|
|
355
|
+
const i = await t.post("/files", {
|
|
347
356
|
files_uuids: e,
|
|
348
|
-
new_folder_name:
|
|
357
|
+
new_folder_name: s
|
|
349
358
|
});
|
|
350
359
|
if ((i == null ? void 0 : i.status) === "error") throw new Error(i.msg || "Failed to move files");
|
|
351
360
|
}
|
|
352
|
-
async function de(
|
|
353
|
-
return (await
|
|
361
|
+
async function de(t) {
|
|
362
|
+
return (await t.get("/labels")).labels ?? [];
|
|
354
363
|
}
|
|
355
|
-
function he(
|
|
356
|
-
if (
|
|
357
|
-
return `labels:${
|
|
364
|
+
function he(t) {
|
|
365
|
+
if (t.sid)
|
|
366
|
+
return `labels:${t.sid.replace(/^#/, "")}`;
|
|
358
367
|
}
|
|
359
|
-
function $(
|
|
368
|
+
function $(t, e) {
|
|
360
369
|
try {
|
|
361
|
-
const
|
|
362
|
-
return
|
|
370
|
+
const s = new URL(t);
|
|
371
|
+
return s.searchParams.set("p", e), s.toString();
|
|
363
372
|
} catch {
|
|
364
|
-
return
|
|
373
|
+
return t;
|
|
365
374
|
}
|
|
366
375
|
}
|
|
367
|
-
function x(
|
|
368
|
-
var e,
|
|
376
|
+
function x(t) {
|
|
377
|
+
var e, s, i, r, o;
|
|
369
378
|
return {
|
|
370
|
-
uuid:
|
|
371
|
-
name:
|
|
372
|
-
url:
|
|
373
|
-
previewUrl:
|
|
374
|
-
width: (e =
|
|
375
|
-
height: (
|
|
376
|
-
size: (i =
|
|
377
|
-
format: (r =
|
|
379
|
+
uuid: t.uuid,
|
|
380
|
+
name: t.name,
|
|
381
|
+
url: t.url,
|
|
382
|
+
previewUrl: t.preview ?? t.url,
|
|
383
|
+
width: (e = t.info) == null ? void 0 : e.img_w,
|
|
384
|
+
height: (s = t.info) == null ? void 0 : s.img_h,
|
|
385
|
+
size: (i = t.info) == null ? void 0 : i.size,
|
|
386
|
+
format: (r = t.info) == null ? void 0 : r.img_type,
|
|
378
387
|
isOriginal: !1,
|
|
379
388
|
isPreset: !1,
|
|
380
|
-
bgRemoved: ((o =
|
|
389
|
+
bgRemoved: ((o = t.info) == null ? void 0 : o.remove_background) === !0
|
|
381
390
|
};
|
|
382
391
|
}
|
|
383
|
-
function fe(
|
|
392
|
+
function fe(t) {
|
|
384
393
|
return {
|
|
385
|
-
uuid:
|
|
386
|
-
name:
|
|
387
|
-
url:
|
|
388
|
-
previewUrl:
|
|
389
|
-
width:
|
|
390
|
-
height:
|
|
391
|
-
size:
|
|
392
|
-
format:
|
|
394
|
+
uuid: t.uuid,
|
|
395
|
+
name: t.name,
|
|
396
|
+
url: t.cdnUrl ?? "",
|
|
397
|
+
previewUrl: t.thumbnailUrl ?? t.cdnUrl,
|
|
398
|
+
width: t.width,
|
|
399
|
+
height: t.height,
|
|
400
|
+
size: t.size,
|
|
401
|
+
format: t.fileType,
|
|
393
402
|
isOriginal: !0,
|
|
394
403
|
isPreset: !1,
|
|
395
404
|
bgRemoved: !1
|
|
396
405
|
};
|
|
397
406
|
}
|
|
398
|
-
function ue(
|
|
399
|
-
const
|
|
407
|
+
function ue(t, e) {
|
|
408
|
+
const s = t.cdnUrl ?? "";
|
|
400
409
|
return {
|
|
401
410
|
uuid: `preset-${e.name}`,
|
|
402
411
|
name: e.name,
|
|
403
|
-
url: $(
|
|
404
|
-
previewUrl: $(
|
|
412
|
+
url: $(s, e.name),
|
|
413
|
+
previewUrl: $(t.thumbnailUrl ?? s, e.name),
|
|
405
414
|
isOriginal: !1,
|
|
406
415
|
isPreset: !0,
|
|
407
416
|
bgRemoved: !1
|
|
408
417
|
};
|
|
409
418
|
}
|
|
410
419
|
function ve({
|
|
411
|
-
asset:
|
|
420
|
+
asset: t,
|
|
412
421
|
variants: e = [],
|
|
413
|
-
presets:
|
|
422
|
+
presets: s = []
|
|
414
423
|
}) {
|
|
415
|
-
const i = new Set(
|
|
424
|
+
const i = new Set(s.map((a) => a.name)), r = e.filter((a) => {
|
|
416
425
|
var c;
|
|
417
426
|
return !i.has(a.name) && ((c = a.info) == null ? void 0 : c.remove_background) !== !0;
|
|
418
427
|
}).map(x), o = e.filter((a) => {
|
|
419
428
|
var c;
|
|
420
429
|
return ((c = a.info) == null ? void 0 : c.remove_background) === !0 && !i.has(a.name);
|
|
421
|
-
}).map(x), l =
|
|
422
|
-
return [fe(
|
|
430
|
+
}).map(x), l = s.map((a) => ue(t, a));
|
|
431
|
+
return [fe(t), ...r, ...o, ...l];
|
|
423
432
|
}
|
|
424
|
-
async function ge(
|
|
425
|
-
const
|
|
433
|
+
async function ge(t, e) {
|
|
434
|
+
const s = await t.get(
|
|
426
435
|
`/file/${encodeURIComponent(e)}/variants`
|
|
427
436
|
);
|
|
428
|
-
return (
|
|
437
|
+
return (s == null ? void 0 : s.variants) ?? [];
|
|
429
438
|
}
|
|
430
|
-
function me(
|
|
431
|
-
return Array.isArray(
|
|
439
|
+
function me(t) {
|
|
440
|
+
return Array.isArray(t) ? t.map(
|
|
432
441
|
(e) => typeof e == "string" ? { name: e } : e && typeof e.name == "string" ? { name: e.name, desc: e.desc } : null
|
|
433
442
|
).filter((e) => e !== null) : [];
|
|
434
443
|
}
|
|
435
|
-
async function pe(
|
|
444
|
+
async function pe(t) {
|
|
436
445
|
var i, r, o;
|
|
437
|
-
const e = await
|
|
438
|
-
return me(
|
|
446
|
+
const e = await t.get("/settings"), s = (e == null ? void 0 : e.presets) ?? ((i = e == null ? void 0 : e.cloudimg) == null ? void 0 : i.presets) ?? ((o = (r = e == null ? void 0 : e.settings) == null ? void 0 : r.cloudimg) == null ? void 0 : o.presets) ?? void 0;
|
|
447
|
+
return me(s);
|
|
439
448
|
}
|
|
440
|
-
async function xe(
|
|
441
|
-
const [
|
|
442
|
-
ge(
|
|
443
|
-
pe(
|
|
449
|
+
async function xe(t, e) {
|
|
450
|
+
const [s, i] = await Promise.all([
|
|
451
|
+
ge(t, e.uuid),
|
|
452
|
+
pe(t)
|
|
444
453
|
]);
|
|
445
|
-
return ve({ asset: e, variants:
|
|
454
|
+
return ve({ asset: e, variants: s, presets: i });
|
|
446
455
|
}
|
|
447
|
-
async function we(
|
|
448
|
-
const
|
|
456
|
+
async function we(t, e) {
|
|
457
|
+
const s = await t.post("/file-archive", {
|
|
449
458
|
files_uuids: e.filesUuids ?? [],
|
|
450
459
|
folders_uuids: e.foldersUuids ?? [],
|
|
451
460
|
urls: e.urls ?? []
|
|
452
461
|
});
|
|
453
|
-
if (!(
|
|
454
|
-
return
|
|
462
|
+
if (!(s != null && s.task_id)) throw new Error("Archive task was not created");
|
|
463
|
+
return s.task_id;
|
|
455
464
|
}
|
|
456
|
-
function ye(
|
|
457
|
-
return
|
|
465
|
+
function ye(t, e) {
|
|
466
|
+
return t.get(`/file-archive/${encodeURIComponent(e)}`, {
|
|
458
467
|
status_only: 1
|
|
459
468
|
});
|
|
460
469
|
}
|
|
461
470
|
const Se = /* @__PURE__ */ new Set(["PENDING", "RUNNING", "PROCESSING", ""]);
|
|
462
|
-
function be(
|
|
463
|
-
const e = ((
|
|
471
|
+
function be(t) {
|
|
472
|
+
const e = ((t == null ? void 0 : t.task_status) ?? "").toUpperCase(), s = typeof (t == null ? void 0 : t.task_percent) == "number" ? t.task_percent : 0;
|
|
464
473
|
if (e === "DONE") return { done: !0, progress: 100 };
|
|
465
|
-
if (Se.has(e)) return { done: !1, progress:
|
|
466
|
-
throw new Error(`Archive job failed: ${(
|
|
474
|
+
if (Se.has(e)) return { done: !1, progress: s };
|
|
475
|
+
throw new Error(`Archive job failed: ${(t == null ? void 0 : t.task_status) ?? "unknown status"}`);
|
|
467
476
|
}
|
|
468
|
-
async function _e(
|
|
477
|
+
async function _e(t, e, s = {}) {
|
|
469
478
|
var h, d;
|
|
470
|
-
const i =
|
|
479
|
+
const i = s.intervalMs ?? 1500, r = s.timeoutMs ?? 12e4, o = s.maxRetries ?? 5, l = s.sleep ?? ((u) => new Promise((g) => setTimeout(g, u))), a = s.now ?? Date.now, c = a() + r;
|
|
471
480
|
let f = 0;
|
|
472
481
|
for (; ; ) {
|
|
473
|
-
if ((h =
|
|
482
|
+
if ((h = s.signal) != null && h.aborted) throw new Error("Archive polling aborted");
|
|
474
483
|
if (a() > c) throw new Error("Archive polling timed out");
|
|
475
484
|
let u;
|
|
476
485
|
try {
|
|
477
|
-
u = await ye(
|
|
486
|
+
u = await ye(t, e);
|
|
478
487
|
} catch (S) {
|
|
479
488
|
if (f++ < o) {
|
|
480
489
|
await l(i);
|
|
@@ -483,19 +492,19 @@ async function _e(s, e, t = {}) {
|
|
|
483
492
|
throw S;
|
|
484
493
|
}
|
|
485
494
|
const { done: g, progress: p } = be(u);
|
|
486
|
-
if ((d =
|
|
495
|
+
if ((d = s.onProgress) == null || d.call(s, p), g) return;
|
|
487
496
|
await l(i);
|
|
488
497
|
}
|
|
489
498
|
}
|
|
490
|
-
function Ae(
|
|
491
|
-
const
|
|
492
|
-
if (!i) return
|
|
493
|
-
const r =
|
|
494
|
-
return `${
|
|
499
|
+
function Ae(t, e) {
|
|
500
|
+
const s = t.absoluteUrl(`/file-archive/${encodeURIComponent(e)}`), i = t.authKey;
|
|
501
|
+
if (!i) return s;
|
|
502
|
+
const r = s.includes("?") ? "&" : "?";
|
|
503
|
+
return `${s}${r}secret_key=${encodeURIComponent(i)}`;
|
|
495
504
|
}
|
|
496
|
-
async function Ce(
|
|
497
|
-
const i = await we(
|
|
498
|
-
return await _e(
|
|
505
|
+
async function Ce(t, e, s = {}) {
|
|
506
|
+
const i = await we(t, e);
|
|
507
|
+
return await _e(t, i, s), Ae(t, i);
|
|
499
508
|
}
|
|
500
509
|
const Fe = ["cdn_permalink"], q = {
|
|
501
510
|
created_at: "created_at",
|
|
@@ -504,56 +513,62 @@ const Fe = ["cdn_permalink"], q = {
|
|
|
504
513
|
size: "size",
|
|
505
514
|
type: "type"
|
|
506
515
|
};
|
|
507
|
-
function Ee(
|
|
508
|
-
let e =
|
|
509
|
-
|
|
510
|
-
const
|
|
511
|
-
offset:
|
|
512
|
-
limit:
|
|
516
|
+
function Ee(t) {
|
|
517
|
+
let e = t.fields ?? Fe;
|
|
518
|
+
t.permalinksEnabled || (e = e.filter((l) => l !== "cdn_permalink"));
|
|
519
|
+
const s = {
|
|
520
|
+
offset: t.offset ?? 0,
|
|
521
|
+
limit: t.limit ?? 100,
|
|
513
522
|
format: "json,regvar:api,select:internal",
|
|
514
523
|
preview: 2301,
|
|
515
|
-
recursive:
|
|
524
|
+
recursive: t.recursive ?? 1
|
|
516
525
|
};
|
|
517
|
-
e.length > 0 && (
|
|
518
|
-
const i =
|
|
519
|
-
|
|
526
|
+
e.length > 0 && (s.fields = e);
|
|
527
|
+
const i = t.sort_by ?? "created_at", r = t.sort_direction ?? "desc";
|
|
528
|
+
s.sort = `${q[i] || i}:${r}`, t.folder && (s.folder = t.folder);
|
|
520
529
|
const o = [];
|
|
521
|
-
return
|
|
530
|
+
return t.search && !t.with_ai && o.push(t.search), t.q && o.push(t.q), o.length > 0 && (s.q = o.join(" ")), t.with_ai && (s.with_ai = !0, t.ai_query && (s.ai_query = t.ai_query), t.ai_lang && (s.ai_lang = t.ai_lang)), t.collection_uuid && (s.collection_uuid = t.collection_uuid), t.f64 && (s.f64 = t.f64), s;
|
|
522
531
|
}
|
|
523
|
-
function Ue(
|
|
524
|
-
return
|
|
532
|
+
function Ue(t, e) {
|
|
533
|
+
return t.get("/files", Ee(e));
|
|
525
534
|
}
|
|
526
|
-
function De(
|
|
527
|
-
const
|
|
528
|
-
e.folder && (
|
|
535
|
+
function De(t, e) {
|
|
536
|
+
const s = { recursive: e.recursive ?? 1 };
|
|
537
|
+
e.folder && (s.folder = e.folder);
|
|
529
538
|
const i = [];
|
|
530
|
-
return e.search && !e.with_ai && i.push(e.search), e.q && i.push(e.q), i.length > 0 && (
|
|
539
|
+
return e.search && !e.with_ai && i.push(e.search), e.q && i.push(e.q), i.length > 0 && (s.q = i.join(" ")), e.with_ai && (s.with_ai = !0, e.ai_query && (s.ai_query = e.ai_query), e.ai_lang && (s.ai_lang = e.ai_lang)), e.collection_uuid && (s.collection_uuid = e.collection_uuid), e.f64 && (s.f64 = e.f64), t.get("/files/stats", s);
|
|
531
540
|
}
|
|
532
|
-
function ke(
|
|
533
|
-
const
|
|
541
|
+
function ke(t, e = {}) {
|
|
542
|
+
const s = {
|
|
534
543
|
recursive: e.recursive ?? 0,
|
|
535
544
|
folder: e.folderPath ?? "/",
|
|
536
545
|
limit: e.limit ?? 1e3,
|
|
537
546
|
offset: e.offset ?? 0
|
|
538
547
|
};
|
|
539
|
-
e.q && (
|
|
548
|
+
e.q && (s.q = e.q);
|
|
540
549
|
const i = e.sort_by ?? "created_at", r = e.sort_direction ?? "asc";
|
|
541
|
-
return
|
|
550
|
+
return s.sort = `${q[i] || i}:${r}`, t.get("/folders", s);
|
|
542
551
|
}
|
|
543
|
-
async function Me(
|
|
544
|
-
return e.length === 0 ? {} : (await
|
|
552
|
+
async function Me(t, e) {
|
|
553
|
+
return e.length === 0 ? {} : (await t.post("/folders/previews", {
|
|
545
554
|
folders: e
|
|
546
555
|
})).folders || {};
|
|
547
556
|
}
|
|
548
|
-
const C = 100, U = 1e3, D = {
|
|
557
|
+
const C = 100, U = 1e3, D = {
|
|
558
|
+
types: [],
|
|
559
|
+
size: null,
|
|
560
|
+
duration: null,
|
|
561
|
+
created: null,
|
|
562
|
+
updated: null
|
|
563
|
+
};
|
|
549
564
|
class E {
|
|
550
|
-
constructor(e,
|
|
551
|
-
this.client = e, this.listeners = /* @__PURE__ */ new Set(), this.loadSeq = 0, this.treeSeq = 0, this.fetchedCount = 0, this.selectionAnchor = null, this.favAdapter =
|
|
552
|
-
scope: { type: "folder", value:
|
|
553
|
-
viewMode:
|
|
554
|
-
gridSize:
|
|
555
|
-
sortBy:
|
|
556
|
-
sortDirection:
|
|
565
|
+
constructor(e, s = {}) {
|
|
566
|
+
this.client = e, this.listeners = /* @__PURE__ */ new Set(), this.loadSeq = 0, this.treeSeq = 0, this.fetchedCount = 0, this.selectionAnchor = null, this.favAdapter = s.favourites, this.onScopeChange = s.onScopeChange, this.state = {
|
|
567
|
+
scope: { type: "folder", value: s.rootFolder ?? "/" },
|
|
568
|
+
viewMode: s.viewMode ?? "grid",
|
|
569
|
+
gridSize: s.gridSize ?? "m",
|
|
570
|
+
sortBy: s.sortBy ?? "created_at",
|
|
571
|
+
sortDirection: s.sortDirection ?? "desc",
|
|
557
572
|
searchQuery: "",
|
|
558
573
|
filters: { ...D },
|
|
559
574
|
folders: [],
|
|
@@ -580,15 +595,15 @@ class E {
|
|
|
580
595
|
async loadFolderChildren(e) {
|
|
581
596
|
if (!this.state.treeChildren[e])
|
|
582
597
|
try {
|
|
583
|
-
const
|
|
584
|
-
this.set({ treeChildren: { ...this.state.treeChildren, [e]:
|
|
598
|
+
const s = await b(this.client, { folderPath: e });
|
|
599
|
+
this.set({ treeChildren: { ...this.state.treeChildren, [e]: s } });
|
|
585
600
|
} catch {
|
|
586
601
|
}
|
|
587
602
|
}
|
|
588
603
|
/** Expand/collapse a folder node, lazy-loading its children on first expand. */
|
|
589
604
|
async toggleFolder(e) {
|
|
590
|
-
const
|
|
591
|
-
|
|
605
|
+
const s = new Set(this.state.expandedFolders);
|
|
606
|
+
s.has(e) ? (s.delete(e), this.set({ expandedFolders: s })) : (await this.loadFolderChildren(e), s.add(e), this.set({ expandedFolders: s }));
|
|
592
607
|
}
|
|
593
608
|
async loadLabels() {
|
|
594
609
|
try {
|
|
@@ -605,13 +620,13 @@ class E {
|
|
|
605
620
|
}
|
|
606
621
|
/** Toggle an asset's favourite status (per-user, via the adapter). */
|
|
607
622
|
async toggleFavourite(e) {
|
|
608
|
-
const
|
|
609
|
-
|
|
623
|
+
const s = this.state.favourites.has(e), i = new Set(this.state.favourites);
|
|
624
|
+
s ? i.delete(e) : i.add(e), this.set({ favourites: i });
|
|
610
625
|
try {
|
|
611
|
-
this.favAdapter && (
|
|
626
|
+
this.favAdapter && (s ? await this.favAdapter.remove(e) : await this.favAdapter.add(e));
|
|
612
627
|
} catch {
|
|
613
628
|
const r = new Set(this.state.favourites);
|
|
614
|
-
|
|
629
|
+
s ? r.add(e) : r.delete(e), this.set({ favourites: r });
|
|
615
630
|
return;
|
|
616
631
|
}
|
|
617
632
|
this.state.scope.type === "favourites" && this.load();
|
|
@@ -624,12 +639,12 @@ class E {
|
|
|
624
639
|
}
|
|
625
640
|
set(e) {
|
|
626
641
|
this.state = { ...this.state, ...e };
|
|
627
|
-
for (const
|
|
642
|
+
for (const s of this.listeners) s(this.state);
|
|
628
643
|
}
|
|
629
644
|
// ── navigation / scope ─────────────────────────────────────────────────────
|
|
630
645
|
setScope(e) {
|
|
631
|
-
var
|
|
632
|
-
this.selectionAnchor = null, this.set({ scope: e, selection: /* @__PURE__ */ new Set() }), (
|
|
646
|
+
var s;
|
|
647
|
+
this.selectionAnchor = null, this.set({ scope: e, selection: /* @__PURE__ */ new Set() }), (s = this.onScopeChange) == null || s.call(this, e), this.load();
|
|
633
648
|
}
|
|
634
649
|
openFolder(e) {
|
|
635
650
|
this.setScope({ type: "folder", value: e });
|
|
@@ -647,8 +662,8 @@ class E {
|
|
|
647
662
|
setGridSize(e) {
|
|
648
663
|
this.set({ gridSize: e });
|
|
649
664
|
}
|
|
650
|
-
setSort(e,
|
|
651
|
-
this.set({ sortBy: e, sortDirection:
|
|
665
|
+
setSort(e, s) {
|
|
666
|
+
this.set({ sortBy: e, sortDirection: s }), this.load();
|
|
652
667
|
}
|
|
653
668
|
setSearch(e) {
|
|
654
669
|
this.set({ searchQuery: e }), this.load();
|
|
@@ -659,23 +674,23 @@ class E {
|
|
|
659
674
|
}
|
|
660
675
|
/** Toggle one file-type in the type facet. Reloads from page 1. */
|
|
661
676
|
toggleType(e) {
|
|
662
|
-
const
|
|
677
|
+
const s = this.state.filters.types;
|
|
663
678
|
this.setFilters({
|
|
664
|
-
types:
|
|
679
|
+
types: s.includes(e) ? s.filter((i) => i !== e) : [...s, e]
|
|
665
680
|
});
|
|
666
681
|
}
|
|
667
682
|
/** Number of active facets across all groups (for the toolbar badge). */
|
|
668
683
|
get activeFilterCount() {
|
|
669
|
-
const { types: e, size:
|
|
670
|
-
return e.length + (
|
|
684
|
+
const { types: e, size: s, duration: i, created: r, updated: o } = this.state.filters;
|
|
685
|
+
return e.length + (s ? 1 : 0) + (i ? 1 : 0) + (r ? 1 : 0) + (o ? 1 : 0);
|
|
671
686
|
}
|
|
672
687
|
/** Clear every facet in one update, then reload. No-op if nothing is active. */
|
|
673
688
|
clearFilters() {
|
|
674
689
|
this.activeFilterCount && (this.set({ filters: { ...D } }), this.load());
|
|
675
690
|
}
|
|
676
691
|
// ── selection ──────────────────────────────────────────────────────────────
|
|
677
|
-
toggleSelect(e,
|
|
678
|
-
const i = new Set(
|
|
692
|
+
toggleSelect(e, s = !1) {
|
|
693
|
+
const i = new Set(s ? this.state.selection : []), r = !i.has(e);
|
|
679
694
|
r ? i.add(e) : i.delete(e), r && (this.selectionAnchor = e), this.set({ selection: i });
|
|
680
695
|
}
|
|
681
696
|
/**
|
|
@@ -686,23 +701,23 @@ class E {
|
|
|
686
701
|
* anchor yet, behaves like a plain multi-select toggle.
|
|
687
702
|
*/
|
|
688
703
|
selectRange(e) {
|
|
689
|
-
const
|
|
704
|
+
const s = this.state.assets, i = s.findIndex((c) => c.uuid === e);
|
|
690
705
|
if (i < 0) return;
|
|
691
|
-
const r = this.selectionAnchor != null ?
|
|
706
|
+
const r = this.selectionAnchor != null ? s.findIndex((c) => c.uuid === this.selectionAnchor) : -1;
|
|
692
707
|
if (r < 0) {
|
|
693
708
|
this.toggleSelect(e, !0);
|
|
694
709
|
return;
|
|
695
710
|
}
|
|
696
711
|
const [o, l] = r <= i ? [r, i] : [i, r], a = new Set(this.state.selection);
|
|
697
|
-
for (let c = o; c <= l; c++) a.add(
|
|
712
|
+
for (let c = o; c <= l; c++) a.add(s[c].uuid);
|
|
698
713
|
this.set({ selection: a });
|
|
699
714
|
}
|
|
700
715
|
/** Replace the whole selection in one update (e.g. "select all", marquee drag). */
|
|
701
716
|
setSelection(e) {
|
|
702
|
-
const
|
|
717
|
+
const s = new Set(e);
|
|
703
718
|
let i = null;
|
|
704
|
-
for (const r of
|
|
705
|
-
this.selectionAnchor = i, this.set({ selection:
|
|
719
|
+
for (const r of s) i = r;
|
|
720
|
+
this.selectionAnchor = i, this.set({ selection: s });
|
|
706
721
|
}
|
|
707
722
|
clearSelection() {
|
|
708
723
|
this.selectionAnchor = null, this.set({ selection: /* @__PURE__ */ new Set() });
|
|
@@ -721,9 +736,9 @@ class E {
|
|
|
721
736
|
* `treeSeq` guard discards a superseded refresh.
|
|
722
737
|
*/
|
|
723
738
|
async refreshTree() {
|
|
724
|
-
const e = ++this.treeSeq,
|
|
739
|
+
const e = ++this.treeSeq, s = /* @__PURE__ */ new Set(["/", this.currentFolderPath, ...this.state.expandedFolders]), i = {};
|
|
725
740
|
await Promise.all(
|
|
726
|
-
[...
|
|
741
|
+
[...s].map(async (r) => {
|
|
727
742
|
try {
|
|
728
743
|
i[r] = await b(this.client, { folderPath: r });
|
|
729
744
|
} catch {
|
|
@@ -740,8 +755,8 @@ class E {
|
|
|
740
755
|
}
|
|
741
756
|
/** Find a cached folder's path by uuid (across the tree cache + current list). */
|
|
742
757
|
folderPath(e) {
|
|
743
|
-
for (const
|
|
744
|
-
const i =
|
|
758
|
+
for (const s of [this.state.folders, ...Object.values(this.state.treeChildren)]) {
|
|
759
|
+
const i = s.find((r) => r.uuid === e);
|
|
745
760
|
if (i) return i.path;
|
|
746
761
|
}
|
|
747
762
|
}
|
|
@@ -751,49 +766,50 @@ class E {
|
|
|
751
766
|
* scope to its new path (or the parent on delete). Returns true if it redirected
|
|
752
767
|
* (which itself triggers a reload), so the caller can skip its own load().
|
|
753
768
|
*/
|
|
754
|
-
redirectScope(e,
|
|
769
|
+
redirectScope(e, s) {
|
|
755
770
|
const { scope: i } = this.state;
|
|
756
771
|
if (i.type !== "folder" || !i.value) return !1;
|
|
757
772
|
const r = i.value;
|
|
758
|
-
return r !== e && !r.startsWith(e + "/") ? !1 : (
|
|
773
|
+
return r !== e && !r.startsWith(e + "/") ? !1 : (s === null ? this.openFolder(E.parentOf(e)) : this.openFolder(r === e ? s : s + r.slice(e.length)), !0);
|
|
759
774
|
}
|
|
760
775
|
async createFolder(e) {
|
|
761
776
|
await K(this.client, e, this.currentFolderPath), await this.refreshTree(), await this.load();
|
|
762
777
|
}
|
|
763
|
-
async renameFolderById(e,
|
|
778
|
+
async renameFolderById(e, s) {
|
|
764
779
|
const i = this.folderPath(e);
|
|
765
|
-
await Y(this.client, e,
|
|
766
|
-
const r = i ? `${E.parentOf(i).replace(/\/$/, "")}/${
|
|
780
|
+
await Y(this.client, e, s), await this.refreshTree();
|
|
781
|
+
const r = i ? `${E.parentOf(i).replace(/\/$/, "")}/${s}` : null;
|
|
767
782
|
i && r && this.redirectScope(i, r) || await this.load();
|
|
768
783
|
}
|
|
769
784
|
async deleteFolderById(e) {
|
|
770
|
-
const
|
|
771
|
-
await Z(this.client, [e]), await this.refreshTree(),
|
|
785
|
+
const s = this.folderPath(e);
|
|
786
|
+
await Z(this.client, [e]), await this.refreshTree(), s && this.redirectScope(s, null) || await this.load();
|
|
772
787
|
}
|
|
773
|
-
async moveFolderById(e,
|
|
788
|
+
async moveFolderById(e, s) {
|
|
774
789
|
const i = this.folderPath(e);
|
|
775
|
-
await Q(this.client, [e],
|
|
776
|
-
const r = (i == null ? void 0 : i.split("/").pop()) ?? "", o = i ? `${
|
|
790
|
+
await Q(this.client, [e], s), await this.refreshTree();
|
|
791
|
+
const r = (i == null ? void 0 : i.split("/").pop()) ?? "", o = i ? `${s.replace(/\/$/, "")}/${r}` : null;
|
|
777
792
|
i && o && this.redirectScope(i, o) || await this.load();
|
|
778
793
|
}
|
|
779
|
-
async renameAsset(e,
|
|
780
|
-
await ae(this.client, e,
|
|
794
|
+
async renameAsset(e, s) {
|
|
795
|
+
await ae(this.client, e, s), await this.load();
|
|
781
796
|
}
|
|
782
797
|
async deleteAssets(e) {
|
|
783
798
|
await ce(this.client, e), this.clearSelection(), await this.load();
|
|
784
799
|
}
|
|
785
|
-
async moveAssets(e,
|
|
786
|
-
await le(this.client, e,
|
|
800
|
+
async moveAssets(e, s) {
|
|
801
|
+
await le(this.client, e, s), this.clearSelection(), await this.load();
|
|
787
802
|
}
|
|
788
803
|
// ── data loading ───────────────────────────────────────────────────────────
|
|
789
804
|
/** Translate the active filter facets into the api query shape (undefined = off). */
|
|
790
805
|
facetParams() {
|
|
791
|
-
const { types: e, size:
|
|
806
|
+
const { types: e, size: s, duration: i, created: r, updated: o } = this.state.filters;
|
|
792
807
|
return {
|
|
793
808
|
types: e.length ? e : void 0,
|
|
794
|
-
sizeBucket:
|
|
795
|
-
|
|
796
|
-
|
|
809
|
+
sizeBucket: s ?? void 0,
|
|
810
|
+
durationRange: i ?? void 0,
|
|
811
|
+
createdWithin: r ?? void 0,
|
|
812
|
+
updatedWithin: o ?? void 0
|
|
797
813
|
};
|
|
798
814
|
}
|
|
799
815
|
/**
|
|
@@ -808,8 +824,8 @@ class E {
|
|
|
808
824
|
* the caller advances its offset cursor correctly even when dedupe drops items.
|
|
809
825
|
*/
|
|
810
826
|
async fetchAssetsPage(e) {
|
|
811
|
-
const { scope:
|
|
812
|
-
if (
|
|
827
|
+
const { scope: s, sortBy: i, sortDirection: r } = this.state, o = this.state.searchQuery || void 0, l = this.facetParams();
|
|
828
|
+
if (s.type === "favourites") {
|
|
813
829
|
const h = [...this.state.favourites], d = await oe(this.client, h.slice(0, U)), u = Date.now(), g = d.filter((S) => re(S, l, u)), p = ne(g, i, r);
|
|
814
830
|
return {
|
|
815
831
|
assets: p,
|
|
@@ -821,11 +837,11 @@ class E {
|
|
|
821
837
|
}
|
|
822
838
|
const a = { sortBy: i, sortDirection: r, search: o, ...l, offset: e, limit: C };
|
|
823
839
|
let c;
|
|
824
|
-
if (
|
|
840
|
+
if (s.type === "folder") {
|
|
825
841
|
const h = this.state.searchQuery.trim() ? 1 : 0;
|
|
826
|
-
c = await w(this.client, { ...a, folder:
|
|
827
|
-
} else if (
|
|
828
|
-
const h = this.state.labels.find((u) => u.uuid ===
|
|
842
|
+
c = await w(this.client, { ...a, folder: s.value ?? "/", recursive: h });
|
|
843
|
+
} else if (s.type === "label") {
|
|
844
|
+
const h = this.state.labels.find((u) => u.uuid === s.value), d = h ? he(h) : void 0;
|
|
829
845
|
c = await w(this.client, { ...a, recursive: 1, q: d });
|
|
830
846
|
} else
|
|
831
847
|
c = await w(this.client, { ...a, recursive: 1 });
|
|
@@ -843,7 +859,7 @@ class E {
|
|
|
843
859
|
const e = ++this.loadSeq;
|
|
844
860
|
this.set({ loading: !0, loadingMore: !1, error: null });
|
|
845
861
|
try {
|
|
846
|
-
const
|
|
862
|
+
const s = b(this.client, { folderPath: this.currentFolderPath }), i = this.fetchAssetsPage(0), [r, o] = await Promise.all([s, i]);
|
|
847
863
|
if (e !== this.loadSeq) return;
|
|
848
864
|
this.fetchedCount = o.fetched, this.set({
|
|
849
865
|
folders: r,
|
|
@@ -855,9 +871,9 @@ class E {
|
|
|
855
871
|
// keep the tree cache warm for the folder we just listed
|
|
856
872
|
treeChildren: { ...this.state.treeChildren, [this.currentFolderPath]: r }
|
|
857
873
|
});
|
|
858
|
-
} catch (
|
|
874
|
+
} catch (s) {
|
|
859
875
|
if (e !== this.loadSeq) return;
|
|
860
|
-
this.set({ error:
|
|
876
|
+
this.set({ error: s instanceof Error ? s.message : String(s), loading: !1 });
|
|
861
877
|
}
|
|
862
878
|
}
|
|
863
879
|
/**
|
|
@@ -874,25 +890,25 @@ class E {
|
|
|
874
890
|
const e = this.loadSeq;
|
|
875
891
|
this.set({ loadingMore: !0 });
|
|
876
892
|
try {
|
|
877
|
-
const
|
|
893
|
+
const s = await this.fetchAssetsPage(this.fetchedCount);
|
|
878
894
|
if (e !== this.loadSeq) return;
|
|
879
|
-
this.fetchedCount +=
|
|
880
|
-
const i = new Set(this.state.assets.map((o) => o.uuid)), r =
|
|
895
|
+
this.fetchedCount += s.fetched;
|
|
896
|
+
const i = new Set(this.state.assets.map((o) => o.uuid)), r = s.assets.filter((o) => !i.has(o.uuid));
|
|
881
897
|
this.set({
|
|
882
898
|
assets: [...this.state.assets, ...r],
|
|
883
|
-
total:
|
|
884
|
-
hasMore:
|
|
899
|
+
total: s.total,
|
|
900
|
+
hasMore: s.hasMore,
|
|
885
901
|
loadingMore: !1,
|
|
886
902
|
error: null
|
|
887
903
|
// a recovered page clears any prior load-more failure
|
|
888
904
|
});
|
|
889
|
-
} catch (
|
|
905
|
+
} catch (s) {
|
|
890
906
|
if (e !== this.loadSeq) return;
|
|
891
|
-
this.set({ error:
|
|
907
|
+
this.set({ error: s instanceof Error ? s.message : String(s), loadingMore: !1 });
|
|
892
908
|
}
|
|
893
909
|
}
|
|
894
910
|
}
|
|
895
|
-
class
|
|
911
|
+
class Re {
|
|
896
912
|
constructor(e = "sfx-light-dam:favourites") {
|
|
897
913
|
this.key = e;
|
|
898
914
|
}
|
|
@@ -917,73 +933,73 @@ class Oe {
|
|
|
917
933
|
return this.read().has(e);
|
|
918
934
|
}
|
|
919
935
|
add(e) {
|
|
920
|
-
const
|
|
921
|
-
|
|
936
|
+
const s = this.read();
|
|
937
|
+
s.add(e), this.write(s);
|
|
922
938
|
}
|
|
923
939
|
remove(e) {
|
|
924
|
-
const
|
|
925
|
-
|
|
940
|
+
const s = this.read();
|
|
941
|
+
s.delete(e), this.write(s);
|
|
926
942
|
}
|
|
927
943
|
}
|
|
928
|
-
function
|
|
929
|
-
const
|
|
930
|
-
return e.width &&
|
|
944
|
+
function Oe(t, e) {
|
|
945
|
+
const s = new URL(t);
|
|
946
|
+
return e.width && s.searchParams.set("w", String(e.width)), e.height && s.searchParams.set("h", String(e.height)), e.quality !== void 0 && s.searchParams.set("q", String(e.quality)), s.toString();
|
|
931
947
|
}
|
|
932
948
|
const Le = { excellent: 90, good: 75, fair: 60 }, ze = { fullhd: 1920, large: 1200, medium: 600, small: 300 }, Pe = {
|
|
933
949
|
webp: "awebp,webp",
|
|
934
950
|
gif: "agif,gif"
|
|
935
951
|
};
|
|
936
|
-
function j(
|
|
937
|
-
|
|
952
|
+
function j(t, e) {
|
|
953
|
+
t.searchParams.delete("download"), e.width && t.searchParams.set("w", String(e.width)), e.height && t.searchParams.set("h", String(e.height)), e.quality != null && t.searchParams.set("q", String(e.quality)), e.format && t.searchParams.set("force_format", Pe[e.format] ?? e.format), e.strictSizes !== void 0 && (e.width || e.height) && t.searchParams.set("func", e.strictSizes ? "bound" : "cover");
|
|
938
954
|
}
|
|
939
|
-
function Te(
|
|
940
|
-
if (!e) return
|
|
941
|
-
const
|
|
942
|
-
return `${
|
|
955
|
+
function Te(t, e) {
|
|
956
|
+
if (!e) return t;
|
|
957
|
+
const s = e === "jpeg" ? "jpg" : e;
|
|
958
|
+
return `${t.replace(/\.[^./\\]+$/, "") || t}.${s}`;
|
|
943
959
|
}
|
|
944
|
-
function qe(
|
|
945
|
-
const i = new URL(
|
|
946
|
-
return j(i,
|
|
960
|
+
function qe(t, e, s = {}) {
|
|
961
|
+
const i = new URL(t);
|
|
962
|
+
return j(i, s), i.searchParams.set("force_download", Te(e, s.format)), i.toString();
|
|
947
963
|
}
|
|
948
|
-
function je(
|
|
949
|
-
const
|
|
950
|
-
return j(
|
|
964
|
+
function je(t, e = {}) {
|
|
965
|
+
const s = new URL(t);
|
|
966
|
+
return j(s, e), s.toString();
|
|
951
967
|
}
|
|
952
968
|
const k = /^(https:\/\/)([a-z0-9_-]+)\.filerobot\.com\/(?:v\d+\/)?/i;
|
|
953
|
-
function _(
|
|
954
|
-
if (!
|
|
969
|
+
function _(t) {
|
|
970
|
+
if (!t) return "";
|
|
955
971
|
const e = (i) => i.replace(/(\.filerobot\.com\/[a-z0-9_-]+)\/v\d+\//i, "$1/");
|
|
956
|
-
if (
|
|
957
|
-
const
|
|
958
|
-
return
|
|
972
|
+
if (t.includes("assets.filerobot.com")) return e(t);
|
|
973
|
+
const s = t.match(k);
|
|
974
|
+
return s ? e(t.replace(k, `$1assets.filerobot.com/${s[2]}/`)) : t;
|
|
959
975
|
}
|
|
960
|
-
function A(
|
|
976
|
+
function A(t, e) {
|
|
961
977
|
try {
|
|
962
|
-
const
|
|
963
|
-
for (const [i, r] of Object.entries(e))
|
|
964
|
-
return
|
|
978
|
+
const s = new URL(t);
|
|
979
|
+
for (const [i, r] of Object.entries(e)) s.searchParams.set(i, r);
|
|
980
|
+
return s.toString();
|
|
965
981
|
} catch {
|
|
966
|
-
return
|
|
982
|
+
return t;
|
|
967
983
|
}
|
|
968
984
|
}
|
|
969
|
-
function Ne(
|
|
970
|
-
const
|
|
971
|
-
if (
|
|
972
|
-
return
|
|
973
|
-
if (
|
|
974
|
-
const i = _(
|
|
985
|
+
function Ne(t, e = 240) {
|
|
986
|
+
const s = String(e);
|
|
987
|
+
if (t.type === "video")
|
|
988
|
+
return t.thumbnailUrl ? A(_(t.thumbnailUrl), { w: s, force_format: "webp,jpeg" }) : "";
|
|
989
|
+
if (t.type === "document" && /\.pdf$/i.test(t.name)) {
|
|
990
|
+
const i = _(t.cdnUrl ?? "");
|
|
975
991
|
if (!i) return "";
|
|
976
992
|
const r = i.replace(/([?&])func=proxy&?/, "$1").replace(/[?&]$/, "");
|
|
977
993
|
return A(r, {
|
|
978
|
-
w:
|
|
994
|
+
w: s,
|
|
979
995
|
force_format: "webp,jpeg",
|
|
980
996
|
doc_page: "1",
|
|
981
997
|
bypass_process_proxy: "1"
|
|
982
998
|
});
|
|
983
999
|
}
|
|
984
|
-
if (
|
|
985
|
-
const i =
|
|
986
|
-
return i ? A(_(i), { w:
|
|
1000
|
+
if (t.type === "image" || t.thumbnailUrl) {
|
|
1001
|
+
const i = t.thumbnailUrl ?? t.cdnUrl;
|
|
1002
|
+
return i ? A(_(i), { w: s, func: "bound" }) : "";
|
|
987
1003
|
}
|
|
988
1004
|
return "";
|
|
989
1005
|
}
|
|
@@ -1099,47 +1115,47 @@ const n = "https://scaleflex.cloudimg.io/v7/assets/file-types/v3/", Ie = '<svg x
|
|
|
1099
1115
|
function Be() {
|
|
1100
1116
|
return P._default;
|
|
1101
1117
|
}
|
|
1102
|
-
function Ge(
|
|
1103
|
-
const e = (
|
|
1118
|
+
function Ge(t) {
|
|
1119
|
+
const e = (t.split(".").pop() || "").toLowerCase();
|
|
1104
1120
|
return P[e] || P._default;
|
|
1105
1121
|
}
|
|
1106
|
-
function We(
|
|
1107
|
-
if (
|
|
1122
|
+
function We(t) {
|
|
1123
|
+
if (t == null || !Number.isFinite(t) || t < 0) return "—";
|
|
1108
1124
|
const e = ["B", "KB", "MB", "GB", "TB"];
|
|
1109
|
-
let
|
|
1110
|
-
for (;
|
|
1111
|
-
|
|
1125
|
+
let s = t, i = 0;
|
|
1126
|
+
for (; s >= 1024 && i < e.length - 1; )
|
|
1127
|
+
s /= 1024, i++;
|
|
1112
1128
|
const r = (a, c) => {
|
|
1113
1129
|
const f = c > 0 && Math.round(a * 10) / 10 < 10 ? 1 : 0, h = a.toFixed(f);
|
|
1114
1130
|
return { str: h, rounded: Number(h) };
|
|
1115
|
-
}, o = r(
|
|
1131
|
+
}, o = r(s, i);
|
|
1116
1132
|
let l = o.str;
|
|
1117
|
-
return o.rounded >= 1024 && i < e.length - 1 && (
|
|
1133
|
+
return o.rounded >= 1024 && i < e.length - 1 && (s /= 1024, i++, l = r(s, i).str), `${l} ${e[i]}`;
|
|
1118
1134
|
}
|
|
1119
|
-
function Xe(
|
|
1120
|
-
if (!
|
|
1121
|
-
const e = new Date(
|
|
1122
|
-
return Number.isNaN(e.getTime()) ?
|
|
1135
|
+
function Xe(t) {
|
|
1136
|
+
if (!t) return "—";
|
|
1137
|
+
const e = new Date(t);
|
|
1138
|
+
return Number.isNaN(e.getTime()) ? t : e.toLocaleDateString(void 0, { year: "numeric", month: "short", day: "numeric" });
|
|
1123
1139
|
}
|
|
1124
|
-
function Ve(
|
|
1125
|
-
return
|
|
1140
|
+
function Ve(t, e) {
|
|
1141
|
+
return t && e ? `${t} × ${e}` : "—";
|
|
1126
1142
|
}
|
|
1127
|
-
function He(
|
|
1128
|
-
let
|
|
1143
|
+
function He(t, e) {
|
|
1144
|
+
let s;
|
|
1129
1145
|
const i = ((...r) => {
|
|
1130
|
-
clearTimeout(
|
|
1146
|
+
clearTimeout(s), s = setTimeout(() => t(...r), e);
|
|
1131
1147
|
});
|
|
1132
|
-
return i.cancel = () => clearTimeout(
|
|
1148
|
+
return i.cancel = () => clearTimeout(s), i;
|
|
1133
1149
|
}
|
|
1134
1150
|
export {
|
|
1135
1151
|
E as BrowseStore,
|
|
1136
|
-
|
|
1137
|
-
|
|
1152
|
+
R as DamClient,
|
|
1153
|
+
Re as LocalFavouritesAdapter,
|
|
1138
1154
|
U as MAX_FAVOURITES,
|
|
1139
1155
|
C as PAGE_SIZE,
|
|
1140
1156
|
Le as QUALITY_LEVELS,
|
|
1141
1157
|
ze as RESIZE_PRESETS,
|
|
1142
|
-
|
|
1158
|
+
Oe as addCdnParams,
|
|
1143
1159
|
Ae as archiveDownloadUrl,
|
|
1144
1160
|
be as archiveStatusOutcome,
|
|
1145
1161
|
ve as assembleVariations,
|