@voltro/plugin-storage 0.33.0 → 0.35.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/CHANGELOG.md +1968 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +210 -203
- package/dist/rpc.js +32 -16
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
import { StorageAccessDenied as e, StorageError as t, StorageRejected as n, StorageScanRejected as r, StorageService as i } from "./types.js";
|
|
2
2
|
import { abortMultipartUploadDescriptor as a, beginMultipartUploadDescriptor as o, beginResumableUploadDescriptor as s, completeMultipartUploadDescriptor as c, finalizeUploadDescriptor as l, ingestUrlDescriptor as u, listGrantsDescriptor as d, listRefsDescriptor as f, mintPresignedUploadDescriptor as p, mintUploadTicketDescriptor as m, mintUploadUrlDescriptor as h, mintUrlDescriptor as g, revokeDescriptor as _, shareDescriptor as ee, signMultipartPartDescriptor as te, storageRpcClientImports as v, uploadDescriptor as ne } from "./rpc.js";
|
|
3
3
|
import { Chunk as y, Effect as b, Exit as x, Layer as S, Schedule as C, Stream as w } from "effect";
|
|
4
|
-
import { definePlugin as re } from "@voltro/protocol";
|
|
5
|
-
import { readCookie as
|
|
6
|
-
import { and as E, bytes as
|
|
7
|
-
import { pluginEnv as
|
|
8
|
-
import { createHmac as F, randomBytes as I, randomUUID as
|
|
9
|
-
import { spawn as
|
|
10
|
-
import { mkdtemp as
|
|
11
|
-
import { tmpdir as
|
|
4
|
+
import { definePlugin as re, pluginInstanceName as T } from "@voltro/protocol";
|
|
5
|
+
import { readCookie as ie, resolveSessionSecret as ae, verifySession as oe } from "@voltro/protocol/session";
|
|
6
|
+
import { and as E, bytes as se, eq as D, generateId as O, id as k, integer as A, json as j, mixin as ce, reference as le, table as M, text as N, timestamp as P } from "@voltro/database";
|
|
7
|
+
import { pluginEnv as ue } from "@voltro/env";
|
|
8
|
+
import { createHmac as F, randomBytes as I, randomUUID as de, scryptSync as fe, timingSafeEqual as L } from "node:crypto";
|
|
9
|
+
import { spawn as pe } from "node:child_process";
|
|
10
|
+
import { mkdtemp as me, readFile as he, rm as R, writeFile as z } from "node:fs/promises";
|
|
11
|
+
import { tmpdir as ge } from "node:os";
|
|
12
12
|
import { join as B } from "node:path";
|
|
13
13
|
//#region src/streamBridge.ts
|
|
14
|
-
var
|
|
14
|
+
var _e = 1 << 20, ve = (e, n, r = !1) => new t({
|
|
15
15
|
provider: e,
|
|
16
16
|
message: n,
|
|
17
17
|
transient: r
|
|
18
|
-
}),
|
|
18
|
+
}), ye = (e) => {
|
|
19
19
|
let t = 0;
|
|
20
20
|
for (let n of e) t += n.byteLength;
|
|
21
21
|
let n = new Uint8Array(t), r = 0;
|
|
22
22
|
for (let t of e) n.set(t, r), r += t.byteLength;
|
|
23
23
|
return n;
|
|
24
|
-
},
|
|
24
|
+
}, be = (e, t = _e) => {
|
|
25
25
|
let n = [];
|
|
26
26
|
for (let r = 0; r < e.byteLength; r += t) n.push(e.subarray(r, Math.min(r + t, e.byteLength)));
|
|
27
27
|
return w.fromIterable(n);
|
|
28
|
-
},
|
|
28
|
+
}, xe = (e) => e.pipe(w.runCollect, b.map((e) => ye(y.toReadonlyArray(e)))), Se = (e, t) => w.suspend(() => w.fromAsyncIterable(t(), (t) => ve(e, `read stream failed: ${String(t?.message ?? t)}`, !0))).pipe(w.map((e) => e instanceof Uint8Array ? e : new Uint8Array(e))), Ce = async (e) => {
|
|
29
29
|
let { Readable: t } = await import("node:stream");
|
|
30
30
|
return t.fromWeb(w.toReadableStream(e));
|
|
31
|
-
},
|
|
32
|
-
stream:
|
|
31
|
+
}, we = (e, t) => e.getStream ? e.getStream(t) : e.get(t).pipe(b.map((e) => ({
|
|
32
|
+
stream: be(e.bytes),
|
|
33
33
|
contentType: e.contentType,
|
|
34
34
|
size: e.bytes.byteLength
|
|
35
|
-
}))),
|
|
35
|
+
}))), Te = (e, t, n, r) => e.putStream ? e.putStream(t, n, r) : xe(n).pipe(b.flatMap((n) => e.put(t, n, {
|
|
36
36
|
contentType: r.contentType,
|
|
37
37
|
...r.public === void 0 ? {} : { public: r.public }
|
|
38
|
-
}))), V = "_voltro_storage_refs", H = "_voltro_storage_grants", U = "_voltro_storage_blobs",
|
|
38
|
+
}))), V = "_voltro_storage_refs", H = "_voltro_storage_grants", U = "_voltro_storage_blobs", Ee = "_voltro_storage_usage", De = M(V, {
|
|
39
39
|
id: k({ prefix: "file" }),
|
|
40
40
|
tenantId: N().nullable(),
|
|
41
41
|
ownerId: N().nullable(),
|
|
@@ -58,7 +58,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
58
58
|
derivedFrom: N().nullable(),
|
|
59
59
|
kind: N().nullable(),
|
|
60
60
|
createdAt: P()
|
|
61
|
-
}).index(["key"]).index(["tenantId"]).index(["ownerId"]).index(["folder"]).index(["derivedFrom"]),
|
|
61
|
+
}).index(["key"]).index(["tenantId"]).index(["ownerId"]).index(["folder"]).index(["derivedFrom"]), Oe = M(H, {
|
|
62
62
|
id: k({ prefix: "sgrant" }),
|
|
63
63
|
refId: N(),
|
|
64
64
|
principalType: N(),
|
|
@@ -67,19 +67,19 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
67
67
|
createdAt: P(),
|
|
68
68
|
expiresAt: P().nullable(),
|
|
69
69
|
createdBy: N().nullable()
|
|
70
|
-
}).index(["refId"]).index(["principalId"]),
|
|
70
|
+
}).index(["refId"]).index(["principalId"]), ke = M(Ee, {
|
|
71
71
|
id: k({ prefix: "susage" }),
|
|
72
72
|
tenantId: N().maxLength(191),
|
|
73
73
|
bytes: A().default(0),
|
|
74
74
|
count: A().default(0),
|
|
75
75
|
updatedAt: P()
|
|
76
|
-
}).unique("byStorageUsageTenant", ["tenantId"]),
|
|
76
|
+
}).unique("byStorageUsageTenant", ["tenantId"]), Ae = M(U, {
|
|
77
77
|
id: k({ prefix: "blob" }),
|
|
78
78
|
key: N(),
|
|
79
|
-
data:
|
|
79
|
+
data: se(),
|
|
80
80
|
contentType: N(),
|
|
81
81
|
size: A()
|
|
82
|
-
}).index(["key"]), W =
|
|
82
|
+
}).index(["key"]), W = ue([
|
|
83
83
|
{
|
|
84
84
|
name: "STORAGE_PROVIDER",
|
|
85
85
|
required: !1,
|
|
@@ -235,11 +235,11 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
235
235
|
message: n,
|
|
236
236
|
transient: r,
|
|
237
237
|
...i === void 0 ? {} : { status: i }
|
|
238
|
-
}), K = (e) => e === void 0 || e === 408 || e === 429 || e >= 500,
|
|
239
|
-
|
|
240
|
-
},
|
|
241
|
-
let t =
|
|
242
|
-
return
|
|
238
|
+
}), K = (e) => e === void 0 || e === 408 || e === 429 || e >= 500, je = /* @__PURE__ */ new Map(), Me = (e, t) => je.get(e)?.get(t)?.bytes, Ne = (e) => {
|
|
239
|
+
je.get(e)?.clear();
|
|
240
|
+
}, Pe = (e = "default") => {
|
|
241
|
+
let t = je.get(e) ?? /* @__PURE__ */ new Map();
|
|
242
|
+
return je.set(e, t), {
|
|
243
243
|
name: "memory",
|
|
244
244
|
presigns: !1,
|
|
245
245
|
put: (e, n, r) => b.sync(() => (t.set(e, {
|
|
@@ -263,7 +263,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
263
263
|
return n ? { size: n.bytes.byteLength } : null;
|
|
264
264
|
})
|
|
265
265
|
};
|
|
266
|
-
},
|
|
266
|
+
}, Fe = (e) => {
|
|
267
267
|
let t = e.root, n = async (e) => {
|
|
268
268
|
let { join: n, resolve: r, sep: i } = await import("node:path"), a = r(t), o = r(a, e);
|
|
269
269
|
if (o !== a && !o.startsWith(a + i)) throw Error(`key '${e}' escapes the storage root`);
|
|
@@ -313,7 +313,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
313
313
|
getStream: (e) => r(async () => {
|
|
314
314
|
let t = await import("node:fs/promises"), { createReadStream: r } = await import("node:fs"), i = await n(e), a = await t.stat(i);
|
|
315
315
|
return {
|
|
316
|
-
stream:
|
|
316
|
+
stream: Se("filesystem", () => r(i)),
|
|
317
317
|
contentType: "application/octet-stream",
|
|
318
318
|
size: a.size
|
|
319
319
|
};
|
|
@@ -323,7 +323,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
323
323
|
await r.mkdir(i(c), { recursive: !0 });
|
|
324
324
|
let l = `${c}.tmp-${a()}`;
|
|
325
325
|
try {
|
|
326
|
-
await s(await
|
|
326
|
+
await s(await Ce(t), o(l));
|
|
327
327
|
let e = await r.stat(l);
|
|
328
328
|
return await r.rename(l, c), { size: e.size };
|
|
329
329
|
} catch (e) {
|
|
@@ -338,10 +338,10 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
338
338
|
end: i
|
|
339
339
|
});
|
|
340
340
|
s.on("data", (e) => o.push(e)), s.on("end", () => e()), s.on("error", n);
|
|
341
|
-
}),
|
|
341
|
+
}), ye(o);
|
|
342
342
|
}, e)
|
|
343
343
|
};
|
|
344
|
-
},
|
|
344
|
+
}, Ie = (e) => {
|
|
345
345
|
let t = e.name ?? "s3", n = e.publicAcl ?? !0, r = null, i = () => r || (r = (async () => {
|
|
346
346
|
let t, n;
|
|
347
347
|
try {
|
|
@@ -490,7 +490,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
490
490
|
Key: n
|
|
491
491
|
})), s = o.Body;
|
|
492
492
|
return {
|
|
493
|
-
stream:
|
|
493
|
+
stream: Se(t, () => s),
|
|
494
494
|
contentType: o.ContentType ?? "application/octet-stream",
|
|
495
495
|
...o.ContentLength === void 0 ? {} : { size: o.ContentLength }
|
|
496
496
|
};
|
|
@@ -502,7 +502,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
502
502
|
} catch (e) {
|
|
503
503
|
throw Error("s3/minio `putStream` requires the '@aws-sdk/lib-storage' optional dependency (multipart upload). Install it to enable streamed uploads.", { cause: e });
|
|
504
504
|
}
|
|
505
|
-
let l = await
|
|
505
|
+
let l = await Ce(r);
|
|
506
506
|
return await new c.Upload({
|
|
507
507
|
client: a,
|
|
508
508
|
params: {
|
|
@@ -526,7 +526,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
526
526
|
return o(c.Body);
|
|
527
527
|
})
|
|
528
528
|
};
|
|
529
|
-
},
|
|
529
|
+
}, Le = (e) => e instanceof Uint8Array ? e : typeof e == "string" ? new Uint8Array(Buffer.from(e, "base64")) : new Uint8Array(e), Re = () => {
|
|
530
530
|
let e = null, t = () => {
|
|
531
531
|
if (!e) throw Error("the 'database' storage provider isn't bound to a DataStore yet");
|
|
532
532
|
return e;
|
|
@@ -569,7 +569,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
569
569
|
}), { size: i.byteLength };
|
|
570
570
|
}),
|
|
571
571
|
get: (e) => b.suspend(() => n(() => r(e)).pipe(b.flatMap((t) => t ? b.succeed({
|
|
572
|
-
bytes:
|
|
572
|
+
bytes: Le(t.data),
|
|
573
573
|
contentType: String(t.contentType)
|
|
574
574
|
}) : b.fail(G("database", `no object at key '${e}'`, !1, 404))))),
|
|
575
575
|
delete: (e) => n(async () => {
|
|
@@ -583,7 +583,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
583
583
|
return t ? { size: Number(t.size) } : null;
|
|
584
584
|
})
|
|
585
585
|
};
|
|
586
|
-
},
|
|
586
|
+
}, ze = (e) => {
|
|
587
587
|
let t = null, n = () => t || (t = (async () => {
|
|
588
588
|
let t;
|
|
589
589
|
try {
|
|
@@ -665,13 +665,13 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
665
665
|
getStream: (e) => r(async () => {
|
|
666
666
|
let { container: t } = await n(), r = await t.getBlockBlobClient(e).download();
|
|
667
667
|
return {
|
|
668
|
-
stream:
|
|
668
|
+
stream: Se("azure", () => r.readableStreamBody),
|
|
669
669
|
contentType: r.contentType ?? "application/octet-stream",
|
|
670
670
|
...r.contentLength === void 0 ? {} : { size: r.contentLength }
|
|
671
671
|
};
|
|
672
672
|
}),
|
|
673
673
|
putStream: (e, t, i) => r(async () => {
|
|
674
|
-
let { container: r } = await n(), a = await
|
|
674
|
+
let { container: r } = await n(), a = await Ce(t);
|
|
675
675
|
return await r.getBlockBlobClient(e).uploadStream(a, 4 * 1024 * 1024, 5, { blobHTTPHeaders: { blobContentType: i.contentType } }), { size: i.totalSize ?? (await r.getBlockBlobClient(e).getProperties()).contentLength ?? 0 };
|
|
676
676
|
}),
|
|
677
677
|
getRange: (e, t, a) => r(async () => {
|
|
@@ -679,13 +679,13 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
679
679
|
return i(o.readableStreamBody);
|
|
680
680
|
})
|
|
681
681
|
};
|
|
682
|
-
},
|
|
682
|
+
}, Be = {
|
|
683
683
|
webp: "image/webp",
|
|
684
684
|
avif: "image/avif",
|
|
685
685
|
jpeg: "image/jpeg",
|
|
686
686
|
jpg: "image/jpeg",
|
|
687
687
|
png: "image/png"
|
|
688
|
-
},
|
|
688
|
+
}, Ve = (e) => {
|
|
689
689
|
if (!e) return null;
|
|
690
690
|
let t = new URLSearchParams(e), n = (e) => {
|
|
691
691
|
let n = t.get(e);
|
|
@@ -700,7 +700,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
700
700
|
...a === void 0 ? {} : { q: a },
|
|
701
701
|
...s ? { fit: s } : {}
|
|
702
702
|
};
|
|
703
|
-
},
|
|
703
|
+
}, He = (e) => e.startsWith("image/") && !e.includes("svg"), q, Ue = async () => {
|
|
704
704
|
if (q !== void 0) return q;
|
|
705
705
|
try {
|
|
706
706
|
let e = await import("sharp");
|
|
@@ -709,9 +709,9 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
709
709
|
q = null;
|
|
710
710
|
}
|
|
711
711
|
return q;
|
|
712
|
-
},
|
|
713
|
-
if (!
|
|
714
|
-
let r = await
|
|
712
|
+
}, We = async (e, t, n) => {
|
|
713
|
+
if (!He(t)) return null;
|
|
714
|
+
let r = await Ue();
|
|
715
715
|
if (!r) return null;
|
|
716
716
|
try {
|
|
717
717
|
let i = r(Buffer.from(e), { failOn: "none" });
|
|
@@ -721,10 +721,10 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
721
721
|
fit: n.fit ?? "cover",
|
|
722
722
|
withoutEnlargement: !0
|
|
723
723
|
}));
|
|
724
|
-
let a = n.format &&
|
|
724
|
+
let a = n.format && Be[n.format] ? n.format : void 0, o = t;
|
|
725
725
|
if (a) {
|
|
726
726
|
let e = a === "jpg" ? "jpeg" : a;
|
|
727
|
-
i = i.toFormat(e, n.q === void 0 ? {} : { quality: n.q }), o =
|
|
727
|
+
i = i.toFormat(e, n.q === void 0 ? {} : { quality: n.q }), o = Be[a];
|
|
728
728
|
} else n.q !== void 0 && (t === "image/jpeg" || t === "image/webp") && (i = i.toFormat(t === "image/webp" ? "webp" : "jpeg", { quality: n.q }));
|
|
729
729
|
let s = await i.toBuffer();
|
|
730
730
|
return {
|
|
@@ -734,43 +734,43 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
734
734
|
} catch {
|
|
735
735
|
return null;
|
|
736
736
|
}
|
|
737
|
-
},
|
|
737
|
+
}, Ge = 200, J = /* @__PURE__ */ new Map(), Ke = async (e, t, n, r) => {
|
|
738
738
|
let i = `${e}::${JSON.stringify(r)}`, a = J.get(i);
|
|
739
739
|
if (a) return a;
|
|
740
|
-
let o = await
|
|
741
|
-
if (o && (J.set(i, o), J.size >
|
|
740
|
+
let o = await We(t, n, r);
|
|
741
|
+
if (o && (J.set(i, o), J.size > Ge)) {
|
|
742
742
|
let e = J.keys().next().value;
|
|
743
743
|
e !== void 0 && J.delete(e);
|
|
744
744
|
}
|
|
745
745
|
return o;
|
|
746
|
-
},
|
|
746
|
+
}, qe = (e) => {
|
|
747
747
|
let t = I(16).toString("hex");
|
|
748
|
-
return `${t}:${
|
|
749
|
-
},
|
|
748
|
+
return `${t}:${fe(e, t, 32).toString("hex")}`;
|
|
749
|
+
}, Je = (e, t) => {
|
|
750
750
|
if (!e || !t) return !1;
|
|
751
751
|
let [n, r] = t.split(":");
|
|
752
752
|
if (!n || !r) return !1;
|
|
753
|
-
let i = Buffer.from(r, "hex"), a =
|
|
753
|
+
let i = Buffer.from(r, "hex"), a = fe(e, n, i.length);
|
|
754
754
|
return a.length === i.length && L(a, i);
|
|
755
|
-
},
|
|
755
|
+
}, Ye = (e) => Array.isArray(e) ? e.filter((e) => typeof e == "string") : [], Xe = (e) => Ye(e.metadata?.roles), Ze = (e) => Ye(e.scopes), Qe = (e, t) => e.some((e) => t.includes(e)), $e = (e) => Ye(e.metadata?.groups), et = (e) => typeof e == "boolean" ? b.succeed(e) : b.isEffect(e) ? e : b.promise(() => e), tt = (e, t, n = {}) => b.gen(function* () {
|
|
756
756
|
if (t.id && e.ownerId && t.id === e.ownerId) return !0;
|
|
757
757
|
let r = e.accessPolicy ?? [];
|
|
758
758
|
if (r.length === 0) return !1;
|
|
759
|
-
let i = n.resolveGroups ? yield* b.promise(async () => await n.resolveGroups(t)) :
|
|
760
|
-
for (let a of r) if (yield*
|
|
759
|
+
let i = n.resolveGroups ? yield* b.promise(async () => await n.resolveGroups(t)) : $e(t);
|
|
760
|
+
for (let a of r) if (yield* nt(a, e, t, i, n)) return !0;
|
|
761
761
|
return !1;
|
|
762
|
-
}),
|
|
762
|
+
}), nt = (e, t, n, r, i) => b.gen(function* () {
|
|
763
763
|
let a = !1, o = (e) => (a = !0, e);
|
|
764
|
-
if (e.owner !== void 0 && e.owner && !o(!!n.id && !!t.ownerId && n.id === t.ownerId) || e.tenant !== void 0 && e.tenant && !o(!!n.tenantId && n.tenantId === t.tenantId) || e.apiKey !== void 0 && e.apiKey && !o(n.type === "apiKey") || e.roles && e.roles.length > 0 && !o(
|
|
764
|
+
if (e.owner !== void 0 && e.owner && !o(!!n.id && !!t.ownerId && n.id === t.ownerId) || e.tenant !== void 0 && e.tenant && !o(!!n.tenantId && n.tenantId === t.tenantId) || e.apiKey !== void 0 && e.apiKey && !o(n.type === "apiKey") || e.roles && e.roles.length > 0 && !o(Qe(Xe(n), e.roles)) || e.groups && e.groups.length > 0 && !o(Qe(r, e.groups)) || e.scopes && e.scopes.length > 0 && !o(Qe(Ze(n), e.scopes)) || e.password !== void 0 && e.password && !o(Je(i.password, t.passwordHash))) return !1;
|
|
765
765
|
if (e.guard) {
|
|
766
766
|
let r = i.guards?.[e.guard];
|
|
767
|
-
if (!o(r ? yield*
|
|
767
|
+
if (!o(r ? yield* et(r({
|
|
768
768
|
subject: n,
|
|
769
769
|
ref: t
|
|
770
770
|
})) : !1)) return !1;
|
|
771
771
|
}
|
|
772
772
|
return a;
|
|
773
|
-
}),
|
|
773
|
+
}), rt = (e, t) => {
|
|
774
774
|
let n = [];
|
|
775
775
|
e.id && n.push({
|
|
776
776
|
type: e.type === "apiKey" ? "apiKey" : "user",
|
|
@@ -781,20 +781,20 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
781
781
|
id: e
|
|
782
782
|
});
|
|
783
783
|
return n;
|
|
784
|
-
},
|
|
785
|
-
let a =
|
|
784
|
+
}, it = (e, t, n, r, i) => {
|
|
785
|
+
let a = rt(t, n);
|
|
786
786
|
return e.some((e) => e.expiresAt && e.expiresAt.getTime() < i || r === "write" && e.permission !== "write" ? !1 : a.some((t) => t.type === e.principalType && t.id === e.principalId));
|
|
787
|
-
},
|
|
787
|
+
}, at = (e, t) => t.resolveGroups ? b.promise(async () => await t.resolveGroups(e)) : b.succeed($e(e)), Y = () => W.read("VOLTRO_STORAGE_SECRET") ?? ae(), X = (e) => (typeof e == "string" ? Buffer.from(e, "utf8") : e).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""), Z = (e) => {
|
|
788
788
|
let t = e.replace(/-/g, "+").replace(/_/g, "/") + "=".repeat((4 - e.length % 4) % 4);
|
|
789
789
|
return Buffer.from(t, "base64");
|
|
790
|
-
},
|
|
790
|
+
}, ot = (e, t, n = Y()) => {
|
|
791
791
|
if (!n) throw Error("signGrant: secret must be a non-empty string");
|
|
792
792
|
let r = {
|
|
793
793
|
refId: e,
|
|
794
794
|
exp: Math.floor(Date.now() / 1e3) + Math.floor(t)
|
|
795
795
|
}, i = X(JSON.stringify(r));
|
|
796
796
|
return `${i}.${X(F("sha256", n).update(i).digest())}`;
|
|
797
|
-
},
|
|
797
|
+
}, st = (e, t = Y()) => {
|
|
798
798
|
if (!e || !t) return null;
|
|
799
799
|
let n = e.indexOf(".");
|
|
800
800
|
if (n <= 0 || n === e.length - 1) return null;
|
|
@@ -806,14 +806,14 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
806
806
|
} catch {
|
|
807
807
|
return null;
|
|
808
808
|
}
|
|
809
|
-
},
|
|
809
|
+
}, ct = (e, t, n = Y()) => {
|
|
810
810
|
if (!n) throw Error("signUploadTicket: secret must be a non-empty string");
|
|
811
811
|
let r = {
|
|
812
812
|
...e,
|
|
813
813
|
exp: Math.floor(Date.now() / 1e3) + Math.floor(t)
|
|
814
814
|
}, i = X(JSON.stringify(r));
|
|
815
815
|
return `${i}.${X(F("sha256", n).update(`u:${i}`).digest())}`;
|
|
816
|
-
},
|
|
816
|
+
}, lt = (e, t = Y()) => {
|
|
817
817
|
if (!e || !t) return null;
|
|
818
818
|
let n = e.indexOf(".");
|
|
819
819
|
if (n <= 0 || n === e.length - 1) return null;
|
|
@@ -825,14 +825,14 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
825
825
|
} catch {
|
|
826
826
|
return null;
|
|
827
827
|
}
|
|
828
|
-
},
|
|
828
|
+
}, ut = (e, t, n = Y()) => {
|
|
829
829
|
if (!n) throw Error("signFinalizeTicket: secret must be a non-empty string");
|
|
830
830
|
let r = {
|
|
831
831
|
...e,
|
|
832
832
|
exp: Math.floor(Date.now() / 1e3) + Math.floor(t)
|
|
833
833
|
}, i = X(JSON.stringify(r));
|
|
834
834
|
return `${i}.${X(F("sha256", n).update(`f:${i}`).digest())}`;
|
|
835
|
-
},
|
|
835
|
+
}, dt = (e, t = Y()) => {
|
|
836
836
|
if (!e || !t) return null;
|
|
837
837
|
let n = e.indexOf(".");
|
|
838
838
|
if (n <= 0 || n === e.length - 1) return null;
|
|
@@ -844,14 +844,14 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
844
844
|
} catch {
|
|
845
845
|
return null;
|
|
846
846
|
}
|
|
847
|
-
},
|
|
847
|
+
}, ft = (e, t, n = Y()) => {
|
|
848
848
|
if (!n) throw Error("signResumableTicket: secret must be a non-empty string");
|
|
849
849
|
let r = {
|
|
850
850
|
...e,
|
|
851
851
|
exp: Math.floor(Date.now() / 1e3) + Math.floor(t)
|
|
852
852
|
}, i = X(JSON.stringify(r));
|
|
853
853
|
return `${i}.${X(F("sha256", n).update(`r:${i}`).digest())}`;
|
|
854
|
-
},
|
|
854
|
+
}, pt = (e, t = Y()) => {
|
|
855
855
|
if (!e || !t) return null;
|
|
856
856
|
let n = e.indexOf(".");
|
|
857
857
|
if (n <= 0 || n === e.length - 1) return null;
|
|
@@ -863,14 +863,14 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
863
863
|
} catch {
|
|
864
864
|
return null;
|
|
865
865
|
}
|
|
866
|
-
},
|
|
866
|
+
}, mt = (e, t, n = Y()) => {
|
|
867
867
|
if (!n) throw Error("signMultipartTicket: secret must be a non-empty string");
|
|
868
868
|
let r = {
|
|
869
869
|
...e,
|
|
870
870
|
exp: Math.floor(Date.now() / 1e3) + Math.floor(t)
|
|
871
871
|
}, i = X(JSON.stringify(r));
|
|
872
872
|
return `${i}.${X(F("sha256", n).update(`m:${i}`).digest())}`;
|
|
873
|
-
},
|
|
873
|
+
}, ht = (e, t = Y()) => {
|
|
874
874
|
if (!e || !t) return null;
|
|
875
875
|
let n = e.indexOf(".");
|
|
876
876
|
if (n <= 0 || n === e.length - 1) return null;
|
|
@@ -882,14 +882,14 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
882
882
|
} catch {
|
|
883
883
|
return null;
|
|
884
884
|
}
|
|
885
|
-
},
|
|
885
|
+
}, gt = (e, t) => {
|
|
886
886
|
if (!t || t.length === 0) return !0;
|
|
887
887
|
let n = e.toLowerCase();
|
|
888
888
|
return t.some((e) => {
|
|
889
889
|
let t = e.toLowerCase();
|
|
890
890
|
return t.endsWith("/*") ? n.startsWith(t.slice(0, -1)) : n === t;
|
|
891
891
|
});
|
|
892
|
-
},
|
|
892
|
+
}, _t = [
|
|
893
893
|
{
|
|
894
894
|
ct: /^image\/png$/,
|
|
895
895
|
offset: 0,
|
|
@@ -959,21 +959,21 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
959
959
|
offset: 0,
|
|
960
960
|
magic: [31, 139]
|
|
961
961
|
}
|
|
962
|
-
],
|
|
963
|
-
let n = t.toLowerCase(), r =
|
|
962
|
+
], vt = (e, t) => {
|
|
963
|
+
let n = t.toLowerCase(), r = _t.find((e) => e.ct.test(n));
|
|
964
964
|
return r ? e.length < r.offset + r.magic.length ? !1 : r.magic.every((t, n) => e[r.offset + n] === t) : !0;
|
|
965
|
-
},
|
|
965
|
+
}, yt = (e, t, n) => n ? n.maxBytes !== void 0 && e.byteLength > n.maxBytes ? {
|
|
966
966
|
reason: "too-large",
|
|
967
967
|
detail: `${e.byteLength} bytes exceeds the ${n.maxBytes}-byte limit`
|
|
968
|
-
} :
|
|
968
|
+
} : gt(t, n.allowedContentTypes) ? n.sniff && !vt(e, t) ? {
|
|
969
969
|
reason: "content-mismatch",
|
|
970
970
|
detail: `bytes do not match the declared content type '${t}'`
|
|
971
971
|
} : null : {
|
|
972
972
|
reason: "content-type-not-allowed",
|
|
973
973
|
detail: `content type '${t}' is not in the allow-list`
|
|
974
|
-
} : null,
|
|
975
|
-
if (!
|
|
976
|
-
let r = await
|
|
974
|
+
} : null, bt = async (e, t, n) => {
|
|
975
|
+
if (!He(t)) return { bytes: e };
|
|
976
|
+
let r = await Ue();
|
|
977
977
|
if (!r) return { bytes: e };
|
|
978
978
|
try {
|
|
979
979
|
let t = e;
|
|
@@ -996,10 +996,10 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
996
996
|
} catch {
|
|
997
997
|
return { bytes: e };
|
|
998
998
|
}
|
|
999
|
-
},
|
|
999
|
+
}, xt = async (e) => {
|
|
1000
1000
|
let { createHash: t } = await import("node:crypto");
|
|
1001
1001
|
return t("sha256").update(e).digest("hex");
|
|
1002
|
-
},
|
|
1002
|
+
}, St = (e, t) => e ? `${e.replace(/\/+$/, "")}/_voltro/storage/${t}` : `/_voltro/storage/${t}`, Ct = (e, t) => {
|
|
1003
1003
|
if (t.tenantId !== void 0 && (e.tenantId ?? null) !== (t.tenantId ?? null) || t.ownerId !== void 0 && e.ownerId !== t.ownerId || !t.includeDerived && e.derivedFrom != null) return !1;
|
|
1004
1004
|
if (t.folder !== void 0) {
|
|
1005
1005
|
let n = t.folder.replace(/\/+$/, ""), r = (e.folder ?? "").replace(/\/+$/, "");
|
|
@@ -1010,7 +1010,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1010
1010
|
if (!t.tags.every((e) => n.includes(e))) return !1;
|
|
1011
1011
|
}
|
|
1012
1012
|
return !0;
|
|
1013
|
-
}, Q = (e) => e ?? "global",
|
|
1013
|
+
}, Q = (e) => e ?? "global", wt = () => {
|
|
1014
1014
|
let e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map();
|
|
1015
1015
|
return {
|
|
1016
1016
|
insert: (t) => b.sync(() => {
|
|
@@ -1050,9 +1050,9 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1050
1050
|
});
|
|
1051
1051
|
}),
|
|
1052
1052
|
listByDerivedFrom: (t) => b.sync(() => [...e.values()].filter((e) => (e.derivedFrom ?? null) === t)),
|
|
1053
|
-
listRefs: (t) => b.sync(() => [...e.values()].filter((e) =>
|
|
1053
|
+
listRefs: (t) => b.sync(() => [...e.values()].filter((e) => Ct(e, t)).sort((e, t) => t.createdAt.getTime() - e.createdAt.getTime()).slice(t.offset, t.offset + t.limit))
|
|
1054
1054
|
};
|
|
1055
|
-
},
|
|
1055
|
+
}, Tt = (e) => Array.isArray(e) && e.every((e) => typeof e == "string") ? e : null, Et = (e) => ({
|
|
1056
1056
|
id: String(e.id),
|
|
1057
1057
|
tenantId: e.tenantId ?? null,
|
|
1058
1058
|
ownerId: e.ownerId ?? null,
|
|
@@ -1070,7 +1070,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1070
1070
|
duration: e.duration ?? null,
|
|
1071
1071
|
placeholder: e.placeholder ?? null,
|
|
1072
1072
|
folder: e.folder ?? null,
|
|
1073
|
-
tags:
|
|
1073
|
+
tags: Tt(e.tags),
|
|
1074
1074
|
alt: e.alt ?? null,
|
|
1075
1075
|
caption: e.caption ?? null,
|
|
1076
1076
|
derivedFrom: e.derivedFrom ?? null,
|
|
@@ -1082,7 +1082,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1082
1082
|
message: String(e?.message ?? e),
|
|
1083
1083
|
transient: !0
|
|
1084
1084
|
})
|
|
1085
|
-
}),
|
|
1085
|
+
}), Dt = async (e, t) => (await e.query({
|
|
1086
1086
|
table: "_voltro_storage_usage",
|
|
1087
1087
|
predicate: {
|
|
1088
1088
|
column: "tenantId",
|
|
@@ -1093,7 +1093,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1093
1093
|
take: 1,
|
|
1094
1094
|
skip: void 0,
|
|
1095
1095
|
projection: void 0
|
|
1096
|
-
}))[0] ?? null,
|
|
1096
|
+
}))[0] ?? null, Ot = (e) => ({
|
|
1097
1097
|
insert: (t) => $(() => e.insert(V, { ...t })),
|
|
1098
1098
|
getById: (t) => $(async () => {
|
|
1099
1099
|
let n = await e.query({
|
|
@@ -1108,7 +1108,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1108
1108
|
skip: void 0,
|
|
1109
1109
|
projection: void 0
|
|
1110
1110
|
});
|
|
1111
|
-
return n[0] ?
|
|
1111
|
+
return n[0] ? Et(n[0]) : null;
|
|
1112
1112
|
}),
|
|
1113
1113
|
delete: (t) => $(() => e.delete(V, t)),
|
|
1114
1114
|
listRecent: (t) => $(async () => (await e.query({
|
|
@@ -1121,7 +1121,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1121
1121
|
take: t,
|
|
1122
1122
|
skip: void 0,
|
|
1123
1123
|
projection: void 0
|
|
1124
|
-
})).map(
|
|
1124
|
+
})).map(Et)),
|
|
1125
1125
|
countByKey: (t, n) => $(async () => (await e.query({
|
|
1126
1126
|
table: V,
|
|
1127
1127
|
predicate: { and: [{
|
|
@@ -1161,7 +1161,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1161
1161
|
let i = Q(t);
|
|
1162
1162
|
for (let t = 0; t < 32; t++) {
|
|
1163
1163
|
t > 0 && await new Promise((e) => setTimeout(e, t));
|
|
1164
|
-
let a = await
|
|
1164
|
+
let a = await Dt(e, i), o = a ? Number(a.bytes ?? 0) : 0, s = a ? Number(a.count ?? 0) : 0;
|
|
1165
1165
|
if (!((r?.maxBytes === void 0 || o + n.bytes <= r.maxBytes) && (r?.maxCount === void 0 || s + n.count <= r.maxCount))) return {
|
|
1166
1166
|
allowed: !1,
|
|
1167
1167
|
bytes: o,
|
|
@@ -1181,7 +1181,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1181
1181
|
let t = O({
|
|
1182
1182
|
kind: "typeid",
|
|
1183
1183
|
prefix: "susage"
|
|
1184
|
-
},
|
|
1184
|
+
}, Ee), r = await e.insertIgnore(Ee, {
|
|
1185
1185
|
id: t,
|
|
1186
1186
|
tenantId: i,
|
|
1187
1187
|
bytes: n.bytes,
|
|
@@ -1201,7 +1201,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1201
1201
|
let r = Q(t);
|
|
1202
1202
|
for (let t = 0; t < 32; t++) {
|
|
1203
1203
|
t > 0 && await new Promise((e) => setTimeout(e, t));
|
|
1204
|
-
let i = await
|
|
1204
|
+
let i = await Dt(e, r);
|
|
1205
1205
|
if (!i) return;
|
|
1206
1206
|
let a = Number(i.bytes ?? 0), o = Number(i.count ?? 0);
|
|
1207
1207
|
if (await e.updateMany("_voltro_storage_usage", {
|
|
@@ -1226,7 +1226,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1226
1226
|
take: void 0,
|
|
1227
1227
|
skip: void 0,
|
|
1228
1228
|
projection: void 0
|
|
1229
|
-
})).map(
|
|
1229
|
+
})).map(Et)),
|
|
1230
1230
|
listRefs: (t) => $(async () => {
|
|
1231
1231
|
let n = [];
|
|
1232
1232
|
t.tenantId !== void 0 && n.push({
|
|
@@ -1249,9 +1249,9 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1249
1249
|
take: void 0,
|
|
1250
1250
|
skip: void 0,
|
|
1251
1251
|
projection: void 0
|
|
1252
|
-
})).map(
|
|
1252
|
+
})).map(Et).filter((e) => Ct(e, t)).slice(t.offset, t.offset + t.limit);
|
|
1253
1253
|
})
|
|
1254
|
-
}),
|
|
1254
|
+
}), kt = () => {
|
|
1255
1255
|
let e = /* @__PURE__ */ new Map();
|
|
1256
1256
|
return {
|
|
1257
1257
|
insert: (t) => b.sync(() => {
|
|
@@ -1266,7 +1266,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1266
1266
|
for (let [n, r] of e) r.refId === t && e.delete(n);
|
|
1267
1267
|
})
|
|
1268
1268
|
};
|
|
1269
|
-
},
|
|
1269
|
+
}, At = (e) => ({
|
|
1270
1270
|
id: String(e.id),
|
|
1271
1271
|
refId: String(e.refId),
|
|
1272
1272
|
principalType: e.principalType,
|
|
@@ -1275,7 +1275,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1275
1275
|
createdAt: e.createdAt instanceof Date ? e.createdAt : new Date(String(e.createdAt)),
|
|
1276
1276
|
expiresAt: e.expiresAt ? e.expiresAt instanceof Date ? e.expiresAt : new Date(String(e.expiresAt)) : null,
|
|
1277
1277
|
createdBy: e.createdBy ?? null
|
|
1278
|
-
}),
|
|
1278
|
+
}), jt = (e) => ({
|
|
1279
1279
|
insert: (t) => $(() => e.insert(H, { ...t })),
|
|
1280
1280
|
delete: (t) => $(() => e.delete(H, t)),
|
|
1281
1281
|
getById: (t) => $(async () => {
|
|
@@ -1291,7 +1291,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1291
1291
|
skip: void 0,
|
|
1292
1292
|
projection: void 0
|
|
1293
1293
|
}))[0];
|
|
1294
|
-
return n ?
|
|
1294
|
+
return n ? At(n) : null;
|
|
1295
1295
|
}),
|
|
1296
1296
|
listByRef: (t) => $(async () => (await e.query({
|
|
1297
1297
|
table: H,
|
|
@@ -1307,7 +1307,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1307
1307
|
take: void 0,
|
|
1308
1308
|
skip: void 0,
|
|
1309
1309
|
projection: void 0
|
|
1310
|
-
})).map(
|
|
1310
|
+
})).map(At)),
|
|
1311
1311
|
deleteByRef: (t) => $(async () => {
|
|
1312
1312
|
let n = await e.query({
|
|
1313
1313
|
table: H,
|
|
@@ -1323,14 +1323,14 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1323
1323
|
});
|
|
1324
1324
|
for (let t of n) await e.delete(H, String(t.id));
|
|
1325
1325
|
})
|
|
1326
|
-
}),
|
|
1326
|
+
}), Mt = () => O({
|
|
1327
1327
|
kind: "typeid",
|
|
1328
1328
|
prefix: "file"
|
|
1329
|
-
}, V),
|
|
1329
|
+
}, V), Nt = () => O({
|
|
1330
1330
|
kind: "typeid",
|
|
1331
1331
|
prefix: "grant"
|
|
1332
|
-
}, H),
|
|
1333
|
-
let { provider: a, refStore: o, grantStore: s, bucket: c } = i, l = i.access ?? {}, u = i.attempts ?? 3, d = i.urlExpiresInSec ?? 3600, f = (e) =>
|
|
1332
|
+
}, H), Pt = (i) => {
|
|
1333
|
+
let { provider: a, refStore: o, grantStore: s, bucket: c } = i, l = i.access ?? {}, u = i.attempts ?? 3, d = i.urlExpiresInSec ?? 3600, f = (e) => St(i.publicBaseUrl, e), p = C.recurs(Math.max(0, u - 1)).pipe(C.intersect(C.exponential("100 millis")), C.whileInput((e) => e.transient)), m = (e, t, n) => [
|
|
1334
1334
|
i.tenantPrefix,
|
|
1335
1335
|
e ?? "global",
|
|
1336
1336
|
n ?? t
|
|
@@ -1374,7 +1374,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1374
1374
|
catch: () => null
|
|
1375
1375
|
}).pipe(b.catchAll(() => b.succeed(null)));
|
|
1376
1376
|
}), v = (e) => b.gen(function* () {
|
|
1377
|
-
let t =
|
|
1377
|
+
let t = yt(e.bytes, e.contentType, i.limits);
|
|
1378
1378
|
if (t) return yield* b.fail(new n(t));
|
|
1379
1379
|
if (i.scan) {
|
|
1380
1380
|
let t = yield* ee({
|
|
@@ -1384,10 +1384,10 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1384
1384
|
});
|
|
1385
1385
|
if (!t.clean) return yield* b.fail(new r({ threat: t.threat ?? "unknown" }));
|
|
1386
1386
|
}
|
|
1387
|
-
let s = yield* b.promise(() =>
|
|
1387
|
+
let s = yield* b.promise(() => bt(e.bytes, e.contentType, { normalize: i.normalizeImages ?? !1 })), l = s.bytes, u = yield* te({
|
|
1388
1388
|
bytes: l,
|
|
1389
1389
|
contentType: e.contentType
|
|
1390
|
-
}), d = s.width ?? u?.width, f = s.height ?? u?.height, h = s.placeholder ?? u?.poster, g = e.duration ?? u?.duration, _ = yield* b.promise(() =>
|
|
1390
|
+
}), d = s.width ?? u?.width, f = s.height ?? u?.height, h = s.placeholder ?? u?.poster, g = e.duration ?? u?.duration, _ = yield* b.promise(() => xt(l)), v = e.tenantId ?? null, ne = e.visibility ?? "private", S = m(v, _, e.key), C = {
|
|
1391
1391
|
bytes: l.byteLength,
|
|
1392
1392
|
count: 1
|
|
1393
1393
|
}, w = yield* o.consumeUsage(v, C, i.quota);
|
|
@@ -1398,8 +1398,8 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1398
1398
|
detail: t
|
|
1399
1399
|
}));
|
|
1400
1400
|
}
|
|
1401
|
-
let re = e.password ? yield* b.sync(() =>
|
|
1402
|
-
id:
|
|
1401
|
+
let re = e.password ? yield* b.sync(() => qe(e.password)) : null, T = {
|
|
1402
|
+
id: Mt(),
|
|
1403
1403
|
tenantId: v,
|
|
1404
1404
|
ownerId: e.ownerId ?? null,
|
|
1405
1405
|
bucket: c,
|
|
@@ -1460,12 +1460,12 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1460
1460
|
}
|
|
1461
1461
|
return r;
|
|
1462
1462
|
}), S = (e, t, n) => b.gen(function* () {
|
|
1463
|
-
if (e.visibility === "public" || (yield*
|
|
1463
|
+
if (e.visibility === "public" || (yield* tt(e, t, {
|
|
1464
1464
|
...l,
|
|
1465
1465
|
...n?.password === void 0 ? {} : { password: n.password }
|
|
1466
1466
|
}))) return !0;
|
|
1467
|
-
let r = yield*
|
|
1468
|
-
return
|
|
1467
|
+
let r = yield* at(t, l);
|
|
1468
|
+
return it(yield* s.listByRef(e.id), t, r, n?.permission ?? "read", Date.now());
|
|
1469
1469
|
}), w = (e) => {
|
|
1470
1470
|
if (e.visibility === "public") {
|
|
1471
1471
|
let t = a.publicUrl?.(e.key);
|
|
@@ -1519,7 +1519,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1519
1519
|
}));
|
|
1520
1520
|
let c = i?.expiresInSec ?? d;
|
|
1521
1521
|
if (a.presigns) return yield* a.getUrl(s.key, c);
|
|
1522
|
-
let l = yield* b.sync(() =>
|
|
1522
|
+
let l = yield* b.sync(() => ot(s.id, c));
|
|
1523
1523
|
return `${f(s.id)}?t=${l}`;
|
|
1524
1524
|
}),
|
|
1525
1525
|
mintUploadUrl: (e) => b.gen(function* () {
|
|
@@ -1535,7 +1535,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1535
1535
|
checkAccess: S,
|
|
1536
1536
|
grant: (e) => b.gen(function* () {
|
|
1537
1537
|
let t = {
|
|
1538
|
-
id:
|
|
1538
|
+
id: Nt(),
|
|
1539
1539
|
refId: e.refId,
|
|
1540
1540
|
principalType: e.principalType,
|
|
1541
1541
|
principalId: e.principalId,
|
|
@@ -1717,7 +1717,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1717
1717
|
detail: `multipart upload of ${l} bytes exceeds tenant quota`
|
|
1718
1718
|
}));
|
|
1719
1719
|
let m = {
|
|
1720
|
-
id:
|
|
1720
|
+
id: Mt(),
|
|
1721
1721
|
tenantId: e.tenantId ?? null,
|
|
1722
1722
|
ownerId: e.ownerId ?? null,
|
|
1723
1723
|
bucket: c,
|
|
@@ -1738,7 +1738,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1738
1738
|
}),
|
|
1739
1739
|
abortMultipart: (e) => b.suspend(() => a.abortMultipartUpload ? a.abortMultipartUpload(e.key, e.uploadId).pipe(b.retry(p)) : b.void)
|
|
1740
1740
|
};
|
|
1741
|
-
},
|
|
1741
|
+
}, Ft = (e) => S.succeed(i, Pt(e)), It = (e, t = 64 * 1024) => {
|
|
1742
1742
|
let n = [Buffer.from("zINSTREAM\0", "utf8")];
|
|
1743
1743
|
for (let r = 0; r < e.length; r += t) {
|
|
1744
1744
|
let i = e.subarray(r, Math.min(r + t, e.length)), a = Buffer.alloc(4);
|
|
@@ -1746,7 +1746,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1746
1746
|
}
|
|
1747
1747
|
let r = Buffer.alloc(4);
|
|
1748
1748
|
return r.writeUInt32BE(0, 0), n.push(r), Buffer.concat(n);
|
|
1749
|
-
},
|
|
1749
|
+
}, Lt = (e) => {
|
|
1750
1750
|
let t = e.replace(/\0+$/, "").trim();
|
|
1751
1751
|
if (/\bOK$/.test(t)) return { clean: !0 };
|
|
1752
1752
|
let n = /:\s*(.+?)\s+FOUND$/.exec(t);
|
|
@@ -1755,7 +1755,7 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1755
1755
|
threat: n[1] ?? "unknown"
|
|
1756
1756
|
};
|
|
1757
1757
|
throw Error(`clamav: unexpected response: ${t}`);
|
|
1758
|
-
},
|
|
1758
|
+
}, Rt = async (e, t) => {
|
|
1759
1759
|
let n = await import("node:net"), r = W.read("CLAMAV_HOST", t.host) ?? "127.0.0.1", i = W.read("CLAMAV_PORT"), a = t.port ?? (i ? Number(i) : 3310), o = t.timeoutMs ?? 3e4;
|
|
1760
1760
|
return new Promise((i, s) => {
|
|
1761
1761
|
let c = n.createConnection({
|
|
@@ -1767,20 +1767,20 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1767
1767
|
c.on("error", (e) => {
|
|
1768
1768
|
clearTimeout(u), s(e);
|
|
1769
1769
|
}), c.on("connect", () => {
|
|
1770
|
-
c.end(
|
|
1770
|
+
c.end(It(e, t.chunkSize));
|
|
1771
1771
|
}), c.on("data", (e) => {
|
|
1772
1772
|
l += e.toString("utf8");
|
|
1773
1773
|
}), c.on("close", () => {
|
|
1774
1774
|
clearTimeout(u);
|
|
1775
1775
|
try {
|
|
1776
|
-
i(
|
|
1776
|
+
i(Lt(l));
|
|
1777
1777
|
} catch (e) {
|
|
1778
1778
|
s(e);
|
|
1779
1779
|
}
|
|
1780
1780
|
});
|
|
1781
1781
|
});
|
|
1782
|
-
},
|
|
1783
|
-
let a =
|
|
1782
|
+
}, zt = (e = {}) => (t) => Rt(t.bytes, e), Bt = (e, t, n) => new Promise((r, i) => {
|
|
1783
|
+
let a = pe(e, [...t], { stdio: [
|
|
1784
1784
|
"ignore",
|
|
1785
1785
|
"ignore",
|
|
1786
1786
|
"pipe"
|
|
@@ -1794,21 +1794,21 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1794
1794
|
}), a.on("close", (e) => {
|
|
1795
1795
|
clearTimeout(s), e === 0 ? r() : i(/* @__PURE__ */ Error(`ffmpeg exited ${String(e)}: ${o.slice(-400)}`));
|
|
1796
1796
|
});
|
|
1797
|
-
}),
|
|
1798
|
-
let n = e.ffmpegPath ?? "ffmpeg", r = e.timeoutMs ?? 5 * 6e4, i = await
|
|
1797
|
+
}), Vt = (e) => async ({ bytes: t }) => {
|
|
1798
|
+
let n = e.ffmpegPath ?? "ffmpeg", r = e.timeoutMs ?? 5 * 6e4, i = await me(B(ge(), "voltro-tc-")), a = B(i, "in"), o = [];
|
|
1799
1799
|
try {
|
|
1800
1800
|
await z(a, t);
|
|
1801
1801
|
for (let t of e.renditions) {
|
|
1802
1802
|
let e = B(i, `out.${t.ext}`);
|
|
1803
1803
|
try {
|
|
1804
|
-
await
|
|
1804
|
+
await Bt(n, [
|
|
1805
1805
|
"-y",
|
|
1806
1806
|
"-i",
|
|
1807
1807
|
a,
|
|
1808
1808
|
...t.args,
|
|
1809
1809
|
e
|
|
1810
1810
|
], r);
|
|
1811
|
-
let i = await
|
|
1811
|
+
let i = await he(e);
|
|
1812
1812
|
o.push({
|
|
1813
1813
|
bytes: new Uint8Array(i),
|
|
1814
1814
|
contentType: t.contentType,
|
|
@@ -1827,21 +1827,21 @@ var ge = 1 << 20, _e = (e, n, r = !1) => new t({
|
|
|
1827
1827
|
};
|
|
1828
1828
|
//#endregion
|
|
1829
1829
|
//#region src/assetRef.ts
|
|
1830
|
-
function
|
|
1831
|
-
let t = e.nullable ?? !0, n = e.fk === !1 ? N() :
|
|
1830
|
+
function Ht(e = {}) {
|
|
1831
|
+
let t = e.nullable ?? !0, n = e.fk === !1 ? N() : le(() => De, { onDelete: e.onDelete ?? "setNull" });
|
|
1832
1832
|
return t ? n.nullable() : n;
|
|
1833
1833
|
}
|
|
1834
|
-
var
|
|
1834
|
+
var Ut = () => ce({
|
|
1835
1835
|
id: "@voltro/plugin-storage/withStorage",
|
|
1836
|
-
fields: { asset:
|
|
1837
|
-
}),
|
|
1836
|
+
fields: { asset: Ht() }
|
|
1837
|
+
}), Wt = {
|
|
1838
1838
|
"image/png": "png",
|
|
1839
1839
|
"image/jpeg": "jpg",
|
|
1840
1840
|
"image/jpg": "jpg",
|
|
1841
1841
|
"image/gif": "gif",
|
|
1842
1842
|
"image/webp": "webp",
|
|
1843
1843
|
"image/svg+xml": "svg"
|
|
1844
|
-
},
|
|
1844
|
+
}, Gt = (e) => {
|
|
1845
1845
|
let t = /^data:([^;,]+)(;base64)?,(.*)$/s.exec(e);
|
|
1846
1846
|
if (!t) throw Error("not a data URI");
|
|
1847
1847
|
let n = t[1] || "application/octet-stream", r = !!t[2], i = t[3] ?? "";
|
|
@@ -1849,16 +1849,16 @@ var Ht = () => se({
|
|
|
1849
1849
|
bytes: r ? new Uint8Array(Buffer.from(i, "base64")) : new Uint8Array(Buffer.from(decodeURIComponent(i), "utf8")),
|
|
1850
1850
|
contentType: n
|
|
1851
1851
|
};
|
|
1852
|
-
},
|
|
1852
|
+
}, Kt = (e, n) => b.gen(function* () {
|
|
1853
1853
|
let r = yield* b.try({
|
|
1854
|
-
try: () =>
|
|
1854
|
+
try: () => Gt(n.dataUri),
|
|
1855
1855
|
catch: (e) => new t({
|
|
1856
1856
|
provider: "avatar",
|
|
1857
1857
|
message: String(e?.message ?? e),
|
|
1858
1858
|
transient: !1,
|
|
1859
1859
|
status: 400
|
|
1860
1860
|
})
|
|
1861
|
-
}), i =
|
|
1861
|
+
}), i = Wt[r.contentType] ?? "bin";
|
|
1862
1862
|
return yield* e.put({
|
|
1863
1863
|
bytes: r.bytes,
|
|
1864
1864
|
contentType: r.contentType,
|
|
@@ -1867,16 +1867,16 @@ var Ht = () => se({
|
|
|
1867
1867
|
visibility: "public",
|
|
1868
1868
|
key: `avatars/${n.userId}/avatar.${i}`
|
|
1869
1869
|
});
|
|
1870
|
-
}),
|
|
1871
|
-
|
|
1872
|
-
},
|
|
1870
|
+
}), qt = W.read("VOLTRO_SESSION_COOKIE") ?? "voltro:session", Jt, Yt = (e) => {
|
|
1871
|
+
Jt = e;
|
|
1872
|
+
}, Xt = () => Jt ?? Zt({}), Zt = (e) => {
|
|
1873
1873
|
if (e.provider && typeof e.provider == "object") return e.provider;
|
|
1874
1874
|
let t = (e.provider ?? W.read("STORAGE_PROVIDER") ?? "memory").toLowerCase(), n = W.read("S3_BUCKET", e.bucket) ?? W.read("STORAGE_BUCKET") ?? "voltro";
|
|
1875
1875
|
switch (t) {
|
|
1876
1876
|
case "s3":
|
|
1877
1877
|
case "minio": {
|
|
1878
1878
|
let r = W.read("S3_REGION", e.region) ?? W.read("AWS_REGION"), i = W.read("S3_ENDPOINT", e.endpoint) ?? W.read("MINIO_ENDPOINT"), a = W.read("S3_ACCESS_KEY_ID", e.accessKeyId) ?? W.read("AWS_ACCESS_KEY_ID"), o = W.read("S3_SECRET_ACCESS_KEY", e.secretAccessKey) ?? W.read("AWS_SECRET_ACCESS_KEY"), s = W.read("STORAGE_CDN_URL", e.cdnBaseUrl);
|
|
1879
|
-
return
|
|
1879
|
+
return Ie({
|
|
1880
1880
|
bucket: n,
|
|
1881
1881
|
name: t,
|
|
1882
1882
|
...r ? { region: r } : {},
|
|
@@ -1890,7 +1890,7 @@ var Ht = () => se({
|
|
|
1890
1890
|
}
|
|
1891
1891
|
case "azure": {
|
|
1892
1892
|
let t = W.read("AZURE_STORAGE_ACCOUNT", e.accountName), r = W.read("AZURE_STORAGE_KEY", e.accountKey), i = W.read("AZURE_STORAGE_CONNECTION_STRING", e.connectionString), a = W.read("AZURE_STORAGE_ENDPOINT", e.endpoint), o = W.read("STORAGE_CDN_URL", e.cdnBaseUrl);
|
|
1893
|
-
return
|
|
1893
|
+
return ze({
|
|
1894
1894
|
container: W.read("AZURE_STORAGE_CONTAINER", e.bucket) ?? n,
|
|
1895
1895
|
...t ? { accountName: t } : {},
|
|
1896
1896
|
...r ? { accountKey: r } : {},
|
|
@@ -1899,15 +1899,15 @@ var Ht = () => se({
|
|
|
1899
1899
|
...o ? { cdnBaseUrl: o } : {}
|
|
1900
1900
|
});
|
|
1901
1901
|
}
|
|
1902
|
-
case "database": return
|
|
1903
|
-
case "filesystem": return
|
|
1904
|
-
default: return
|
|
1902
|
+
case "database": return Re();
|
|
1903
|
+
case "filesystem": return Fe({ root: W.read("STORAGE_ROOT", e.root) ?? ".voltro-storage" });
|
|
1904
|
+
default: return Pe(e.name ?? "default");
|
|
1905
1905
|
}
|
|
1906
|
-
},
|
|
1906
|
+
}, Qt = (e) => {
|
|
1907
1907
|
if (e !== void 0) return e;
|
|
1908
1908
|
let t = W.read("STORAGE_ALLOWED_ORIGINS");
|
|
1909
1909
|
return t ? t.trim() === "*" ? "*" : t.split(",").map((e) => e.trim()).filter(Boolean) : [];
|
|
1910
|
-
},
|
|
1910
|
+
}, $t = (e, t) => {
|
|
1911
1911
|
if (!e || t !== "*" && !t.includes(e)) return {};
|
|
1912
1912
|
let n = {
|
|
1913
1913
|
"access-control-allow-origin": t === "*" ? "*" : e,
|
|
@@ -1917,7 +1917,7 @@ var Ht = () => se({
|
|
|
1917
1917
|
vary: "Origin"
|
|
1918
1918
|
};
|
|
1919
1919
|
return t !== "*" && (n["access-control-allow-credentials"] = "true"), n;
|
|
1920
|
-
},
|
|
1920
|
+
}, en = (e) => ({
|
|
1921
1921
|
id: e.id,
|
|
1922
1922
|
tenantId: e.tenantId,
|
|
1923
1923
|
ownerId: e.ownerId,
|
|
@@ -1940,18 +1940,18 @@ var Ht = () => se({
|
|
|
1940
1940
|
caption: e.caption ?? null,
|
|
1941
1941
|
derivedFrom: e.derivedFrom ?? null,
|
|
1942
1942
|
kind: e.kind ?? null
|
|
1943
|
-
}),
|
|
1943
|
+
}), tn = () => new t({
|
|
1944
1944
|
provider: "storage",
|
|
1945
1945
|
message: "not permitted to administer sharing for this object",
|
|
1946
1946
|
transient: !1,
|
|
1947
1947
|
status: 403
|
|
1948
|
-
}),
|
|
1948
|
+
}), nn = (e, t, n) => {
|
|
1949
1949
|
let r = n.request.subject;
|
|
1950
|
-
return (r.scopes ?? []).includes("admin:full") ? b.void : e.head(t, { tenantId: r.tenantId ?? null }).pipe(b.catchAll(() => b.fail(
|
|
1950
|
+
return (r.scopes ?? []).includes("admin:full") ? b.void : e.head(t, { tenantId: r.tenantId ?? null }).pipe(b.catchAll(() => b.fail(tn())), b.flatMap((e) => {
|
|
1951
1951
|
let t = e?.ownerId;
|
|
1952
|
-
return t != null && t === r.id ? b.void : b.fail(
|
|
1952
|
+
return t != null && t === r.id ? b.void : b.fail(tn());
|
|
1953
1953
|
}));
|
|
1954
|
-
},
|
|
1954
|
+
}, rn = (e) => ({
|
|
1955
1955
|
id: e.id,
|
|
1956
1956
|
refId: e.refId,
|
|
1957
1957
|
principalType: e.principalType,
|
|
@@ -1960,10 +1960,10 @@ var Ht = () => se({
|
|
|
1960
1960
|
createdAt: e.createdAt.toISOString(),
|
|
1961
1961
|
expiresAt: e.expiresAt ? e.expiresAt.toISOString() : null,
|
|
1962
1962
|
createdBy: e.createdBy
|
|
1963
|
-
}),
|
|
1964
|
-
let y =
|
|
1965
|
-
|
|
1966
|
-
let x = W.read("S3_BUCKET", i.bucket) ?? W.read("STORAGE_BUCKET") ?? "voltro", S = W.read("VOLTRO_PUBLIC_URL", i.publicBaseUrl), C =
|
|
1963
|
+
}), an = "@voltro/plugin-storage", on = (i = {}) => {
|
|
1964
|
+
let y = Zt(i);
|
|
1965
|
+
Yt(y);
|
|
1966
|
+
let x = W.read("S3_BUCKET", i.bucket) ?? W.read("STORAGE_BUCKET") ?? "voltro", S = W.read("VOLTRO_PUBLIC_URL", i.publicBaseUrl), C = Qt(i.allowedOrigins), w = i.limits?.maxBytes, E = 5 * 1024 * 1024, se = 6 * 3600, D = i.refStore === void 0 || i.refStore === "memory", O = i.grantStore === void 0 || i.grantStore === "memory", k = { current: D ? wt() : i.refStore }, A = { current: O ? kt() : i.grantStore }, j = {
|
|
1967
1967
|
insert: (e) => k.current.insert(e),
|
|
1968
1968
|
getById: (e) => k.current.getById(e),
|
|
1969
1969
|
delete: (e) => k.current.delete(e),
|
|
@@ -1974,16 +1974,16 @@ var Ht = () => se({
|
|
|
1974
1974
|
releaseUsage: (e, t) => k.current.releaseUsage(e, t),
|
|
1975
1975
|
listByDerivedFrom: (e) => k.current.listByDerivedFrom(e),
|
|
1976
1976
|
listRefs: (e) => k.current.listRefs(e)
|
|
1977
|
-
},
|
|
1977
|
+
}, ce = {
|
|
1978
1978
|
insert: (e) => A.current.insert(e),
|
|
1979
1979
|
delete: (e) => A.current.delete(e),
|
|
1980
1980
|
getById: (e) => A.current.getById(e),
|
|
1981
1981
|
listByRef: (e) => A.current.listByRef(e),
|
|
1982
1982
|
deleteByRef: (e) => A.current.deleteByRef(e)
|
|
1983
|
-
},
|
|
1983
|
+
}, le = {
|
|
1984
1984
|
provider: y,
|
|
1985
1985
|
refStore: j,
|
|
1986
|
-
grantStore:
|
|
1986
|
+
grantStore: ce,
|
|
1987
1987
|
bucket: x,
|
|
1988
1988
|
...i.tenantPrefix === void 0 ? {} : { tenantPrefix: i.tenantPrefix },
|
|
1989
1989
|
...i.attempts === void 0 ? {} : { attempts: i.attempts },
|
|
@@ -1997,7 +1997,7 @@ var Ht = () => se({
|
|
|
1997
1997
|
...S ? { publicBaseUrl: S } : {},
|
|
1998
1998
|
...i.normalizeImages === void 0 ? {} : { normalizeImages: i.normalizeImages },
|
|
1999
1999
|
...i.quota === void 0 ? {} : { quota: i.quota }
|
|
2000
|
-
}, M =
|
|
2000
|
+
}, M = Ft(le), N = Pt(le), P = (e) => b.runPromise(e.pipe(b.catchAll(() => b.succeed(null)))), ue = (e, t) => {
|
|
2001
2001
|
if (!e) return "invalid";
|
|
2002
2002
|
let n = /^bytes=(\d*)-(\d*)$/.exec(e.trim());
|
|
2003
2003
|
if (!n) return "invalid";
|
|
@@ -2021,7 +2021,7 @@ var Ht = () => se({
|
|
|
2021
2021
|
}, F = /^(?:image\/(?!svg)|video\/|audio\/|application\/pdf(?:;|$)|text\/plain(?:;|$))/i, I = (e) => ({
|
|
2022
2022
|
"x-content-type-options": "nosniff",
|
|
2023
2023
|
"content-disposition": F.test(e) ? "inline" : "attachment"
|
|
2024
|
-
}),
|
|
2024
|
+
}), fe = async (e, t, n, r) => {
|
|
2025
2025
|
if (n) {
|
|
2026
2026
|
let r = await P(N.get(e.id));
|
|
2027
2027
|
if (!r) return {
|
|
@@ -2029,7 +2029,7 @@ var Ht = () => se({
|
|
|
2029
2029
|
body: "not found",
|
|
2030
2030
|
contentType: "text/plain"
|
|
2031
2031
|
};
|
|
2032
|
-
let i = await
|
|
2032
|
+
let i = await Ke(e.id, r.bytes, e.contentType, n).catch(() => null), a = i ? i.bytes : r.bytes, o = i ? i.contentType : e.contentType;
|
|
2033
2033
|
return {
|
|
2034
2034
|
status: 200,
|
|
2035
2035
|
body: a,
|
|
@@ -2041,7 +2041,7 @@ var Ht = () => se({
|
|
|
2041
2041
|
}
|
|
2042
2042
|
};
|
|
2043
2043
|
}
|
|
2044
|
-
let i = r === void 0 ? "invalid" :
|
|
2044
|
+
let i = r === void 0 ? "invalid" : ue(r, e.size);
|
|
2045
2045
|
if (i === "unsatisfiable") return {
|
|
2046
2046
|
status: 416,
|
|
2047
2047
|
body: "range not satisfiable",
|
|
@@ -2097,7 +2097,7 @@ var Ht = () => se({
|
|
|
2097
2097
|
body: "not found",
|
|
2098
2098
|
contentType: "text/plain"
|
|
2099
2099
|
};
|
|
2100
|
-
let r =
|
|
2100
|
+
let r = Ve(e.query), i = e.headers.range;
|
|
2101
2101
|
if (n.visibility === "public") {
|
|
2102
2102
|
let e = y.publicUrl?.(n.key) ?? null;
|
|
2103
2103
|
return e && !r ? {
|
|
@@ -2106,15 +2106,15 @@ var Ht = () => se({
|
|
|
2106
2106
|
location: e,
|
|
2107
2107
|
"cache-control": "public, max-age=300"
|
|
2108
2108
|
}
|
|
2109
|
-
} :
|
|
2109
|
+
} : fe(n, "public, max-age=31536000, immutable", r, i);
|
|
2110
2110
|
}
|
|
2111
2111
|
let a = !1, o = e.query ? new URLSearchParams(e.query).get("t") : null;
|
|
2112
2112
|
if (o) {
|
|
2113
|
-
let e =
|
|
2113
|
+
let e = st(o);
|
|
2114
2114
|
a = !!e && e.refId === t;
|
|
2115
2115
|
}
|
|
2116
2116
|
if (!a) {
|
|
2117
|
-
let t =
|
|
2117
|
+
let t = ie(e.headers.cookie, qt), r = t ? oe(t, ae()) : null;
|
|
2118
2118
|
r && (a = await P(N.checkAccess(n, r)) === !0);
|
|
2119
2119
|
}
|
|
2120
2120
|
if (!a) return {
|
|
@@ -2132,12 +2132,12 @@ var Ht = () => se({
|
|
|
2132
2132
|
}
|
|
2133
2133
|
};
|
|
2134
2134
|
}
|
|
2135
|
-
return
|
|
2136
|
-
},
|
|
2135
|
+
return fe(n, "private, no-store", r, i);
|
|
2136
|
+
}, pe = {
|
|
2137
2137
|
method: "GET",
|
|
2138
2138
|
path: "/_voltro/storage",
|
|
2139
2139
|
handle: async (e) => {
|
|
2140
|
-
let t = await L(e), n =
|
|
2140
|
+
let t = await L(e), n = $t(e.headers.origin, C);
|
|
2141
2141
|
return Object.keys(n).length === 0 ? t : {
|
|
2142
2142
|
...t,
|
|
2143
2143
|
headers: {
|
|
@@ -2146,11 +2146,12 @@ var Ht = () => se({
|
|
|
2146
2146
|
}
|
|
2147
2147
|
};
|
|
2148
2148
|
}
|
|
2149
|
-
},
|
|
2149
|
+
}, me = {
|
|
2150
2150
|
method: "*",
|
|
2151
2151
|
path: "/_voltro/storage/upload",
|
|
2152
|
+
originGuard: "exempt",
|
|
2152
2153
|
handle: async (e) => {
|
|
2153
|
-
let t =
|
|
2154
|
+
let t = $t(e.headers.origin, C);
|
|
2154
2155
|
if (e.method === "OPTIONS") return {
|
|
2155
2156
|
status: 204,
|
|
2156
2157
|
headers: t
|
|
@@ -2161,7 +2162,7 @@ var Ht = () => se({
|
|
|
2161
2162
|
contentType: "text/plain",
|
|
2162
2163
|
headers: t
|
|
2163
2164
|
};
|
|
2164
|
-
let n = e.query ? new URLSearchParams(e.query).get("ticket") : null, r = n ?
|
|
2165
|
+
let n = e.query ? new URLSearchParams(e.query).get("ticket") : null, r = n ? lt(n) : null;
|
|
2165
2166
|
if (!r) return {
|
|
2166
2167
|
status: 401,
|
|
2167
2168
|
body: "invalid or expired upload ticket",
|
|
@@ -2237,16 +2238,17 @@ var Ht = () => se({
|
|
|
2237
2238
|
headers: t
|
|
2238
2239
|
};
|
|
2239
2240
|
}
|
|
2240
|
-
},
|
|
2241
|
+
}, he = {
|
|
2241
2242
|
method: "*",
|
|
2242
2243
|
path: "/_voltro/storage/upload/resumable",
|
|
2244
|
+
originGuard: "exempt",
|
|
2243
2245
|
handle: async (e) => {
|
|
2244
|
-
let t =
|
|
2246
|
+
let t = $t(e.headers.origin, C);
|
|
2245
2247
|
if (e.method === "OPTIONS") return {
|
|
2246
2248
|
status: 204,
|
|
2247
2249
|
headers: t
|
|
2248
2250
|
};
|
|
2249
|
-
let n = new URLSearchParams(e.query || ""), r =
|
|
2251
|
+
let n = new URLSearchParams(e.query || ""), r = pt(n.get("token") ?? "");
|
|
2250
2252
|
if (!r) return {
|
|
2251
2253
|
status: 401,
|
|
2252
2254
|
body: "invalid or expired resumable token",
|
|
@@ -2370,7 +2372,7 @@ var Ht = () => se({
|
|
|
2370
2372
|
kind: "json",
|
|
2371
2373
|
status: e,
|
|
2372
2374
|
data: { error: t }
|
|
2373
|
-
}),
|
|
2375
|
+
}), ge = (e, t) => {
|
|
2374
2376
|
try {
|
|
2375
2377
|
return new URL(e, "http://localhost").searchParams.get(t);
|
|
2376
2378
|
} catch {
|
|
@@ -2381,7 +2383,7 @@ var Ht = () => se({
|
|
|
2381
2383
|
method: "GET",
|
|
2382
2384
|
path: "/refs",
|
|
2383
2385
|
description: "Recent storage refs (newest first)",
|
|
2384
|
-
handler: () => j.listRecent(100).pipe(b.map((e) => R({ refs: e.map(
|
|
2386
|
+
handler: () => j.listRecent(100).pipe(b.map((e) => R({ refs: e.map(en) })), b.catchAll((e) => b.succeed(z(500, e.message))))
|
|
2385
2387
|
},
|
|
2386
2388
|
{
|
|
2387
2389
|
method: "GET",
|
|
@@ -2412,8 +2414,8 @@ var Ht = () => se({
|
|
|
2412
2414
|
path: "/grants",
|
|
2413
2415
|
description: "Grants for a ref (?refId=…)",
|
|
2414
2416
|
handler: (e) => {
|
|
2415
|
-
let t =
|
|
2416
|
-
return t ?
|
|
2417
|
+
let t = ge(e.url, "refId");
|
|
2418
|
+
return t ? ce.listByRef(t).pipe(b.map((e) => R({ grants: e.map(rn) })), b.catchAll((e) => b.succeed(z(500, e.message)))) : b.succeed(z(400, "refId query param required"));
|
|
2417
2419
|
}
|
|
2418
2420
|
},
|
|
2419
2421
|
{
|
|
@@ -2438,7 +2440,7 @@ var Ht = () => se({
|
|
|
2438
2440
|
...n.permission ? { permission: n.permission } : {},
|
|
2439
2441
|
expiresAt: r
|
|
2440
2442
|
});
|
|
2441
|
-
return R({ grant:
|
|
2443
|
+
return R({ grant: rn(i) });
|
|
2442
2444
|
}).pipe(b.catchAll((e) => b.succeed(z(e.status ?? 500, e.message ?? "share failed"))))
|
|
2443
2445
|
},
|
|
2444
2446
|
{
|
|
@@ -2458,7 +2460,7 @@ var Ht = () => se({
|
|
|
2458
2460
|
return n.grantId ? (yield* N.revoke(n.grantId), R({ ok: !0 })) : z(400, "grantId required");
|
|
2459
2461
|
}).pipe(b.catchAll((e) => b.succeed(z(e.status ?? 500, e.message ?? "revoke failed"))))
|
|
2460
2462
|
}
|
|
2461
|
-
],
|
|
2463
|
+
], _e = [
|
|
2462
2464
|
{
|
|
2463
2465
|
...g,
|
|
2464
2466
|
execute: (e, t) => {
|
|
@@ -2486,7 +2488,7 @@ var Ht = () => se({
|
|
|
2486
2488
|
execute: (e, t) => {
|
|
2487
2489
|
let n = e;
|
|
2488
2490
|
return b.sync(() => {
|
|
2489
|
-
let e = n.expiresInSec ?? 900, r =
|
|
2491
|
+
let e = n.expiresInSec ?? 900, r = ct({
|
|
2490
2492
|
sub: t.request.subject.id,
|
|
2491
2493
|
tenant: t.request.subject.tenantId,
|
|
2492
2494
|
ct: n.contentType,
|
|
@@ -2514,7 +2516,7 @@ var Ht = () => se({
|
|
|
2514
2516
|
tenantId: t.request.subject.tenantId,
|
|
2515
2517
|
...n.expiresInSec === void 0 ? {} : { expiresInSec: n.expiresInSec }
|
|
2516
2518
|
}).pipe(b.map((e) => {
|
|
2517
|
-
let r =
|
|
2519
|
+
let r = ut({
|
|
2518
2520
|
key: e.key,
|
|
2519
2521
|
sub: t.request.subject.id,
|
|
2520
2522
|
tenant: t.request.subject.tenantId,
|
|
@@ -2537,7 +2539,7 @@ var Ht = () => se({
|
|
|
2537
2539
|
{
|
|
2538
2540
|
...l,
|
|
2539
2541
|
execute: (e, n) => {
|
|
2540
|
-
let r =
|
|
2542
|
+
let r = dt(e.finalizeToken);
|
|
2541
2543
|
return r ? r.sub !== null && r.sub !== n.request.subject.id ? b.fail(new t({
|
|
2542
2544
|
provider: "storage",
|
|
2543
2545
|
message: "finalize token belongs to another subject",
|
|
@@ -2573,10 +2575,10 @@ var Ht = () => se({
|
|
|
2573
2575
|
execute: (e, t) => {
|
|
2574
2576
|
let n = e;
|
|
2575
2577
|
return b.sync(() => {
|
|
2576
|
-
let e = n.expiresInSec ??
|
|
2578
|
+
let e = n.expiresInSec ?? se, r = de(), i = n.chunkSize && n.chunkSize > 0 ? n.chunkSize : E;
|
|
2577
2579
|
return {
|
|
2578
2580
|
uploadId: r,
|
|
2579
|
-
resumableToken:
|
|
2581
|
+
resumableToken: ft({
|
|
2580
2582
|
id: r,
|
|
2581
2583
|
sub: t.request.subject.id,
|
|
2582
2584
|
tenant: t.request.subject.tenantId,
|
|
@@ -2599,14 +2601,14 @@ var Ht = () => se({
|
|
|
2599
2601
|
{
|
|
2600
2602
|
...o,
|
|
2601
2603
|
execute: (e, t) => {
|
|
2602
|
-
let n = e, r = n.expiresInSec ??
|
|
2604
|
+
let n = e, r = n.expiresInSec ?? se;
|
|
2603
2605
|
return N.beginMultipartUpload({
|
|
2604
2606
|
contentType: n.contentType,
|
|
2605
2607
|
tenantId: t.request.subject.tenantId,
|
|
2606
2608
|
visibility: n.visibility ?? "private",
|
|
2607
2609
|
expiresInSec: r
|
|
2608
2610
|
}).pipe(b.map((e) => ({
|
|
2609
|
-
multipartToken:
|
|
2611
|
+
multipartToken: mt({
|
|
2610
2612
|
key: e.key,
|
|
2611
2613
|
uploadId: e.uploadId,
|
|
2612
2614
|
sub: t.request.subject.id,
|
|
@@ -2627,7 +2629,7 @@ var Ht = () => se({
|
|
|
2627
2629
|
{
|
|
2628
2630
|
...te,
|
|
2629
2631
|
execute: (e) => {
|
|
2630
|
-
let n = e, r =
|
|
2632
|
+
let n = e, r = ht(n.multipartToken);
|
|
2631
2633
|
return r ? !Number.isInteger(n.partNumber) || n.partNumber < 1 ? b.fail(new t({
|
|
2632
2634
|
provider: "storage",
|
|
2633
2635
|
message: "partNumber must be a positive integer",
|
|
@@ -2648,7 +2650,7 @@ var Ht = () => se({
|
|
|
2648
2650
|
{
|
|
2649
2651
|
...c,
|
|
2650
2652
|
execute: (e, n) => {
|
|
2651
|
-
let r = e, i =
|
|
2653
|
+
let r = e, i = ht(r.multipartToken);
|
|
2652
2654
|
return i ? i.sub !== null && i.sub !== n.request.subject.id ? b.fail(new t({
|
|
2653
2655
|
provider: "storage",
|
|
2654
2656
|
message: "multipart token belongs to another subject",
|
|
@@ -2681,7 +2683,7 @@ var Ht = () => se({
|
|
|
2681
2683
|
{
|
|
2682
2684
|
...a,
|
|
2683
2685
|
execute: (e) => {
|
|
2684
|
-
let n =
|
|
2686
|
+
let n = ht(e.multipartToken);
|
|
2685
2687
|
return n ? N.abortMultipart({
|
|
2686
2688
|
key: n.key,
|
|
2687
2689
|
uploadId: n.uploadId
|
|
@@ -2734,7 +2736,7 @@ var Ht = () => se({
|
|
|
2734
2736
|
...ee,
|
|
2735
2737
|
execute: (e, t) => {
|
|
2736
2738
|
let n = e, r = n.expiresInDays ? new Date(Date.now() + n.expiresInDays * 864e5) : null;
|
|
2737
|
-
return
|
|
2739
|
+
return nn(N, n.refId, t).pipe(b.flatMap(() => N.grant({
|
|
2738
2740
|
refId: n.refId,
|
|
2739
2741
|
principalType: n.principalType,
|
|
2740
2742
|
principalId: n.principalId,
|
|
@@ -2748,14 +2750,14 @@ var Ht = () => se({
|
|
|
2748
2750
|
..._,
|
|
2749
2751
|
execute: (e, t) => {
|
|
2750
2752
|
let n = e;
|
|
2751
|
-
return N.getGrant(n.grantId).pipe(b.flatMap((e) => e === null ? b.fail(
|
|
2753
|
+
return N.getGrant(n.grantId).pipe(b.flatMap((e) => e === null ? b.fail(tn()) : nn(N, e.refId, t)), b.flatMap(() => N.revoke(n.grantId)), b.map(() => ({ ok: !0 })));
|
|
2752
2754
|
}
|
|
2753
2755
|
},
|
|
2754
2756
|
{
|
|
2755
2757
|
...d,
|
|
2756
2758
|
execute: (e, t) => {
|
|
2757
2759
|
let n = e;
|
|
2758
|
-
return
|
|
2760
|
+
return nn(N, n.refId, t).pipe(b.flatMap(() => N.listGrants(n.refId)), b.map((e) => ({ grants: e.map(rn) })));
|
|
2759
2761
|
}
|
|
2760
2762
|
},
|
|
2761
2763
|
{
|
|
@@ -2771,14 +2773,19 @@ var Ht = () => se({
|
|
|
2771
2773
|
...n.limit === void 0 ? {} : { limit: n.limit },
|
|
2772
2774
|
...n.offset === void 0 ? {} : { offset: n.offset }
|
|
2773
2775
|
}).pipe(b.map((e) => ({
|
|
2774
|
-
refs: e.refs.map(
|
|
2776
|
+
refs: e.refs.map(en),
|
|
2775
2777
|
nextOffset: e.nextOffset
|
|
2776
2778
|
})));
|
|
2777
2779
|
}
|
|
2778
2780
|
}
|
|
2779
2781
|
];
|
|
2780
2782
|
return re({
|
|
2781
|
-
name:
|
|
2783
|
+
name: T({
|
|
2784
|
+
base: an,
|
|
2785
|
+
alias: i.alias,
|
|
2786
|
+
instance: i.name
|
|
2787
|
+
}),
|
|
2788
|
+
baseName: an,
|
|
2782
2789
|
description: "File storage — StorageService over S3 / MinIO / filesystem / memory. Public objects served direct from bucket/CDN; private objects gated by an access policy + per-object grants. Checksums, tenant key-prefixing, _voltro_storage_refs + _voltro_storage_grants, retry.",
|
|
2783
2790
|
permissions: [
|
|
2784
2791
|
"network:outbound:*",
|
|
@@ -2789,11 +2796,11 @@ var Ht = () => se({
|
|
|
2789
2796
|
services: M,
|
|
2790
2797
|
inspectEndpoints: B,
|
|
2791
2798
|
httpRoutes: [
|
|
2792
|
-
fe,
|
|
2793
2799
|
pe,
|
|
2794
|
-
me
|
|
2800
|
+
me,
|
|
2801
|
+
he
|
|
2795
2802
|
],
|
|
2796
|
-
routes:
|
|
2803
|
+
routes: _e,
|
|
2797
2804
|
rpcClientDescriptors: v,
|
|
2798
2805
|
errorSchemas: [
|
|
2799
2806
|
{
|
|
@@ -2826,7 +2833,7 @@ var Ht = () => se({
|
|
|
2826
2833
|
}
|
|
2827
2834
|
],
|
|
2828
2835
|
bindDataStore: (e) => {
|
|
2829
|
-
D && (k.current =
|
|
2836
|
+
D && (k.current = Ot(e)), O && (A.current = jt(e)), y.bindDataStore?.(e);
|
|
2830
2837
|
},
|
|
2831
2838
|
onActivate: (e) => b.sync(() => {
|
|
2832
2839
|
let t = !!S || !!W.read("STORAGE_CDN_URL", i.cdnBaseUrl);
|
|
@@ -2840,4 +2847,4 @@ var Ht = () => se({
|
|
|
2840
2847
|
});
|
|
2841
2848
|
};
|
|
2842
2849
|
//#endregion
|
|
2843
|
-
export { U as STORAGE_BLOBS_TABLE, H as STORAGE_GRANTS_TABLE, V as STORAGE_REFS_TABLE,
|
|
2850
|
+
export { U as STORAGE_BLOBS_TABLE, H as STORAGE_GRANTS_TABLE, V as STORAGE_REFS_TABLE, Ee as STORAGE_USAGE_TABLE, e as StorageAccessDenied, t as StorageError, n as StorageRejected, r as StorageScanRejected, i as StorageService, Ae as _voltroStorageBlobsTable, Oe as _voltroStorageGrantsTable, De as _voltroStorageRefsTable, ke as _voltroStorageUsageTable, Xt as appStorageProvider, Ht as assetRef, ze as azureProvider, Pt as buildStorageService, be as bytesToStream, yt as checkLimits, zt as clamavScanner, Ne as clearStorageBuffer, xe as collectStream, ye as concatBytes, gt as contentTypeAllowed, jt as dataStoreGrantStore, Ot as dataStoreRefStore, Re as databaseProvider, Gt as decodeDataUri, It as encodeInstream, Vt as ffmpegTranscoder, Fe as filesystemProvider, Se as fromNodeReadable, we as getObjectStream, qe as hashPassword, kt as memoryGrantStore, Pe as memoryProvider, wt as memoryRefStore, Lt as parseClamavResponse, Ve as parseTransformParams, Kt as putAvatar, Te as putObjectStream, Me as readStorageBuffer, Ct as refMatchesListQuery, Zt as resolveStorageProvider, Y as resolveStorageSecret, Ie as s3Provider, Yt as setActiveStorageProvider, ut as signFinalizeTicket, ot as signGrant, mt as signMultipartTicket, ft as signResumableTicket, ct as signUploadTicket, vt as sniffMatches, on as storagePlugin, Ft as storageServiceLayer, Ce as toNodeReadable, Ke as transformCached, We as transformImage, dt as verifyFinalizeTicket, st as verifyGrant, ht as verifyMultipartTicket, Je as verifyPassword, pt as verifyResumableTicket, lt as verifyUploadTicket, Ut as withStorage };
|