@antelopejs/dms-media 0.6.0 → 0.6.2
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/README.md +18 -3
- package/dist/acl/entries.js +1 -2
- package/dist/acl/entries.js.map +1 -1
- package/dist/bindings.js +1 -3
- package/dist/bindings.js.map +1 -1
- package/dist/db/models/mediaFolders.model.d.ts +0 -3
- package/dist/db/models/mediaFolders.model.js +0 -29
- package/dist/db/models/mediaFolders.model.js.map +1 -1
- package/dist/db/tables/mediaDeclarations.table.d.ts +0 -4
- package/dist/db/tables/mediaDeclarations.table.js +0 -16
- package/dist/db/tables/mediaDeclarations.table.js.map +1 -1
- package/dist/declared/assets.d.ts +0 -2
- package/dist/declared/assets.js +12 -140
- package/dist/declared/assets.js.map +1 -1
- package/dist/declared/folders.d.ts +1 -5
- package/dist/declared/folders.js +17 -82
- package/dist/declared/folders.js.map +1 -1
- package/dist/declared/index.d.ts +0 -2
- package/dist/declared/index.js +0 -2
- package/dist/declared/index.js.map +1 -1
- package/dist/declared/records.d.ts +4 -32
- package/dist/declared/records.js +6 -35
- package/dist/declared/records.js.map +1 -1
- package/dist/derivatives.js +14 -23
- package/dist/derivatives.js.map +1 -1
- package/dist/guards.d.ts +4 -0
- package/dist/guards.js +19 -0
- package/dist/guards.js.map +1 -0
- package/dist/implementations/interface-dms-media/index.d.ts +1 -3
- package/dist/implementations/interface-dms-media/index.js +0 -2
- package/dist/implementations/interface-dms-media/index.js.map +1 -1
- package/dist/library/activity.js +7 -5
- package/dist/library/activity.js.map +1 -1
- package/dist/library/batches.js +6 -3
- package/dist/library/batches.js.map +1 -1
- package/dist/library/events.js +4 -4
- package/dist/library/events.js.map +1 -1
- package/dist/library/module-readout.js +5 -2
- package/dist/library/module-readout.js.map +1 -1
- package/dist/library/realtime.js.map +1 -1
- package/dist/pages/activity.js +1 -1
- package/dist/pages/activity.js.map +1 -1
- package/dist/routes/media/assets.d.ts +1 -1
- package/dist/routes/media/assets.js +5 -5
- package/dist/routes/media/assets.js.map +1 -1
- package/dist/routes/media/bulk.js +17 -13
- package/dist/routes/media/bulk.js.map +1 -1
- package/dist/routes/media/delivery-headers.js +9 -9
- package/dist/routes/media/delivery-headers.js.map +1 -1
- package/dist/routes/media/delivery-stream.js +7 -21
- package/dist/routes/media/delivery-stream.js.map +1 -1
- package/dist/routes/media/delivery.js.map +1 -1
- package/dist/routes/media/manage.js.map +1 -1
- package/dist/routes/media/transform.js +13 -8
- package/dist/routes/media/transform.js.map +1 -1
- package/dist/routes/media/upload.js +2 -5
- package/dist/routes/media/upload.js.map +1 -1
- package/dist/test/antelope.test.js +17 -16
- package/dist/test/antelope.test.js.map +1 -1
- package/dist/test/helpers/folders.d.ts +27 -0
- package/dist/test/helpers/folders.js +15 -0
- package/dist/test/helpers/folders.js.map +1 -1
- package/dist/test/helpers/pages.js +10 -6
- package/dist/test/helpers/pages.js.map +1 -1
- package/dist/test/helpers/permissions-world.d.ts +98 -0
- package/dist/test/helpers/permissions-world.js +205 -0
- package/dist/test/helpers/permissions-world.js.map +1 -0
- package/dist/test/helpers/prototype.d.ts +1 -0
- package/dist/test/helpers/prototype.js +11 -0
- package/dist/test/helpers/prototype.js.map +1 -0
- package/dist/test/integration/derivative-sweep-query.test.js +13 -16
- package/dist/test/integration/derivative-sweep-query.test.js.map +1 -1
- package/dist/test/integration/folder-query.test.js +5 -9
- package/dist/test/integration/folder-query.test.js.map +1 -1
- package/dist/test/integration/media-bindings.test.js +2 -2
- package/dist/test/integration/media-bindings.test.js.map +1 -1
- package/dist/test/integration/media-cleanup.test.js +14 -17
- package/dist/test/integration/media-cleanup.test.js.map +1 -1
- package/dist/test/integration/media-declared-content.test.js +19 -318
- package/dist/test/integration/media-declared-content.test.js.map +1 -1
- package/dist/test/integration/media-delivery-editing.test.js +7 -5
- package/dist/test/integration/media-delivery-editing.test.js.map +1 -1
- package/dist/test/integration/media-delivery.test.js +19 -5
- package/dist/test/integration/media-delivery.test.js.map +1 -1
- package/dist/test/integration/media-explorer-writes.test.js +2 -2
- package/dist/test/integration/media-explorer-writes.test.js.map +1 -1
- package/dist/test/integration/media-guards.test.js +18 -7
- package/dist/test/integration/media-guards.test.js.map +1 -1
- package/dist/test/integration/media-library.test.js +1 -1
- package/dist/test/integration/media-library.test.js.map +1 -1
- package/dist/test/integration/media-linked-subfolders.test.js +6 -6
- package/dist/test/integration/media-linked-subfolders.test.js.map +1 -1
- package/dist/test/integration/media-member-access.test.js +2 -5
- package/dist/test/integration/media-member-access.test.js.map +1 -1
- package/dist/test/integration/media-permissions.test.js +142 -473
- package/dist/test/integration/media-permissions.test.js.map +1 -1
- package/dist/test/integration/media-project-field.test.js +3 -5
- package/dist/test/integration/media-project-field.test.js.map +1 -1
- package/dist/test/integration/media-search-query.test.js +11 -16
- package/dist/test/integration/media-search-query.test.js.map +1 -1
- package/dist/test/integration/media-storage-origin-unreachable.test.js +80 -0
- package/dist/test/integration/media-storage-origin-unreachable.test.js.map +1 -0
- package/dist/test/integration/media-upload-policy.test.js +2 -2
- package/dist/test/integration/media-upload-policy.test.js.map +1 -1
- package/dist/test/integration/permissions-management.d.ts +2 -0
- package/dist/test/integration/permissions-management.js +189 -0
- package/dist/test/integration/permissions-management.js.map +1 -0
- package/dist/test/unit/acl/entries.test.js +2 -1
- package/dist/test/unit/acl/entries.test.js.map +1 -1
- package/dist/test/unit/acl/resolver.test.js +10 -3
- package/dist/test/unit/acl/resolver.test.js.map +1 -1
- package/dist/test/unit/declared.test.js +0 -66
- package/dist/test/unit/declared.test.js.map +1 -1
- package/dist/test/unit/library/fixtures.d.ts +1 -1
- package/dist/test/unit/library/fixtures.js +6 -1
- package/dist/test/unit/library/fixtures.js.map +1 -1
- package/dist/test/unit/library/library.test.js +0 -1
- package/dist/test/unit/library/library.test.js.map +1 -1
- package/dist/test/unit/library/realtime.test.js +1 -0
- package/dist/test/unit/library/realtime.test.js.map +1 -1
- package/dist/test/unit/library/search-facets.test.js +2 -2
- package/dist/test/unit/library/search-facets.test.js.map +1 -1
- package/dist/test/unit/pages/toolbar.test.js +24 -7
- package/dist/test/unit/pages/toolbar.test.js.map +1 -1
- package/dist/test/unit/routes/dto.test.js +7 -6
- package/dist/test/unit/routes/dto.test.js.map +1 -1
- package/dist/test/unit/routes/file-page.test.js +5 -7
- package/dist/test/unit/routes/file-page.test.js.map +1 -1
- package/dist/test/unit/routes/preset-row.test.js +2 -1
- package/dist/test/unit/routes/preset-row.test.js.map +1 -1
- package/dist/transform.js +6 -6
- package/dist/transform.js.map +1 -1
- package/dist/upload-checks.d.ts +8 -2
- package/dist/upload-checks.js.map +1 -1
- package/dist/upload-policy.js +8 -8
- package/dist/upload-policy.js.map +1 -1
- package/dist/validation/declared.schema.d.ts +7 -36
- package/dist/validation/declared.schema.js +15 -20
- package/dist/validation/declared.schema.js.map +1 -1
- package/dist/validation/media.schema.d.ts +1 -1
- package/dist/validation/media.schema.js +2 -2
- package/dist/validation/media.schema.js.map +1 -1
- package/frontend-vue/app/build/imageEditor/editorShapes.ts +118 -0
- package/frontend-vue/app/build/imageEditor/useEditorSaving.ts +86 -0
- package/frontend-vue/app/build/library/libraryActions.ts +444 -0
- package/frontend-vue/app/build/library/libraryCore.ts +136 -0
- package/frontend-vue/app/components/ImageEditor.vue +22 -179
- package/frontend-vue/app/composables/library/useMediaLibrary.ts +3 -575
- package/frontend-vue/app/composables/useMediaApi.ts +21 -5
- package/frontend-vue/build/backend-boundary.ts +122 -0
- package/frontend-vue/dms.frontend.build.ts +3 -0
- package/frontend-vue/eslint.config.mjs +13 -0
- package/frontend-vue/package.json +3 -1
- package/frontend-vue/pnpm-lock.yaml +217 -61
- package/frontend-vue/tests/backend-boundary.test.ts +203 -0
- package/frontend-vue/tests/mediaPreviews.test.ts +39 -0
- package/package.json +10 -16
- package/skills/dms-media/SKILL.md +12 -24
- package/skills/dms-media/cases.json +38 -0
- package/src/acl/entries.ts +6 -4
- package/src/bindings.ts +3 -3
- package/src/db/models/mediaFolders.model.ts +0 -44
- package/src/db/tables/mediaDeclarations.table.ts +3 -19
- package/src/declared/assets.ts +19 -210
- package/src/declared/folders.ts +25 -138
- package/src/declared/index.ts +0 -2
- package/src/declared/records.ts +17 -90
- package/src/derivatives.ts +17 -23
- package/src/guards.ts +19 -0
- package/src/implementations/interface-dms-media/index.ts +1 -8
- package/src/library/activity.ts +17 -9
- package/src/library/batches.ts +12 -9
- package/src/library/events.ts +7 -4
- package/src/library/module-readout.ts +6 -2
- package/src/library/realtime.ts +5 -1
- package/src/library/zip.ts +1 -1
- package/src/pages/activity.ts +6 -2
- package/src/routes/media/assets.ts +4 -3
- package/src/routes/media/bulk.ts +16 -14
- package/src/routes/media/delivery-headers.ts +9 -12
- package/src/routes/media/delivery-stream.ts +13 -28
- package/src/routes/media/delivery.ts +4 -2
- package/src/routes/media/manage.ts +4 -6
- package/src/routes/media/transform.ts +27 -23
- package/src/routes/media/upload.ts +4 -6
- package/src/test/antelope.test.ts +25 -21
- package/src/test/helpers/folders.ts +22 -0
- package/src/test/helpers/pages.ts +12 -5
- package/src/test/helpers/permissions-world.ts +326 -0
- package/src/test/helpers/prototype.ts +12 -0
- package/src/test/integration/derivative-sweep-query.test.ts +19 -21
- package/src/test/integration/folder-query.test.ts +11 -11
- package/src/test/integration/media-bindings.test.ts +7 -7
- package/src/test/integration/media-cleanup.test.ts +25 -37
- package/src/test/integration/media-declared-content.test.ts +35 -379
- package/src/test/integration/media-delivery-editing.test.ts +11 -7
- package/src/test/integration/media-delivery.test.ts +29 -8
- package/src/test/integration/media-explorer-writes.test.ts +2 -7
- package/src/test/integration/media-guards.test.ts +21 -7
- package/src/test/integration/media-library.test.ts +1 -1
- package/src/test/integration/media-linked-subfolders.test.ts +12 -21
- package/src/test/integration/media-member-access.test.ts +5 -9
- package/src/test/integration/media-permissions.test.ts +56 -570
- package/src/test/integration/media-project-field.test.ts +5 -7
- package/src/test/integration/media-search-query.test.ts +16 -20
- package/src/test/integration/media-storage-origin-unreachable.test.ts +111 -0
- package/src/test/integration/media-upload-policy.test.ts +2 -8
- package/src/test/integration/permissions-management.ts +292 -0
- package/src/test/unit/acl/entries.test.ts +2 -1
- package/src/test/unit/acl/resolver.test.ts +19 -7
- package/src/test/unit/declared.test.ts +0 -87
- package/src/test/unit/library/fixtures.ts +9 -3
- package/src/test/unit/library/library.test.ts +1 -7
- package/src/test/unit/library/realtime.test.ts +2 -0
- package/src/test/unit/library/search-facets.test.ts +2 -2
- package/src/test/unit/pages/toolbar.test.ts +42 -17
- package/src/test/unit/routes/dto.test.ts +7 -6
- package/src/test/unit/routes/file-page.test.ts +10 -9
- package/src/test/unit/routes/preset-row.test.ts +2 -2
- package/src/transform.ts +6 -6
- package/src/upload-checks.ts +12 -3
- package/src/upload-policy.ts +8 -8
- package/src/validation/declared.schema.ts +17 -25
- package/src/validation/media.schema.ts +6 -6
- package/dist/declared/readiness.d.ts +0 -2
- package/dist/declared/readiness.js +0 -52
- package/dist/declared/readiness.js.map +0 -1
- package/dist/declared/retire.d.ts +0 -3
- package/dist/declared/retire.js +0 -118
- package/dist/declared/retire.js.map +0 -1
- package/dist/test/integration/media-declared-retire.test.js +0 -186
- package/dist/test/integration/media-declared-retire.test.js.map +0 -1
- package/frontend-vue/tests/engines.test.ts +0 -20
- package/frontend-vue/tests/locales.test.ts +0 -61
- package/src/declared/readiness.ts +0 -64
- package/src/declared/retire.ts +0 -206
- package/src/test/integration/media-declared-retire.test.ts +0 -257
- /package/dist/test/integration/{media-declared-retire.test.d.ts → media-storage-origin-unreachable.test.d.ts} +0 -0
|
@@ -1,75 +1,12 @@
|
|
|
1
1
|
import { setTimeout as delay } from "node:timers/promises";
|
|
2
2
|
import { expect } from "chai";
|
|
3
3
|
import {
|
|
4
|
-
hashState,
|
|
5
|
-
judgeDeclaredRow,
|
|
6
|
-
judgeMemberChange,
|
|
7
4
|
MediaDeclarationError,
|
|
8
5
|
parseDeclaration,
|
|
9
6
|
withDeclarationLock,
|
|
10
7
|
} from "../../declared/records";
|
|
11
|
-
import { writeWhenReachable } from "../../declared/readiness";
|
|
12
|
-
import type { MediaDeclaration } from "../../db";
|
|
13
8
|
import { declaredFolderSchema } from "../../validation/declared.schema";
|
|
14
9
|
|
|
15
|
-
const ROW = { _id: "row-1" };
|
|
16
|
-
const APPLIED = hashState({ name: "Procedures" });
|
|
17
|
-
const DECLARED = hashState({ declared: 1 });
|
|
18
|
-
|
|
19
|
-
function record(): MediaDeclaration {
|
|
20
|
-
return {
|
|
21
|
-
_id: "declaration-1",
|
|
22
|
-
kind: "folder",
|
|
23
|
-
key: "helio.procedures",
|
|
24
|
-
targetId: ROW._id,
|
|
25
|
-
declaredHash: DECLARED,
|
|
26
|
-
appliedHash: APPLIED,
|
|
27
|
-
} as MediaDeclaration;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
describe("[unit] declared content — the refresh rule", () => {
|
|
31
|
-
it("keeps a deleted row deleted", () => {
|
|
32
|
-
expect(
|
|
33
|
-
judgeDeclaredRow(record(), undefined, undefined, DECLARED),
|
|
34
|
-
).to.deep.equal({ status: "deleted" });
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("preserves a row whose state moved away from the applied one", () => {
|
|
38
|
-
const edited = hashState({ name: "Our procedures" });
|
|
39
|
-
expect(
|
|
40
|
-
judgeDeclaredRow(record(), ROW, edited, hashState({ declared: 2 })),
|
|
41
|
-
).to.deep.equal({ status: "preserved", id: ROW._id });
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("reports an untouched row declared the same way as unchanged", () => {
|
|
45
|
-
expect(judgeDeclaredRow(record(), ROW, APPLIED, DECLARED)).to.deep.equal({
|
|
46
|
-
status: "unchanged",
|
|
47
|
-
id: ROW._id,
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("lets an untouched row with a new declaration be refreshed", () => {
|
|
52
|
-
expect(
|
|
53
|
-
judgeDeclaredRow(record(), ROW, APPLIED, hashState({ declared: 2 })),
|
|
54
|
-
).to.equal(undefined);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("judges a member's change without a new declaration", () => {
|
|
58
|
-
expect(judgeMemberChange(record(), undefined, undefined)).to.deep.equal({
|
|
59
|
-
status: "deleted",
|
|
60
|
-
});
|
|
61
|
-
expect(
|
|
62
|
-
judgeMemberChange(record(), ROW, hashState({ name: "Ours" })),
|
|
63
|
-
).to.deep.equal({ status: "preserved", id: ROW._id });
|
|
64
|
-
expect(judgeMemberChange(record(), ROW, APPLIED)).to.equal(undefined);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("hashes equal states equally and different states differently", () => {
|
|
68
|
-
expect(hashState({ a: 1, b: null })).to.equal(hashState({ a: 1, b: null }));
|
|
69
|
-
expect(hashState({ a: 1 })).to.not.equal(hashState({ a: 2 }));
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
10
|
describe("[unit] declared content — declarations", () => {
|
|
74
11
|
it("keeps an explicit default tenant and defaults the visibility", () => {
|
|
75
12
|
const parsed = parseDeclaration(
|
|
@@ -132,27 +69,3 @@ describe("[unit] declared content — declarations", () => {
|
|
|
132
69
|
expect(await next).to.equal("ok");
|
|
133
70
|
});
|
|
134
71
|
});
|
|
135
|
-
|
|
136
|
-
describe("[unit] declared content — storage writes at startup", () => {
|
|
137
|
-
it("retries a write while its endpoint does not answer", async function () {
|
|
138
|
-
this.timeout(10_000);
|
|
139
|
-
let attempts = 0;
|
|
140
|
-
const result = await writeWhenReachable(async () => {
|
|
141
|
-
attempts += 1;
|
|
142
|
-
if (attempts < 3) throw new TypeError("fetch failed");
|
|
143
|
-
return "stored";
|
|
144
|
-
});
|
|
145
|
-
expect(result).to.equal("stored");
|
|
146
|
-
expect(attempts).to.equal(3);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it("does not retry a refused write", async () => {
|
|
150
|
-
let attempts = 0;
|
|
151
|
-
const refusal = await writeWhenReachable(async () => {
|
|
152
|
-
attempts += 1;
|
|
153
|
-
throw new Error("Failed to upload logo.png: 413");
|
|
154
|
-
}).catch((error: Error) => error.message);
|
|
155
|
-
expect(refusal).to.contain("413");
|
|
156
|
-
expect(attempts).to.equal(1);
|
|
157
|
-
});
|
|
158
|
-
});
|
|
@@ -6,6 +6,7 @@ export function folder(
|
|
|
6
6
|
id: string,
|
|
7
7
|
parentId?: string,
|
|
8
8
|
path: string[] = [],
|
|
9
|
+
overrides: Partial<MediaFolder> = {},
|
|
9
10
|
): MediaFolder {
|
|
10
11
|
return {
|
|
11
12
|
_id: id,
|
|
@@ -15,7 +16,8 @@ export function folder(
|
|
|
15
16
|
visibility: "private",
|
|
16
17
|
createdAt: EPOCH,
|
|
17
18
|
updatedAt: EPOCH,
|
|
18
|
-
|
|
19
|
+
...overrides,
|
|
20
|
+
};
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export function asset(
|
|
@@ -28,11 +30,15 @@ export function asset(
|
|
|
28
30
|
name: `${id}.jpg`,
|
|
29
31
|
mimetype: "image/jpeg",
|
|
30
32
|
size: 100,
|
|
33
|
+
storageKey: `${id}.jpg`,
|
|
31
34
|
visibility: "inherit",
|
|
35
|
+
mediaRevision: "revision",
|
|
36
|
+
json_retiredFiles: "[]",
|
|
37
|
+
createdBy: "user",
|
|
32
38
|
createdAt: EPOCH,
|
|
33
39
|
updatedAt: EPOCH,
|
|
34
40
|
...overrides,
|
|
35
|
-
}
|
|
41
|
+
};
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
export function event(
|
|
@@ -48,5 +54,5 @@ export function event(
|
|
|
48
54
|
folderId: "root",
|
|
49
55
|
createdAt: EPOCH,
|
|
50
56
|
...overrides,
|
|
51
|
-
}
|
|
57
|
+
};
|
|
52
58
|
}
|
|
@@ -3,12 +3,7 @@ import { buildActivityItems } from "../../../library/activity";
|
|
|
3
3
|
import { buildUploadBatches } from "../../../library/batches";
|
|
4
4
|
import { composedBytes, composedText } from "../../../library/composed-text";
|
|
5
5
|
import { computeFolderStats } from "../../../library/folder-stats";
|
|
6
|
-
import {
|
|
7
|
-
fileLink,
|
|
8
|
-
folderLink,
|
|
9
|
-
MEDIA_ROUTES,
|
|
10
|
-
viewLink,
|
|
11
|
-
} from "../../../library/links";
|
|
6
|
+
import { fileLink, folderLink, viewLink } from "../../../library/links";
|
|
12
7
|
import { countByTypeGroup, pageAssets } from "../../../library/listing";
|
|
13
8
|
import { searchAssets, searchFolders } from "../../../library/search";
|
|
14
9
|
import {
|
|
@@ -216,7 +211,6 @@ describe("[unit] library — composed texts", () => {
|
|
|
216
211
|
|
|
217
212
|
describe("[unit] library — links", () => {
|
|
218
213
|
it("points at the pages of the media module", () => {
|
|
219
|
-
expect(MEDIA_ROUTES.overview).to.equal("/modules/media/overview");
|
|
220
214
|
expect(folderLink("f 1")).to.equal("/modules/media/files?folder=f%201");
|
|
221
215
|
expect(fileLink("a1")).to.equal("/modules/media/file?asset=a1");
|
|
222
216
|
expect(viewLink("missing-alt")).to.equal(
|
|
@@ -20,7 +20,9 @@ describe("[unit] library — realtime", () => {
|
|
|
20
20
|
let messages: RealtimeMessage[];
|
|
21
21
|
let unsubscribe: () => void;
|
|
22
22
|
|
|
23
|
+
/** Changes the integration suites made may still be waiting to be announced: drop them first. */
|
|
23
24
|
beforeEach(() => {
|
|
25
|
+
cancelLibraryChange();
|
|
24
26
|
messages = [];
|
|
25
27
|
unsubscribe = SubscribeMessage(MEDIA_LIBRARY_TOPIC, (message) => {
|
|
26
28
|
messages.push(message);
|
|
@@ -77,7 +77,7 @@ describe("[unit] library/search — accent-free, multi-word search", () => {
|
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
describe("[unit] library — listing facets and folder counts", () => {
|
|
80
|
-
const
|
|
80
|
+
const candidates = [
|
|
81
81
|
asset("wide", { width: 400, height: 200 }),
|
|
82
82
|
asset("tall", { width: 200, height: 400 }),
|
|
83
83
|
asset("even", { width: 300, height: 300 }),
|
|
@@ -85,7 +85,7 @@ describe("[unit] library — listing facets and folder counts", () => {
|
|
|
85
85
|
];
|
|
86
86
|
|
|
87
87
|
function keep(orientation: AssetFilterQuery["orientation"]): string[] {
|
|
88
|
-
return filterAssets(
|
|
88
|
+
return filterAssets(candidates, {
|
|
89
89
|
query: { ...ANY_FILTER, orientation },
|
|
90
90
|
now: NOW,
|
|
91
91
|
visibilityOf: () => "private",
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { expect } from "chai";
|
|
2
|
-
import
|
|
2
|
+
import { GetMetadata } from "@antelopejs/interface-core";
|
|
3
|
+
import {
|
|
4
|
+
ComponentBuilder,
|
|
5
|
+
type ComponentInfoSerialized,
|
|
6
|
+
} from "@antelopejs/interface-dms/component";
|
|
7
|
+
import { PageMetadata } from "@antelopejs/interface-dms/page";
|
|
3
8
|
import { MEDIA_LIBRARY_TOPIC } from "../../../constants";
|
|
9
|
+
import { isObject } from "../../../guards";
|
|
4
10
|
import { MediaActivityPage } from "../../../pages/activity";
|
|
5
11
|
import { MediaOverviewPage } from "../../../pages/overview";
|
|
6
|
-
import {
|
|
12
|
+
import { mediaPageToolbar } from "../../../pages/toolbar";
|
|
7
13
|
import { MediaUploadsPage } from "../../../pages/uploads";
|
|
8
14
|
|
|
9
15
|
const TOOLBAR_COMPONENT = "dms-page-toolbar-block";
|
|
@@ -17,29 +23,39 @@ type LivePage = (typeof LIVE_PAGES)[keyof typeof LIVE_PAGES];
|
|
|
17
23
|
|
|
18
24
|
/** The blocks a page declares, in the order it renders them. */
|
|
19
25
|
function pageBlocks(page: LivePage): ComponentBuilder<unknown>[] {
|
|
20
|
-
return Object.values(page)
|
|
26
|
+
return Object.values(page).filter(
|
|
27
|
+
(value): value is ComponentBuilder<unknown> =>
|
|
28
|
+
value instanceof ComponentBuilder,
|
|
29
|
+
);
|
|
21
30
|
}
|
|
22
31
|
|
|
23
|
-
/** What a block
|
|
24
|
-
interface
|
|
32
|
+
/** What a block reads, as its serialized options say. */
|
|
33
|
+
interface BlockReads {
|
|
25
34
|
componentName: string;
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
fetchUrl?: unknown;
|
|
36
|
+
realtimeTopic?: unknown;
|
|
28
37
|
}
|
|
29
38
|
|
|
30
39
|
/**
|
|
31
40
|
* The blocks under `block` that read data, `block` included: a `fetchUrl`, or
|
|
32
41
|
* a table, which reads through a route of its own and only says its topic.
|
|
33
42
|
*/
|
|
34
|
-
function fetchingBlocks(block:
|
|
43
|
+
function fetchingBlocks(block: ComponentInfoSerialized): BlockReads[] {
|
|
44
|
+
const { options } = block;
|
|
35
45
|
const own =
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
isObject(options) && ("fetchUrl" in options || "realtimeTopic" in options)
|
|
47
|
+
? [
|
|
48
|
+
{
|
|
49
|
+
componentName: block.componentName,
|
|
50
|
+
fetchUrl: "fetchUrl" in options ? options.fetchUrl : undefined,
|
|
51
|
+
realtimeTopic:
|
|
52
|
+
"realtimeTopic" in options ? options.realtimeTopic : undefined,
|
|
53
|
+
},
|
|
54
|
+
]
|
|
39
55
|
: [];
|
|
40
56
|
return [
|
|
41
57
|
...own,
|
|
42
|
-
...(block.children ?? []).flatMap((child
|
|
58
|
+
...(block.children ?? []).flatMap((child) =>
|
|
43
59
|
fetchingBlocks(child.component),
|
|
44
60
|
),
|
|
45
61
|
];
|
|
@@ -58,8 +74,17 @@ describe("[unit] pages — toolbar", () => {
|
|
|
58
74
|
});
|
|
59
75
|
|
|
60
76
|
it("shares one Direct / Pause choice between the media pages", () => {
|
|
61
|
-
|
|
62
|
-
|
|
77
|
+
const lives = Object.values(LIVE_PAGES).map(
|
|
78
|
+
(page) => GetMetadata(page, PageMetadata).pageInfo?.live,
|
|
79
|
+
);
|
|
80
|
+
const rememberKeys = new Set(lives.map((live) => live?.rememberKey));
|
|
81
|
+
const [rememberKey] = rememberKeys;
|
|
82
|
+
expect([...rememberKeys]).to.have.length(1);
|
|
83
|
+
expect(rememberKey).to.be.a("string");
|
|
84
|
+
expect(rememberKey).to.not.equal("");
|
|
85
|
+
for (const live of lives) {
|
|
86
|
+
expect(live?.maxRate).to.be.greaterThan(0);
|
|
87
|
+
}
|
|
63
88
|
});
|
|
64
89
|
|
|
65
90
|
for (const [name, page] of Object.entries(LIVE_PAGES)) {
|
|
@@ -72,13 +97,13 @@ describe("[unit] pages — toolbar", () => {
|
|
|
72
97
|
for (const [name, page] of Object.entries(LIVE_PAGES)) {
|
|
73
98
|
it(`reads every block of the ${name} page again on library changes`, () => {
|
|
74
99
|
const blocks = pageBlocks(page).flatMap((block) =>
|
|
75
|
-
fetchingBlocks(block.serializeSync()
|
|
100
|
+
fetchingBlocks(block.serializeSync()),
|
|
76
101
|
);
|
|
77
102
|
expect(blocks).to.have.length.greaterThan(0);
|
|
78
103
|
for (const block of blocks) {
|
|
79
104
|
expect(
|
|
80
|
-
block.
|
|
81
|
-
`${block.componentName} ${JSON.stringify(block.
|
|
105
|
+
block.realtimeTopic,
|
|
106
|
+
`${block.componentName} ${JSON.stringify(block.fetchUrl)}`,
|
|
82
107
|
).to.equal(MEDIA_LIBRARY_TOPIC);
|
|
83
108
|
}
|
|
84
109
|
});
|
|
@@ -5,13 +5,14 @@ import {
|
|
|
5
5
|
resolveEffectiveVisibility,
|
|
6
6
|
} from "../../../routes/media/dto";
|
|
7
7
|
import type { AssetVisibility, FolderVisibility } from "../../../types";
|
|
8
|
+
import { asset, folder } from "../library/fixtures";
|
|
8
9
|
|
|
9
10
|
function assetWithVisibility(visibility: AssetVisibility): MediaAsset {
|
|
10
|
-
return { visibility }
|
|
11
|
+
return asset("asset", { visibility });
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
function folderWithVisibility(visibility: FolderVisibility): MediaFolder {
|
|
14
|
-
return { visibility }
|
|
15
|
+
return folder("folder", undefined, [], { visibility });
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
describe("[unit] routes/dto — resolveEffectiveVisibility", () => {
|
|
@@ -54,12 +55,12 @@ describe("[unit] routes/dto — resolveEffectiveVisibility", () => {
|
|
|
54
55
|
|
|
55
56
|
describe("[unit] routes/dto — buildDeliveryPath", () => {
|
|
56
57
|
it("builds the stable delivery URL from id and name", () => {
|
|
57
|
-
const
|
|
58
|
-
expect(buildDeliveryPath(
|
|
58
|
+
const photo = asset("a1", { name: "photo.png" });
|
|
59
|
+
expect(buildDeliveryPath(photo)).to.equal("/media/a1/photo.png");
|
|
59
60
|
});
|
|
60
61
|
|
|
61
62
|
it("escapes unsafe characters in the filename", () => {
|
|
62
|
-
const
|
|
63
|
-
expect(buildDeliveryPath(
|
|
63
|
+
const spaced = asset("a1", { name: "my file#1.png" });
|
|
64
|
+
expect(buildDeliveryPath(spaced)).to.equal("/media/a1/my%20file%231.png");
|
|
64
65
|
});
|
|
65
66
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { expect } from "chai";
|
|
1
|
+
import { assert, expect } from "chai";
|
|
2
2
|
import type { KeyValueListItem } from "@antelopejs/interface-dms/base/key-value-list";
|
|
3
3
|
import type { MediaAsset, MediaFolder } from "../../../db";
|
|
4
4
|
import { buildDeliveryPath } from "../../../routes/media/dto";
|
|
@@ -7,31 +7,32 @@ import {
|
|
|
7
7
|
buildDeliveryNotice,
|
|
8
8
|
buildFileInformation,
|
|
9
9
|
} from "../../../routes/media/file";
|
|
10
|
+
import {
|
|
11
|
+
asset as buildAsset,
|
|
12
|
+
folder as buildFolder,
|
|
13
|
+
} from "../library/fixtures";
|
|
10
14
|
|
|
11
15
|
const ORIGIN = "https://api.example.com";
|
|
12
16
|
const ASSET_ID = "7554eb0a-c6fb-4518-a8b9-65c6e8a3e6a9";
|
|
13
17
|
|
|
14
18
|
function jpeg(overrides: Partial<MediaAsset> = {}): MediaAsset {
|
|
15
|
-
return {
|
|
16
|
-
_id: ASSET_ID,
|
|
19
|
+
return buildAsset(ASSET_ID, {
|
|
17
20
|
name: "Été à Liège.jpg",
|
|
18
|
-
mimetype: "image/jpeg",
|
|
19
|
-
visibility: "inherit",
|
|
20
21
|
folderId: "folder",
|
|
21
22
|
createdAt: new Date("2026-10-01T10:00:00Z"),
|
|
22
23
|
updatedAt: new Date("2026-10-02T10:00:00Z"),
|
|
23
24
|
...overrides,
|
|
24
|
-
}
|
|
25
|
+
});
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
function folder(visibility: MediaFolder["visibility"]): MediaFolder {
|
|
28
|
-
return { visibility }
|
|
29
|
+
return buildFolder("folder", undefined, [], { visibility });
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
function row(items: KeyValueListItem[], id: string): KeyValueListItem {
|
|
32
33
|
const found = items.find((item) => item.id === id);
|
|
33
|
-
|
|
34
|
-
return found
|
|
34
|
+
assert.isDefined(found, id);
|
|
35
|
+
return found;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
describe("[unit] routes/file — delivery links", () => {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { expect } from "chai";
|
|
2
|
-
import type { MediaAsset } from "../../../db";
|
|
3
2
|
import type { MediaPresetConfig } from "../../../presets";
|
|
4
3
|
import { presetRow } from "../../../routes/media/manage";
|
|
4
|
+
import { asset } from "../library/fixtures";
|
|
5
5
|
|
|
6
6
|
const ORIGIN = "http://127.0.0.1:5010";
|
|
7
7
|
const ASSET_ID = "7554eb0a-c6fb-4518-a8b9-65c6e8a3e6a9";
|
|
8
8
|
const THUMB: MediaPresetConfig = { id: "thumb", width: 300, height: 300 };
|
|
9
|
-
const EXAMPLE =
|
|
9
|
+
const EXAMPLE = asset(ASSET_ID, { name: "Été à Liège.jpg" });
|
|
10
10
|
const EXAMPLE_PATH = `/media/${ASSET_ID}/thumb/%C3%89t%C3%A9%20%C3%A0%20Li%C3%A8ge.jpg`;
|
|
11
11
|
|
|
12
12
|
describe("[unit] routes/manage — image size cards", () => {
|
package/src/transform.ts
CHANGED
|
@@ -28,11 +28,11 @@ type EditOutputOptions =
|
|
|
28
28
|
| sharp.WebpOptions
|
|
29
29
|
| sharp.AvifOptions;
|
|
30
30
|
|
|
31
|
-
const EDIT_OUTPUT_OPTIONS
|
|
32
|
-
jpeg
|
|
33
|
-
webp
|
|
34
|
-
avif
|
|
35
|
-
|
|
31
|
+
const EDIT_OUTPUT_OPTIONS = new Map<keyof sharp.FormatEnum, EditOutputOptions>([
|
|
32
|
+
["jpeg", { quality: 92, mozjpeg: true }],
|
|
33
|
+
["webp", { quality: 92 }],
|
|
34
|
+
["avif", { quality: 80 }],
|
|
35
|
+
]);
|
|
36
36
|
|
|
37
37
|
export class AnimatedImageTransformError extends Error {}
|
|
38
38
|
/** Someone else changed the image while this edit was being rendered. */
|
|
@@ -123,7 +123,7 @@ function encodeLikeSource(
|
|
|
123
123
|
metadata: sharp.Metadata,
|
|
124
124
|
): sharp.Sharp {
|
|
125
125
|
const kept = pipeline.keepMetadata();
|
|
126
|
-
const options = metadata.format && EDIT_OUTPUT_OPTIONS
|
|
126
|
+
const options = metadata.format && EDIT_OUTPUT_OPTIONS.get(metadata.format);
|
|
127
127
|
if (!options || !metadata.format) return kept;
|
|
128
128
|
return kept.toFormat(metadata.format, options);
|
|
129
129
|
}
|
package/src/upload-checks.ts
CHANGED
|
@@ -13,8 +13,10 @@ const HTTP_PAYLOAD_TOO_LARGE = 413;
|
|
|
13
13
|
const HTTP_UNSUPPORTED_MEDIA_TYPE = 415;
|
|
14
14
|
const HTTP_UNPROCESSABLE_ENTITY = 422;
|
|
15
15
|
const FIRST_SWAPPED_ORIENTATION = 5;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Dimension probing buffers the file in memory, so files too large to hold in
|
|
18
|
+
* the heap are skipped; they simply stay without width/height metadata.
|
|
19
|
+
*/
|
|
18
20
|
const MAX_PROBE_SIZE_BYTES = 32 * 1024 * 1024;
|
|
19
21
|
|
|
20
22
|
/** Why an upload is refused, for the queue to explain it in the member's language. */
|
|
@@ -24,6 +26,13 @@ export type UploadRefusal =
|
|
|
24
26
|
| "quota"
|
|
25
27
|
| "invalid_image";
|
|
26
28
|
|
|
29
|
+
/** What a refusal tells the member besides its reason: the accepted types of the field, or the quota left. */
|
|
30
|
+
interface UploadRefusalDetails {
|
|
31
|
+
accepted?: string[];
|
|
32
|
+
remaining?: number;
|
|
33
|
+
quota?: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
27
36
|
/**
|
|
28
37
|
* A file the library refuses, whoever adds it: the upload routes answer it as
|
|
29
38
|
* an HTTP error, declared content throws it to the calling module.
|
|
@@ -33,7 +42,7 @@ export class UploadRefusedError extends Error {
|
|
|
33
42
|
readonly status: number,
|
|
34
43
|
readonly reason: UploadRefusal,
|
|
35
44
|
message: string,
|
|
36
|
-
readonly details:
|
|
45
|
+
readonly details: UploadRefusalDetails = {},
|
|
37
46
|
) {
|
|
38
47
|
super(message);
|
|
39
48
|
}
|
package/src/upload-policy.ts
CHANGED
|
@@ -46,13 +46,13 @@ const DECODABLE_IMAGE_MIMETYPES: Record<string, string> = {
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
/** Mimetype of what sharp actually read, to store instead of the claim. */
|
|
49
|
-
const MIMETYPES_BY_FORMAT
|
|
50
|
-
jpeg
|
|
51
|
-
png
|
|
52
|
-
webp
|
|
53
|
-
gif
|
|
54
|
-
tiff
|
|
55
|
-
|
|
49
|
+
const MIMETYPES_BY_FORMAT = new Map([
|
|
50
|
+
["jpeg", "image/jpeg"],
|
|
51
|
+
["png", "image/png"],
|
|
52
|
+
["webp", "image/webp"],
|
|
53
|
+
["gif", "image/gif"],
|
|
54
|
+
["tiff", "image/tiff"],
|
|
55
|
+
]);
|
|
56
56
|
|
|
57
57
|
function normalizeMimetype(mimetype: string): string {
|
|
58
58
|
return (mimetype.split(PARAMETER_SEPARATOR)[0] ?? "").trim().toLowerCase();
|
|
@@ -96,5 +96,5 @@ export function expectedImageFormat(mimetype: string): string | undefined {
|
|
|
96
96
|
export function mimetypeOfFormat(
|
|
97
97
|
format: string | undefined,
|
|
98
98
|
): string | undefined {
|
|
99
|
-
return format ? MIMETYPES_BY_FORMAT
|
|
99
|
+
return format ? MIMETYPES_BY_FORMAT.get(format) : undefined;
|
|
100
100
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z, ZodError } from "zod";
|
|
2
|
+
import { isCallable } from "../guards";
|
|
2
3
|
import {
|
|
3
4
|
altSchema,
|
|
4
5
|
fileNameSchema,
|
|
@@ -11,13 +12,15 @@ import {
|
|
|
11
12
|
* The dashboard answers with i18n keys its pages translate; a module declaring
|
|
12
13
|
* content reads the error in its logs, so it gets the English text.
|
|
13
14
|
*/
|
|
14
|
-
const DECLARATION_ERROR_TEXTS
|
|
15
|
-
[MEDIA_ERRORS.nameRequired
|
|
16
|
-
[MEDIA_ERRORS.nameTooLong
|
|
17
|
-
[
|
|
15
|
+
const DECLARATION_ERROR_TEXTS = new Map<string, string>([
|
|
16
|
+
[MEDIA_ERRORS.nameRequired, "a name is required"],
|
|
17
|
+
[MEDIA_ERRORS.nameTooLong, "the name is limited to 255 characters"],
|
|
18
|
+
[
|
|
19
|
+
MEDIA_ERRORS.nameForbidden,
|
|
18
20
|
"a name can't contain / \\ < > : \" | ? * or control characters",
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
],
|
|
22
|
+
[MEDIA_ERRORS.altTooLong, "the alt text is limited to 255 characters"],
|
|
23
|
+
]);
|
|
21
24
|
|
|
22
25
|
const keySchema = z.string().trim().min(1).max(255);
|
|
23
26
|
const tenantSchema = z.string().trim().min(1);
|
|
@@ -44,16 +47,18 @@ export const declaredFolderSchema = z.object({
|
|
|
44
47
|
tenantId: tenantSchema,
|
|
45
48
|
});
|
|
46
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Where a declared file's bytes come from. `load` is checked as a function
|
|
52
|
+
* only: wrapping it in `z.function()` would replace the caller's loader.
|
|
53
|
+
*/
|
|
47
54
|
const sourceSchema = z.union([
|
|
48
55
|
z.object({ bytes: z.instanceof(Uint8Array) }).strict(),
|
|
49
56
|
z.object({ filePath: z.string().min(1) }).strict(),
|
|
50
|
-
// Checked as a function only: wrapping it in z.function() would replace the caller's loader.
|
|
51
57
|
z
|
|
52
58
|
.object({
|
|
53
|
-
load: z.custom<() => Uint8Array | Promise<Uint8Array>>(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
),
|
|
59
|
+
load: z.custom<() => Uint8Array | Promise<Uint8Array>>(isCallable, {
|
|
60
|
+
message: "load must be a function",
|
|
61
|
+
}),
|
|
57
62
|
})
|
|
58
63
|
.strict(),
|
|
59
64
|
]);
|
|
@@ -64,23 +69,10 @@ export const declaredAssetSchema = z.object({
|
|
|
64
69
|
name: fileNameSchema,
|
|
65
70
|
mimetype: z.string().trim().min(1),
|
|
66
71
|
source: sourceSchema,
|
|
67
|
-
version: keySchema.optional(),
|
|
68
72
|
alt: altSchema.optional(),
|
|
69
73
|
tenantId: tenantSchema,
|
|
70
74
|
});
|
|
71
75
|
|
|
72
|
-
export const declarationRetirementSchema = z.object({
|
|
73
|
-
kind: z.enum(["folder", "asset"]),
|
|
74
|
-
key: keySchema,
|
|
75
|
-
tenantId: tenantSchema,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
export const declarationPruneSchema = z.object({
|
|
79
|
-
prefix: keySchema,
|
|
80
|
-
keep: z.array(keySchema),
|
|
81
|
-
tenantId: tenantSchema,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
76
|
export type DeclaredFolderInput = z.output<typeof declaredFolderSchema>;
|
|
85
77
|
export type DeclaredAssetInput = z.output<typeof declaredAssetSchema>;
|
|
86
78
|
|
|
@@ -98,7 +90,7 @@ export function describeDeclarationIssues(error: ZodError): string {
|
|
|
98
90
|
return error.issues
|
|
99
91
|
.map((issue) => {
|
|
100
92
|
const field = issue.path.join(".") || "declaration";
|
|
101
|
-
return `${field}: ${DECLARATION_ERROR_TEXTS
|
|
93
|
+
return `${field}: ${DECLARATION_ERROR_TEXTS.get(issue.message) ?? issue.message}`;
|
|
102
94
|
})
|
|
103
95
|
.join("; ");
|
|
104
96
|
}
|
|
@@ -67,13 +67,13 @@ export function describeValidationError(error: unknown): string {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/** Parses a request body, answering 400 with a translatable message. */
|
|
70
|
-
export function parseBody<
|
|
70
|
+
export function parseBody<Output>(
|
|
71
71
|
body: unknown,
|
|
72
|
-
schema:
|
|
73
|
-
):
|
|
72
|
+
schema: z.ZodType<Output, z.ZodTypeDef, unknown>,
|
|
73
|
+
): Output {
|
|
74
74
|
return assertValidation(
|
|
75
75
|
body,
|
|
76
|
-
(value) => schema.parse(value)
|
|
76
|
+
(value) => schema.parse(value),
|
|
77
77
|
describeValidationError,
|
|
78
78
|
);
|
|
79
79
|
}
|
|
@@ -131,7 +131,7 @@ export const assetVisibilitySchema = z.object({
|
|
|
131
131
|
const MAX_PREVIEW_BATCH = 200;
|
|
132
132
|
|
|
133
133
|
export const previewIdsSchema = z.object({
|
|
134
|
-
ids: z.array(z.string().min(1)
|
|
134
|
+
ids: z.array(z.string().uuid()).min(1).max(MAX_PREVIEW_BATCH),
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
const normalizedRatio = z.number().min(0).max(1);
|
|
@@ -154,7 +154,7 @@ export const transformSchema = z
|
|
|
154
154
|
rotate: z
|
|
155
155
|
.number()
|
|
156
156
|
.refine((value) =>
|
|
157
|
-
ALLOWED_ROTATIONS.
|
|
157
|
+
ALLOWED_ROTATIONS.some((rotation) => rotation === value),
|
|
158
158
|
)
|
|
159
159
|
.optional(),
|
|
160
160
|
})
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.waitForTenant = waitForTenant;
|
|
4
|
-
exports.writeWhenReachable = writeWhenReachable;
|
|
5
|
-
const promises_1 = require("node:timers/promises");
|
|
6
|
-
const interface_database_1 = require("@antelopejs/interface-database");
|
|
7
|
-
const constants_1 = require("@antelopejs/interface-dms/constants");
|
|
8
|
-
const POLL_INTERVAL_MS = 500;
|
|
9
|
-
const MAX_RETRY_DELAY_MS = 5_000;
|
|
10
|
-
const TENANT_WAIT_MS = 5 * 60_000;
|
|
11
|
-
const STORAGE_WAIT_MS = 2 * 60_000;
|
|
12
|
-
const readyTenants = new Set();
|
|
13
|
-
async function hasTenantInstance(tenantId) {
|
|
14
|
-
try {
|
|
15
|
-
const schema = interface_database_1.Schema.get(constants_1.TENANT_SCHEMA_NAME);
|
|
16
|
-
if (!schema)
|
|
17
|
-
return false;
|
|
18
|
-
const instances = await schema.listInstances();
|
|
19
|
-
return instances.includes(tenantId);
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
async function waitForTenant(tenantId) {
|
|
26
|
-
if (readyTenants.has(tenantId))
|
|
27
|
-
return;
|
|
28
|
-
const deadline = Date.now() + TENANT_WAIT_MS;
|
|
29
|
-
while (!(await hasTenantInstance(tenantId))) {
|
|
30
|
-
if (Date.now() > deadline)
|
|
31
|
-
throw new Error(`Media tenant '${tenantId}' was not ready after ${TENANT_WAIT_MS / 1000}s: declare content from start() or a Hook.DATABASE_INITIALIZED handler, never awaited in construct()`);
|
|
32
|
-
await (0, promises_1.setTimeout)(POLL_INTERVAL_MS);
|
|
33
|
-
}
|
|
34
|
-
readyTenants.add(tenantId);
|
|
35
|
-
}
|
|
36
|
-
async function writeWhenReachable(write) {
|
|
37
|
-
const deadline = Date.now() + STORAGE_WAIT_MS;
|
|
38
|
-
let retryDelay = POLL_INTERVAL_MS;
|
|
39
|
-
for (;;) {
|
|
40
|
-
try {
|
|
41
|
-
return await write();
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
const isUnreachable = error instanceof TypeError;
|
|
45
|
-
if (!isUnreachable || Date.now() > deadline)
|
|
46
|
-
throw error;
|
|
47
|
-
}
|
|
48
|
-
await (0, promises_1.setTimeout)(retryDelay);
|
|
49
|
-
retryDelay = Math.min(retryDelay * 2, MAX_RETRY_DELAY_MS);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=readiness.js.map
|