@antelopejs/dms-media 0.6.1 → 0.7.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/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/declared/folders.js +3 -2
- package/dist/declared/folders.js.map +1 -1
- package/dist/declared/records.d.ts +2 -2
- package/dist/declared/records.js +3 -2
- package/dist/declared/records.js.map +1 -1
- package/dist/derivatives.js +9 -6
- 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/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.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/test/antelope.test.js +13 -12
- 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 +2 -1
- 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 +5 -5
- 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 +1 -0
- package/dist/test/integration/media-storage-origin-unreachable.test.js.map +1 -1
- 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/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.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.js +14 -8
- 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 +87 -0
- package/frontend-vue/app/build/library/libraryActions.ts +444 -0
- package/frontend-vue/app/build/library/libraryCore.ts +137 -0
- package/frontend-vue/app/components/FirstRun.vue +2 -1
- package/frontend-vue/app/components/ImageEditor.vue +22 -179
- package/frontend-vue/app/components/dialogs/DestinationDialog.vue +3 -3
- package/frontend-vue/app/components/field/FieldAltPopover.vue +2 -1
- package/frontend-vue/app/composables/library/useMediaLibrary.ts +3 -575
- package/frontend-vue/app/composables/useAssetFieldUploads.ts +9 -1
- package/frontend-vue/app/composables/useAssetLink.ts +33 -13
- package/frontend-vue/app/composables/useFileDetails.ts +6 -5
- package/frontend-vue/app/composables/useMediaApi.ts +21 -5
- package/frontend-vue/app/composables/useUploadFailureText.ts +24 -5
- package/frontend-vue/app/composables/useUploadQueue.ts +178 -44
- package/frontend-vue/app/composables/useUploadToasts.ts +81 -19
- 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 +4 -2
- package/frontend-vue/pnpm-lock.yaml +217 -61
- package/frontend-vue/tests/api-error-presentation.test.ts +183 -0
- package/frontend-vue/tests/backend-boundary.test.ts +203 -0
- package/frontend-vue/tests/fixtures/serverRender.ts +1 -1
- package/frontend-vue/tests/mediaPreviews.test.ts +39 -0
- package/package.json +5 -11
- package/skills/dms-media/SKILL.md +3 -2
- package/skills/dms-media/cases.json +38 -0
- package/src/acl/entries.ts +6 -4
- package/src/bindings.ts +3 -3
- package/src/declared/folders.ts +3 -3
- package/src/declared/records.ts +9 -8
- package/src/derivatives.ts +10 -6
- package/src/guards.ts +19 -0
- 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 +3 -2
- 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/test/antelope.test.ts +21 -17
- 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 +18 -19
- 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 +11 -20
- 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 +3 -2
- 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/library/fixtures.ts +9 -3
- package/src/test/unit/library/library.test.ts +1 -7
- package/src/test/unit/library/realtime.test.ts +1 -1
- 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 -12
- package/src/validation/media.schema.ts +6 -6
- package/frontend-vue/tests/engines.test.ts +0 -20
- package/frontend-vue/tests/locales.test.ts +0 -61
|
@@ -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
|
]);
|
|
@@ -85,7 +90,7 @@ export function describeDeclarationIssues(error: ZodError): string {
|
|
|
85
90
|
return error.issues
|
|
86
91
|
.map((issue) => {
|
|
87
92
|
const field = issue.path.join(".") || "declaration";
|
|
88
|
-
return `${field}: ${DECLARATION_ERROR_TEXTS
|
|
93
|
+
return `${field}: ${DECLARATION_ERROR_TEXTS.get(issue.message) ?? issue.message}`;
|
|
89
94
|
})
|
|
90
95
|
.join("; ");
|
|
91
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,20 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs'
|
|
2
|
-
import { join } from 'node:path'
|
|
3
|
-
import { describe, expect, it } from 'vitest'
|
|
4
|
-
|
|
5
|
-
type Manifest = { engines?: Record<string, string> }
|
|
6
|
-
|
|
7
|
-
function rendererRange(dir: string): string | undefined {
|
|
8
|
-
const manifest = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) as Manifest
|
|
9
|
-
return manifest.engines?.['@antelopejs/dms-frontend']
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// `ajs dms dev` refuses to start when a frontend module's range excludes the
|
|
13
|
-
// installed renderer, so the playground's own frontend must follow this layer.
|
|
14
|
-
describe('renderer range', () => {
|
|
15
|
-
it('is the same for the playground frontend as for this layer', () => {
|
|
16
|
-
const layer = rendererRange(join(__dirname, '..'))
|
|
17
|
-
expect(layer).toBeDefined()
|
|
18
|
-
expect(rendererRange(join(__dirname, '../../playground/frontend-vue'))).toBe(layer)
|
|
19
|
-
})
|
|
20
|
-
})
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { readdirSync, readFileSync, statSync } from 'node:fs'
|
|
2
|
-
import { join } from 'node:path'
|
|
3
|
-
import { describe, expect, it } from 'vitest'
|
|
4
|
-
|
|
5
|
-
type Messages = { [key: string]: string | Messages }
|
|
6
|
-
|
|
7
|
-
const LOCALES_DIR = join(__dirname, '../i18n/locales')
|
|
8
|
-
const APP_DIR = join(__dirname, '../app')
|
|
9
|
-
const KEY_PATTERN = /\bt\(\s*'(dms_media\.[a-z0-9_.-]+)'/g
|
|
10
|
-
// What one line of an overview KPI card holds at four columns (183px of 12px
|
|
11
|
-
// text at 1440px wide): a detail on two lines makes the cards taller than their
|
|
12
|
-
// skeleton, and every block below moves when they land.
|
|
13
|
-
const KPI_DETAIL_MAX_LENGTH = 32
|
|
14
|
-
const KPI_DETAILS = ['files_detail', 'storage_detail', 'storage_quota_detail', 'public_share', 'missing_alt_none', 'missing_alt_public']
|
|
15
|
-
// The widest values a detail is written with.
|
|
16
|
-
const WIDEST_PARAMS: Record<string, string> = { files: '99,999', percent: '100', quota: '100 GB' }
|
|
17
|
-
|
|
18
|
-
function load(file: string): Messages {
|
|
19
|
-
return JSON.parse(readFileSync(join(LOCALES_DIR, file), 'utf8')) as Messages
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function leaves(messages: Messages, prefix = ''): string[] {
|
|
23
|
-
return Object.entries(messages).flatMap(([key, value]) =>
|
|
24
|
-
typeof value === 'string' ? [`${prefix}${key}`] : leaves(value, `${prefix}${key}.`),
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function sources(dir: string): string[] {
|
|
29
|
-
return readdirSync(dir).flatMap((entry) => {
|
|
30
|
-
const path = join(dir, entry)
|
|
31
|
-
if (statSync(path).isDirectory()) return sources(path)
|
|
32
|
-
return /\.(vue|ts)$/.test(entry) ? [path] : []
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
describe('media locales', () => {
|
|
37
|
-
const english = load('media-en-GB.json')
|
|
38
|
-
const french = load('media-fr-FR.json')
|
|
39
|
-
|
|
40
|
-
it('declares the same keys in English and French', () => {
|
|
41
|
-
expect(leaves(french).sort()).toEqual(leaves(english).sort())
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
it('keeps each overview KPI detail on one line of its card', () => {
|
|
45
|
-
for (const messages of [english, french]) {
|
|
46
|
-
const kpis = ((messages.dms_media as Messages).overview as Messages).kpis as Messages
|
|
47
|
-
const written = KPI_DETAILS.flatMap((key) =>
|
|
48
|
-
(kpis[key] as string).split(' | ').map((form) => form.replace(/\{(\w+)\}/g, (_, name: string) => WIDEST_PARAMS[name] ?? name)),
|
|
49
|
-
)
|
|
50
|
-
expect(written.filter((text) => text.length > KPI_DETAIL_MAX_LENGTH)).toEqual([])
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
it('translates every literal key the layer uses', () => {
|
|
55
|
-
const known = new Set(leaves(english))
|
|
56
|
-
const used = sources(APP_DIR).flatMap((file) =>
|
|
57
|
-
[...readFileSync(file, 'utf8').matchAll(KEY_PATTERN)].map((match) => match[1]!),
|
|
58
|
-
)
|
|
59
|
-
expect(used.filter((key) => !known.has(key))).toEqual([])
|
|
60
|
-
})
|
|
61
|
-
})
|