@scaleflex/dam-core 0.3.1 → 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 +400 -383
- 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,20 +1,20 @@
|
|
|
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);
|
|
14
|
-
const
|
|
14
|
+
const f = new AbortController(), h = setTimeout(() => f.abort(), 3e4);
|
|
15
15
|
try {
|
|
16
|
-
const d = await fetch(r, { signal:
|
|
17
|
-
if (clearTimeout(
|
|
16
|
+
const d = await fetch(r, { signal: f.signal, cache: "no-store" });
|
|
17
|
+
if (clearTimeout(h), !d.ok) {
|
|
18
18
|
if (a = new Error(`SASS key exchange failed (HTTP ${d.status})`), B(d.status) && c < o) continue;
|
|
19
19
|
throw a;
|
|
20
20
|
}
|
|
@@ -23,7 +23,7 @@ async function W(s, e, t, i = {}) {
|
|
|
23
23
|
throw new Error(`SASS key exchange failed: ${u.msg || "Unknown error"}`);
|
|
24
24
|
return u.key;
|
|
25
25
|
} catch (d) {
|
|
26
|
-
if (clearTimeout(
|
|
26
|
+
if (clearTimeout(h), d instanceof DOMException && d.name === "AbortError")
|
|
27
27
|
throw new Error("SASS key exchange timed out");
|
|
28
28
|
if (d instanceof TypeError && c < o) {
|
|
29
29
|
a = d;
|
|
@@ -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,91 +111,91 @@ 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
|
-
const
|
|
132
|
-
return this.headers =
|
|
131
|
+
const h = await I(this.auth, this.apiDomain);
|
|
132
|
+
return this.headers = h.headers, this.send(e, s, !0);
|
|
133
133
|
}
|
|
134
134
|
if (!a.ok) {
|
|
135
|
-
let
|
|
135
|
+
let h = `API error: ${a.status} ${a.statusText}`;
|
|
136
136
|
try {
|
|
137
137
|
const d = await a.json();
|
|
138
|
-
d != null && d.msg && (
|
|
138
|
+
d != null && d.msg && (h = `API error: ${a.status} - ${d.msg}`);
|
|
139
139
|
} catch {
|
|
140
140
|
}
|
|
141
|
-
throw new Error(
|
|
141
|
+
throw new Error(h);
|
|
142
142
|
}
|
|
143
143
|
if (a.status === 204) return;
|
|
144
144
|
const c = await a.text();
|
|
145
145
|
if (!c) return;
|
|
146
|
-
const
|
|
147
|
-
if ((
|
|
148
|
-
throw new Error(`API error: ${
|
|
149
|
-
return
|
|
146
|
+
const f = JSON.parse(c);
|
|
147
|
+
if ((f == null ? void 0 : f.status) === "error")
|
|
148
|
+
throw new Error(`API error: ${f.msg || "Unknown error"}`);
|
|
149
|
+
return f;
|
|
150
150
|
} catch (a) {
|
|
151
151
|
throw clearTimeout(o), a instanceof DOMException && a.name === "AbortError" ? new Error("API request timed out") : a;
|
|
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,194 +317,194 @@ 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
|
|
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
|
|
327
336
|
});
|
|
328
|
-
|
|
337
|
+
f != null && f.file && (r[c] = z(f.file));
|
|
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(
|
|
469
|
-
var
|
|
470
|
-
const i =
|
|
471
|
-
let
|
|
477
|
+
async function _e(t, e, s = {}) {
|
|
478
|
+
var h, d;
|
|
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;
|
|
480
|
+
let f = 0;
|
|
472
481
|
for (; ; ) {
|
|
473
|
-
if ((
|
|
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
|
-
if (
|
|
488
|
+
if (f++ < o) {
|
|
480
489
|
await l(i);
|
|
481
490
|
continue;
|
|
482
491
|
}
|
|
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,32 +824,33 @@ 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 (
|
|
813
|
-
const
|
|
827
|
+
const { scope: s, sortBy: i, sortDirection: r } = this.state, o = this.state.searchQuery || void 0, l = this.facetParams();
|
|
828
|
+
if (s.type === "favourites") {
|
|
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,
|
|
816
832
|
total: p.length,
|
|
817
|
-
truncated:
|
|
833
|
+
truncated: h.length > U,
|
|
818
834
|
hasMore: !1,
|
|
819
835
|
fetched: 0
|
|
820
836
|
};
|
|
821
837
|
}
|
|
822
838
|
const a = { sortBy: i, sortDirection: r, search: o, ...l, offset: e, limit: C };
|
|
823
839
|
let c;
|
|
824
|
-
if (
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
840
|
+
if (s.type === "folder") {
|
|
841
|
+
const h = this.state.searchQuery.trim() ? 1 : 0;
|
|
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;
|
|
828
845
|
c = await w(this.client, { ...a, recursive: 1, q: d });
|
|
829
846
|
} else
|
|
830
847
|
c = await w(this.client, { ...a, recursive: 1 });
|
|
831
|
-
const
|
|
848
|
+
const f = c.assets.length === C;
|
|
832
849
|
return {
|
|
833
850
|
assets: c.assets,
|
|
834
851
|
total: c.total,
|
|
835
852
|
truncated: !1,
|
|
836
|
-
hasMore:
|
|
853
|
+
hasMore: f,
|
|
837
854
|
fetched: c.assets.length
|
|
838
855
|
};
|
|
839
856
|
}
|
|
@@ -842,7 +859,7 @@ class E {
|
|
|
842
859
|
const e = ++this.loadSeq;
|
|
843
860
|
this.set({ loading: !0, loadingMore: !1, error: null });
|
|
844
861
|
try {
|
|
845
|
-
const
|
|
862
|
+
const s = b(this.client, { folderPath: this.currentFolderPath }), i = this.fetchAssetsPage(0), [r, o] = await Promise.all([s, i]);
|
|
846
863
|
if (e !== this.loadSeq) return;
|
|
847
864
|
this.fetchedCount = o.fetched, this.set({
|
|
848
865
|
folders: r,
|
|
@@ -854,9 +871,9 @@ class E {
|
|
|
854
871
|
// keep the tree cache warm for the folder we just listed
|
|
855
872
|
treeChildren: { ...this.state.treeChildren, [this.currentFolderPath]: r }
|
|
856
873
|
});
|
|
857
|
-
} catch (
|
|
874
|
+
} catch (s) {
|
|
858
875
|
if (e !== this.loadSeq) return;
|
|
859
|
-
this.set({ error:
|
|
876
|
+
this.set({ error: s instanceof Error ? s.message : String(s), loading: !1 });
|
|
860
877
|
}
|
|
861
878
|
}
|
|
862
879
|
/**
|
|
@@ -873,25 +890,25 @@ class E {
|
|
|
873
890
|
const e = this.loadSeq;
|
|
874
891
|
this.set({ loadingMore: !0 });
|
|
875
892
|
try {
|
|
876
|
-
const
|
|
893
|
+
const s = await this.fetchAssetsPage(this.fetchedCount);
|
|
877
894
|
if (e !== this.loadSeq) return;
|
|
878
|
-
this.fetchedCount +=
|
|
879
|
-
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));
|
|
880
897
|
this.set({
|
|
881
898
|
assets: [...this.state.assets, ...r],
|
|
882
|
-
total:
|
|
883
|
-
hasMore:
|
|
899
|
+
total: s.total,
|
|
900
|
+
hasMore: s.hasMore,
|
|
884
901
|
loadingMore: !1,
|
|
885
902
|
error: null
|
|
886
903
|
// a recovered page clears any prior load-more failure
|
|
887
904
|
});
|
|
888
|
-
} catch (
|
|
905
|
+
} catch (s) {
|
|
889
906
|
if (e !== this.loadSeq) return;
|
|
890
|
-
this.set({ error:
|
|
907
|
+
this.set({ error: s instanceof Error ? s.message : String(s), loadingMore: !1 });
|
|
891
908
|
}
|
|
892
909
|
}
|
|
893
910
|
}
|
|
894
|
-
class
|
|
911
|
+
class Re {
|
|
895
912
|
constructor(e = "sfx-light-dam:favourites") {
|
|
896
913
|
this.key = e;
|
|
897
914
|
}
|
|
@@ -916,73 +933,73 @@ class Oe {
|
|
|
916
933
|
return this.read().has(e);
|
|
917
934
|
}
|
|
918
935
|
add(e) {
|
|
919
|
-
const
|
|
920
|
-
|
|
936
|
+
const s = this.read();
|
|
937
|
+
s.add(e), this.write(s);
|
|
921
938
|
}
|
|
922
939
|
remove(e) {
|
|
923
|
-
const
|
|
924
|
-
|
|
940
|
+
const s = this.read();
|
|
941
|
+
s.delete(e), this.write(s);
|
|
925
942
|
}
|
|
926
943
|
}
|
|
927
|
-
function
|
|
928
|
-
const
|
|
929
|
-
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();
|
|
930
947
|
}
|
|
931
948
|
const Le = { excellent: 90, good: 75, fair: 60 }, ze = { fullhd: 1920, large: 1200, medium: 600, small: 300 }, Pe = {
|
|
932
949
|
webp: "awebp,webp",
|
|
933
950
|
gif: "agif,gif"
|
|
934
951
|
};
|
|
935
|
-
function j(
|
|
936
|
-
|
|
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");
|
|
937
954
|
}
|
|
938
|
-
function Te(
|
|
939
|
-
if (!e) return
|
|
940
|
-
const
|
|
941
|
-
return `${
|
|
955
|
+
function Te(t, e) {
|
|
956
|
+
if (!e) return t;
|
|
957
|
+
const s = e === "jpeg" ? "jpg" : e;
|
|
958
|
+
return `${t.replace(/\.[^./\\]+$/, "") || t}.${s}`;
|
|
942
959
|
}
|
|
943
|
-
function qe(
|
|
944
|
-
const i = new URL(
|
|
945
|
-
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();
|
|
946
963
|
}
|
|
947
|
-
function je(
|
|
948
|
-
const
|
|
949
|
-
return j(
|
|
964
|
+
function je(t, e = {}) {
|
|
965
|
+
const s = new URL(t);
|
|
966
|
+
return j(s, e), s.toString();
|
|
950
967
|
}
|
|
951
968
|
const k = /^(https:\/\/)([a-z0-9_-]+)\.filerobot\.com\/(?:v\d+\/)?/i;
|
|
952
|
-
function _(
|
|
953
|
-
if (!
|
|
969
|
+
function _(t) {
|
|
970
|
+
if (!t) return "";
|
|
954
971
|
const e = (i) => i.replace(/(\.filerobot\.com\/[a-z0-9_-]+)\/v\d+\//i, "$1/");
|
|
955
|
-
if (
|
|
956
|
-
const
|
|
957
|
-
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;
|
|
958
975
|
}
|
|
959
|
-
function A(
|
|
976
|
+
function A(t, e) {
|
|
960
977
|
try {
|
|
961
|
-
const
|
|
962
|
-
for (const [i, r] of Object.entries(e))
|
|
963
|
-
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();
|
|
964
981
|
} catch {
|
|
965
|
-
return
|
|
982
|
+
return t;
|
|
966
983
|
}
|
|
967
984
|
}
|
|
968
|
-
function Ne(
|
|
969
|
-
const
|
|
970
|
-
if (
|
|
971
|
-
return
|
|
972
|
-
if (
|
|
973
|
-
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 ?? "");
|
|
974
991
|
if (!i) return "";
|
|
975
992
|
const r = i.replace(/([?&])func=proxy&?/, "$1").replace(/[?&]$/, "");
|
|
976
993
|
return A(r, {
|
|
977
|
-
w:
|
|
994
|
+
w: s,
|
|
978
995
|
force_format: "webp,jpeg",
|
|
979
996
|
doc_page: "1",
|
|
980
997
|
bypass_process_proxy: "1"
|
|
981
998
|
});
|
|
982
999
|
}
|
|
983
|
-
if (
|
|
984
|
-
const i =
|
|
985
|
-
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" }) : "";
|
|
986
1003
|
}
|
|
987
1004
|
return "";
|
|
988
1005
|
}
|
|
@@ -1098,47 +1115,47 @@ const n = "https://scaleflex.cloudimg.io/v7/assets/file-types/v3/", Ie = '<svg x
|
|
|
1098
1115
|
function Be() {
|
|
1099
1116
|
return P._default;
|
|
1100
1117
|
}
|
|
1101
|
-
function Ge(
|
|
1102
|
-
const e = (
|
|
1118
|
+
function Ge(t) {
|
|
1119
|
+
const e = (t.split(".").pop() || "").toLowerCase();
|
|
1103
1120
|
return P[e] || P._default;
|
|
1104
1121
|
}
|
|
1105
|
-
function We(
|
|
1106
|
-
if (
|
|
1122
|
+
function We(t) {
|
|
1123
|
+
if (t == null || !Number.isFinite(t) || t < 0) return "—";
|
|
1107
1124
|
const e = ["B", "KB", "MB", "GB", "TB"];
|
|
1108
|
-
let
|
|
1109
|
-
for (;
|
|
1110
|
-
|
|
1125
|
+
let s = t, i = 0;
|
|
1126
|
+
for (; s >= 1024 && i < e.length - 1; )
|
|
1127
|
+
s /= 1024, i++;
|
|
1111
1128
|
const r = (a, c) => {
|
|
1112
|
-
const
|
|
1113
|
-
return { str:
|
|
1114
|
-
}, o = r(
|
|
1129
|
+
const f = c > 0 && Math.round(a * 10) / 10 < 10 ? 1 : 0, h = a.toFixed(f);
|
|
1130
|
+
return { str: h, rounded: Number(h) };
|
|
1131
|
+
}, o = r(s, i);
|
|
1115
1132
|
let l = o.str;
|
|
1116
|
-
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]}`;
|
|
1117
1134
|
}
|
|
1118
|
-
function Xe(
|
|
1119
|
-
if (!
|
|
1120
|
-
const e = new Date(
|
|
1121
|
-
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" });
|
|
1122
1139
|
}
|
|
1123
|
-
function Ve(
|
|
1124
|
-
return
|
|
1140
|
+
function Ve(t, e) {
|
|
1141
|
+
return t && e ? `${t} × ${e}` : "—";
|
|
1125
1142
|
}
|
|
1126
|
-
function He(
|
|
1127
|
-
let
|
|
1143
|
+
function He(t, e) {
|
|
1144
|
+
let s;
|
|
1128
1145
|
const i = ((...r) => {
|
|
1129
|
-
clearTimeout(
|
|
1146
|
+
clearTimeout(s), s = setTimeout(() => t(...r), e);
|
|
1130
1147
|
});
|
|
1131
|
-
return i.cancel = () => clearTimeout(
|
|
1148
|
+
return i.cancel = () => clearTimeout(s), i;
|
|
1132
1149
|
}
|
|
1133
1150
|
export {
|
|
1134
1151
|
E as BrowseStore,
|
|
1135
|
-
|
|
1136
|
-
|
|
1152
|
+
R as DamClient,
|
|
1153
|
+
Re as LocalFavouritesAdapter,
|
|
1137
1154
|
U as MAX_FAVOURITES,
|
|
1138
1155
|
C as PAGE_SIZE,
|
|
1139
1156
|
Le as QUALITY_LEVELS,
|
|
1140
1157
|
ze as RESIZE_PRESETS,
|
|
1141
|
-
|
|
1158
|
+
Oe as addCdnParams,
|
|
1142
1159
|
Ae as archiveDownloadUrl,
|
|
1143
1160
|
be as archiveStatusOutcome,
|
|
1144
1161
|
ve as assembleVariations,
|