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