@antelopejs/dms-media 0.6.2 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -23
- package/dist/acl/entries.js +2 -1
- package/dist/acl/entries.js.map +1 -1
- package/dist/asset-lifecycle.js.map +1 -1
- package/dist/db/models/mediaAssets.model.d.ts +7 -5
- package/dist/db/models/mediaDeclarations.model.d.ts +7 -5
- package/dist/db/models/mediaEvents.model.d.ts +7 -5
- package/dist/db/models/mediaFavorites.model.d.ts +7 -5
- package/dist/db/models/mediaFolders.model.d.ts +7 -5
- package/dist/db/models/mediaUploads.model.d.ts +7 -5
- package/dist/declared/assets.js +2 -5
- package/dist/declared/assets.js.map +1 -1
- package/dist/declared/records.d.ts +2 -1
- package/dist/declared/records.js.map +1 -1
- package/dist/library/activity.js +2 -1
- package/dist/library/activity.js.map +1 -1
- package/dist/routes/media/manage.js +2 -2
- package/dist/routes/media/manage.js.map +1 -1
- package/dist/routes/media/storage-keys.js.map +1 -1
- package/dist/test/antelope.test.js +7 -5
- package/dist/test/antelope.test.js.map +1 -1
- package/dist/test/helpers/assets.d.ts +24 -5
- package/dist/test/helpers/assets.js +22 -7
- package/dist/test/helpers/assets.js.map +1 -1
- package/dist/test/helpers/bodies.d.ts +31 -0
- package/dist/test/helpers/bodies.js +16 -0
- package/dist/test/helpers/bodies.js.map +1 -0
- package/dist/test/helpers/folders.d.ts +50 -0
- package/dist/test/helpers/folders.js +4 -2
- package/dist/test/helpers/folders.js.map +1 -1
- package/dist/test/helpers/members.js +10 -3
- package/dist/test/helpers/members.js.map +1 -1
- package/dist/test/helpers/owner.js +6 -1
- package/dist/test/helpers/owner.js.map +1 -1
- package/dist/test/helpers/permissions-world.d.ts +132 -11
- package/dist/test/helpers/permissions-world.js +21 -2
- package/dist/test/helpers/permissions-world.js.map +1 -1
- package/dist/test/helpers/setup-token.d.ts +1 -0
- package/dist/test/helpers/setup-token.js +5 -0
- package/dist/test/helpers/setup-token.js.map +1 -0
- package/dist/test/integration/derivative-sweep-query.test.js +1 -2
- package/dist/test/integration/derivative-sweep-query.test.js.map +1 -1
- package/dist/test/integration/folder-cascade.test.js +3 -1
- package/dist/test/integration/folder-cascade.test.js.map +1 -1
- package/dist/test/integration/media-activity-overview.test.js +39 -12
- package/dist/test/integration/media-activity-overview.test.js.map +1 -1
- package/dist/test/integration/media-api.test.js +22 -21
- package/dist/test/integration/media-api.test.js.map +1 -1
- package/dist/test/integration/media-bindings.test.js +6 -5
- package/dist/test/integration/media-bindings.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 +12 -2
- package/dist/test/integration/media-delivery-editing.test.js.map +1 -1
- package/dist/test/integration/media-delivery.test.js +5 -3
- package/dist/test/integration/media-delivery.test.js.map +1 -1
- package/dist/test/integration/media-explorer-writes.test.js +6 -4
- package/dist/test/integration/media-explorer-writes.test.js.map +1 -1
- package/dist/test/integration/media-guards.test.js +11 -16
- package/dist/test/integration/media-guards.test.js.map +1 -1
- package/dist/test/integration/media-library.test.js +73 -23
- package/dist/test/integration/media-library.test.js.map +1 -1
- package/dist/test/integration/media-linked-subfolders.test.js +3 -2
- package/dist/test/integration/media-linked-subfolders.test.js.map +1 -1
- package/dist/test/integration/media-member-access.test.js +18 -2
- package/dist/test/integration/media-member-access.test.js.map +1 -1
- package/dist/test/integration/media-permissions.test.js +7 -2
- package/dist/test/integration/media-permissions.test.js.map +1 -1
- package/dist/test/integration/media-project-field.test.js +17 -2
- package/dist/test/integration/media-project-field.test.js.map +1 -1
- package/dist/test/integration/media-search-views.test.js +24 -10
- package/dist/test/integration/media-search-views.test.js.map +1 -1
- package/dist/test/integration/media-storage-origin-unreachable.test.js +2 -1
- package/dist/test/integration/media-storage-origin-unreachable.test.js.map +1 -1
- package/dist/test/integration/media-transform.test.js +8 -9
- package/dist/test/integration/media-transform.test.js.map +1 -1
- package/dist/test/integration/media-upload-history-filters.test.d.ts +1 -0
- package/dist/test/integration/media-upload-history-filters.test.js +67 -0
- package/dist/test/integration/media-upload-history-filters.test.js.map +1 -0
- package/dist/test/integration/media-upload-policy.test.js +31 -14
- package/dist/test/integration/media-upload-policy.test.js.map +1 -1
- package/dist/test/integration/permissions-management.js +15 -4
- package/dist/test/integration/permissions-management.js.map +1 -1
- package/dist/test/unit/declared.test.js +1 -1
- package/dist/test/unit/declared.test.js.map +1 -1
- package/dist/test/unit/library/zip-names.test.js +22 -4
- package/dist/test/unit/library/zip-names.test.js.map +1 -1
- package/dist/test/unit/upload-rules.test.js +10 -0
- package/dist/test/unit/upload-rules.test.js.map +1 -1
- package/dist/transform-ops.js.map +1 -1
- package/dist/upload-policy.js +11 -11
- package/dist/upload-policy.js.map +1 -1
- package/dist/validation/declared.schema.d.ts +4 -4
- package/dist/validation/library.schema.d.ts +10 -10
- package/dist/validation/media.schema.d.ts +8 -9
- package/dist/validation/media.schema.js +4 -6
- package/dist/validation/media.schema.js.map +1 -1
- package/frontend-vue/app/build/imageEditor/useEditorSaving.ts +3 -2
- package/frontend-vue/app/build/library/libraryCore.ts +2 -1
- package/frontend-vue/app/components/FirstRun.vue +2 -1
- 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/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/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/package.json +3 -3
- package/frontend-vue/tests/api-error-presentation.test.ts +183 -0
- package/frontend-vue/tests/fixtures/serverRender.ts +1 -1
- package/package.json +12 -11
- package/skills/dms-media/SKILL.md +2 -2
- package/src/acl/entries.ts +5 -2
- package/src/asset-lifecycle.ts +2 -1
- package/src/declared/assets.ts +6 -6
- package/src/declared/records.ts +5 -1
- package/src/library/activity.ts +3 -1
- package/src/routes/media/manage.ts +2 -2
- package/src/routes/media/storage-keys.ts +1 -0
- package/src/test/antelope.test.ts +7 -5
- package/src/test/helpers/assets.ts +28 -15
- package/src/test/helpers/bodies.ts +22 -0
- package/src/test/helpers/folders.ts +6 -3
- package/src/test/helpers/members.ts +11 -3
- package/src/test/helpers/owner.ts +6 -1
- package/src/test/helpers/permissions-world.ts +23 -19
- package/src/test/helpers/setup-token.ts +6 -0
- package/src/test/integration/derivative-sweep-query.test.ts +4 -3
- package/src/test/integration/folder-cascade.test.ts +3 -1
- package/src/test/integration/media-activity-overview.test.ts +52 -37
- package/src/test/integration/media-api.test.ts +25 -27
- package/src/test/integration/media-bindings.test.ts +10 -16
- package/src/test/integration/media-declared-content.test.ts +2 -1
- package/src/test/integration/media-delivery-editing.test.ts +13 -2
- package/src/test/integration/media-delivery.test.ts +8 -3
- package/src/test/integration/media-explorer-writes.test.ts +6 -4
- package/src/test/integration/media-guards.test.ts +18 -13
- package/src/test/integration/media-library.test.ts +101 -47
- package/src/test/integration/media-linked-subfolders.test.ts +3 -2
- package/src/test/integration/media-member-access.test.ts +22 -24
- package/src/test/integration/media-permissions.test.ts +11 -5
- package/src/test/integration/media-project-field.test.ts +21 -9
- package/src/test/integration/media-search-views.test.ts +35 -31
- package/src/test/integration/media-storage-origin-unreachable.test.ts +2 -1
- package/src/test/integration/media-transform.test.ts +8 -9
- package/src/test/integration/media-upload-history-filters.test.ts +77 -0
- package/src/test/integration/media-upload-policy.test.ts +39 -20
- package/src/test/integration/permissions-management.ts +16 -4
- package/src/test/unit/declared.test.ts +4 -1
- package/src/test/unit/library/zip-names.test.ts +26 -7
- package/src/test/unit/upload-rules.test.ts +11 -0
- package/src/transform-ops.ts +1 -0
- package/src/upload-policy.ts +11 -11
- package/src/validation/media.schema.ts +8 -8
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { AxiosInstance } from "axios";
|
|
2
|
-
import axios from "axios";
|
|
3
2
|
import { expect } from "chai";
|
|
4
3
|
import sharp from "sharp";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { putPresigned } from "../helpers/assets";
|
|
6
|
+
import { createdBody, presignBody, readBody } from "../helpers/bodies";
|
|
5
7
|
import { authorizedClient } from "../helpers/http";
|
|
6
8
|
import { ensureOwnerSession } from "../helpers/owner";
|
|
7
9
|
|
|
@@ -41,19 +43,16 @@ async function uploadAsset(
|
|
|
41
43
|
mimetype,
|
|
42
44
|
});
|
|
43
45
|
expect(presign.status).to.equal(HTTP_OK);
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
validateStatus: () => true,
|
|
47
|
-
transformRequest: [(data) => data],
|
|
48
|
-
});
|
|
46
|
+
const presigned = readBody(presign, presignBody);
|
|
47
|
+
const put = await putPresigned(presigned, body);
|
|
49
48
|
expect(put.status).to.be.lessThan(300);
|
|
50
49
|
const confirm = await client.post("/api/media/upload/confirm", {
|
|
51
50
|
folderId,
|
|
52
|
-
resourceKey:
|
|
51
|
+
resourceKey: presigned.resourceKey,
|
|
53
52
|
filename,
|
|
54
53
|
});
|
|
55
54
|
expect(confirm.status).to.equal(HTTP_OK);
|
|
56
|
-
return confirm.
|
|
55
|
+
return readBody(confirm, z.object({ asset: createdBody })).asset.id;
|
|
57
56
|
}
|
|
58
57
|
|
|
59
58
|
function uploadImage(
|
|
@@ -77,7 +76,7 @@ describe("[integration] media transform — crop, rotate, revert", () => {
|
|
|
77
76
|
name: "Transforms",
|
|
78
77
|
});
|
|
79
78
|
expect(folder.status).to.equal(HTTP_OK);
|
|
80
|
-
folderId = folder.
|
|
79
|
+
folderId = readBody(folder, createdBody).id;
|
|
81
80
|
assetId = await uploadImage(client, folderId, await buildTestImage());
|
|
82
81
|
});
|
|
83
82
|
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { AxiosInstance } from "axios";
|
|
2
|
+
import { expect } from "chai";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { createdBody, readBody } from "../helpers/bodies";
|
|
5
|
+
import { authorizedClient } from "../helpers/http";
|
|
6
|
+
import { ensureOwnerSession } from "../helpers/owner";
|
|
7
|
+
|
|
8
|
+
const HTTP_OK = 200;
|
|
9
|
+
const BATCH_ID = "batch-history-filters";
|
|
10
|
+
const BATCH_TOTAL = 4;
|
|
11
|
+
const BATCH_UPLOADED = 3;
|
|
12
|
+
const BATCH_FAILED = 1;
|
|
13
|
+
const BATCH_SIZE = 300;
|
|
14
|
+
|
|
15
|
+
const batchesBody = z.object({
|
|
16
|
+
total: z.number(),
|
|
17
|
+
results: z.array(z.object({ _id: z.string() })),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const INHERITED_COLUMNS: ReadonlyArray<readonly [string, string]> = [
|
|
21
|
+
["constructor", "function Object() { [native code] }"],
|
|
22
|
+
["toString", "function toString() { [native code] }"],
|
|
23
|
+
["hasOwnProperty", "function hasOwnProperty() { [native code] }"],
|
|
24
|
+
["__proto__", "[object Object]"],
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
describe("[integration] upload history — row filters", () => {
|
|
28
|
+
let client: AxiosInstance;
|
|
29
|
+
|
|
30
|
+
async function listBatches(filters: Record<string, string>) {
|
|
31
|
+
const response = await client.get("/api/media/upload/batches", {
|
|
32
|
+
params: filters,
|
|
33
|
+
});
|
|
34
|
+
expect(response.status).to.equal(HTTP_OK);
|
|
35
|
+
return readBody(response, batchesBody);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
before(async function () {
|
|
39
|
+
this.timeout(30_000);
|
|
40
|
+
const session = await ensureOwnerSession();
|
|
41
|
+
client = authorizedClient(session.accessToken);
|
|
42
|
+
const folderId = readBody(
|
|
43
|
+
await client.post("/api/media/folders", { name: "History filters spec" }),
|
|
44
|
+
createdBody,
|
|
45
|
+
).id;
|
|
46
|
+
const report = await client.post("/api/media/upload/batches", {
|
|
47
|
+
batchId: BATCH_ID,
|
|
48
|
+
folderId,
|
|
49
|
+
total: BATCH_TOTAL,
|
|
50
|
+
uploaded: BATCH_UPLOADED,
|
|
51
|
+
failed: BATCH_FAILED,
|
|
52
|
+
size: BATCH_SIZE,
|
|
53
|
+
});
|
|
54
|
+
expect(report.status).to.equal(HTTP_OK);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("keeps the batch a filter on one of its columns matches", async () => {
|
|
58
|
+
const body = await listBatches({ filter__id: `eq:${BATCH_ID}` });
|
|
59
|
+
expect(body.results.map((row) => row._id)).to.deep.equal([BATCH_ID]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("drops the batch a filter on an unknown column cannot match", async () => {
|
|
63
|
+
const body = await listBatches({ filter_nonexistent: `eq:${BATCH_ID}` });
|
|
64
|
+
expect(body.results).to.deep.equal([]);
|
|
65
|
+
expect(body.total).to.equal(0);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
for (const [column, inheritedText] of INHERITED_COLUMNS) {
|
|
69
|
+
it(`treats the inherited member ${column} like an unknown column`, async () => {
|
|
70
|
+
const body = await listBatches({
|
|
71
|
+
[`filter_${column}`]: `eq:${inheritedText}`,
|
|
72
|
+
});
|
|
73
|
+
expect(body.results).to.deep.equal([]);
|
|
74
|
+
expect(body.total).to.equal(0);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
@@ -16,7 +16,8 @@ import {
|
|
|
16
16
|
} from "../../config";
|
|
17
17
|
import { runPurgeStaging } from "../../crons/purge-staging";
|
|
18
18
|
import { MediaFolderModel } from "../../db";
|
|
19
|
-
import { uploadAsset, uploadPixelPng } from "../helpers/assets";
|
|
19
|
+
import { putPresigned, uploadAsset, uploadPixelPng } from "../helpers/assets";
|
|
20
|
+
import { createdBody, presignBody, readBody } from "../helpers/bodies";
|
|
20
21
|
import { fetchFolderNodes } from "../helpers/folders";
|
|
21
22
|
import { authorizedClient } from "../helpers/http";
|
|
22
23
|
import { ensureOwnerSession } from "../helpers/owner";
|
|
@@ -92,13 +93,10 @@ describe("[integration] media upload policy — types, quota, real content and s
|
|
|
92
93
|
body.byteLength,
|
|
93
94
|
);
|
|
94
95
|
expect(presigned.status, "presign").to.equal(HTTP_OK);
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
validateStatus: () => true,
|
|
98
|
-
transformRequest: [(data) => data],
|
|
99
|
-
});
|
|
96
|
+
const target = readBody(presigned, presignBody);
|
|
97
|
+
const put = await putPresigned(target, body);
|
|
100
98
|
expect(put.status, "storage PUT").to.be.lessThan(HTTP_REDIRECT_BOUNDARY);
|
|
101
|
-
return { resourceKey:
|
|
99
|
+
return { resourceKey: target.resourceKey };
|
|
102
100
|
}
|
|
103
101
|
|
|
104
102
|
before(async function () {
|
|
@@ -114,7 +112,7 @@ describe("[integration] media upload policy — types, quota, real content and s
|
|
|
114
112
|
name: "Upload policy",
|
|
115
113
|
});
|
|
116
114
|
expect(folder.status).to.equal(HTTP_OK);
|
|
117
|
-
folderId = folder.
|
|
115
|
+
folderId = readBody(folder, createdBody).id;
|
|
118
116
|
});
|
|
119
117
|
|
|
120
118
|
after(async () => {
|
|
@@ -228,29 +226,50 @@ describe("[integration] media upload policy — types, quota, real content and s
|
|
|
228
226
|
expect(await FileExists(staged.resourceKey)).to.equal(false);
|
|
229
227
|
});
|
|
230
228
|
|
|
229
|
+
it("confirms a text file declared with the name of an Object.prototype member", async () => {
|
|
230
|
+
configureMediaModule({ ...initialConfig, allowedMimetypes: ["*"] });
|
|
231
|
+
try {
|
|
232
|
+
for (const mimetype of ["constructor", "__proto__"]) {
|
|
233
|
+
const filename = `${mimetype.replaceAll("_", "")}.txt`;
|
|
234
|
+
const staged = await stage(
|
|
235
|
+
filename,
|
|
236
|
+
mimetype,
|
|
237
|
+
Buffer.from("plain text"),
|
|
238
|
+
);
|
|
239
|
+
const confirm = await client.post("/api/media/upload/confirm", {
|
|
240
|
+
folderId,
|
|
241
|
+
resourceKey: staged.resourceKey,
|
|
242
|
+
filename,
|
|
243
|
+
});
|
|
244
|
+
expect(confirm.status, mimetype).to.equal(HTTP_OK);
|
|
245
|
+
}
|
|
246
|
+
} finally {
|
|
247
|
+
configureMediaModule(initialConfig);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
231
251
|
it("deletes the staged file when the folder disappeared before confirm", async () => {
|
|
232
252
|
const doomed = await client.post("/api/media/folders", {
|
|
233
253
|
name: "Doomed upload target",
|
|
234
254
|
});
|
|
235
255
|
const body = Buffer.from("bytes");
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
"x.txt",
|
|
239
|
-
|
|
240
|
-
body.byteLength,
|
|
256
|
+
const doomedId = readBody(doomed, createdBody).id;
|
|
257
|
+
const presigned = readBody(
|
|
258
|
+
await presign(doomedId, "x.txt", "text/plain", body.byteLength),
|
|
259
|
+
presignBody,
|
|
241
260
|
);
|
|
242
|
-
await axios.put(presigned.
|
|
243
|
-
headers: presigned.
|
|
244
|
-
transformRequest: [(data) => data],
|
|
261
|
+
await axios.put(presigned.uploadUrl, body, {
|
|
262
|
+
headers: presigned.headers,
|
|
263
|
+
transformRequest: [(data: Buffer) => data],
|
|
245
264
|
});
|
|
246
|
-
await client.delete(`/api/media/folders/${
|
|
265
|
+
await client.delete(`/api/media/folders/${doomedId}`);
|
|
247
266
|
const confirm = await client.post("/api/media/upload/confirm", {
|
|
248
|
-
folderId:
|
|
249
|
-
resourceKey: presigned.
|
|
267
|
+
folderId: doomedId,
|
|
268
|
+
resourceKey: presigned.resourceKey,
|
|
250
269
|
filename: "x.txt",
|
|
251
270
|
});
|
|
252
271
|
expect(confirm.status).to.be.greaterThanOrEqual(400);
|
|
253
|
-
expect(await FileExists(presigned.
|
|
272
|
+
expect(await FileExists(presigned.resourceKey)).to.equal(false);
|
|
254
273
|
});
|
|
255
274
|
|
|
256
275
|
it("deletes a staged file on abort", async () => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AxiosInstance } from "axios";
|
|
2
2
|
import { expect } from "chai";
|
|
3
|
+
import { z } from "zod";
|
|
3
4
|
import { RegisterAssetBinding } from "@antelopejs/interface-dms-media";
|
|
4
5
|
import { GetPermissionId } from "@antelopejs/interface-dms/page";
|
|
5
6
|
import { UserModel } from "@antelopejs/interface-dms/auth/db";
|
|
@@ -8,6 +9,7 @@ import { GetModel } from "@antelopejs/interface-database-decorators";
|
|
|
8
9
|
import { MediaUploadsPage } from "../../pages/uploads";
|
|
9
10
|
import { uploadAvailability } from "../../pages/upload-availability";
|
|
10
11
|
import { MEDIA_ROUTES } from "../../library/links";
|
|
12
|
+
import { createdBody, readBody } from "../helpers/bodies";
|
|
11
13
|
import { readFolderAcl, writeFolderAcl } from "../helpers/folders";
|
|
12
14
|
import { readPageAccess } from "../helpers/pages";
|
|
13
15
|
import { setRolePermissions } from "../helpers/members";
|
|
@@ -35,6 +37,14 @@ import {
|
|
|
35
37
|
WAREHOUSE_VIEW_PERMISSION,
|
|
36
38
|
} from "../helpers/permissions-world";
|
|
37
39
|
|
|
40
|
+
const pageLayoutBody = z.object({
|
|
41
|
+
layout: z.object({
|
|
42
|
+
options: z.object({
|
|
43
|
+
headerActions: z.array(z.object({ disabled: z.boolean().optional() })),
|
|
44
|
+
}),
|
|
45
|
+
}),
|
|
46
|
+
});
|
|
47
|
+
|
|
38
48
|
/** Folder management and ACL edition, run after the transform suites. */
|
|
39
49
|
export function folderManagementSuites(): void {
|
|
40
50
|
describe("folder management and ACL edition", () => {
|
|
@@ -58,7 +68,7 @@ function folderManagementTests(): void {
|
|
|
58
68
|
{ name: "Managed" },
|
|
59
69
|
);
|
|
60
70
|
expect(created.status).to.equal(HTTP_OK);
|
|
61
|
-
const managedId = created.
|
|
71
|
+
const managedId = readBody(created, createdBody).id;
|
|
62
72
|
const renamed = await sessions.folderManager.client.post(
|
|
63
73
|
`/api/media/folders/${managedId}/rename`,
|
|
64
74
|
{ name: "Managed renamed" },
|
|
@@ -93,7 +103,7 @@ function folderManagementTests(): void {
|
|
|
93
103
|
{ name: "Nomad" },
|
|
94
104
|
);
|
|
95
105
|
expect(created.status).to.equal(HTTP_OK);
|
|
96
|
-
const nomadId = created.
|
|
106
|
+
const nomadId = readBody(created, createdBody).id;
|
|
97
107
|
const invisibleTarget = await sessions.folderManager.client.post(
|
|
98
108
|
`/api/media/folders/${nomadId}/move`,
|
|
99
109
|
{ parentId: folders.restricted },
|
|
@@ -216,7 +226,9 @@ export function laterPermissionSuites(): void {
|
|
|
216
226
|
params: { slug: MEDIA_ROUTES.uploads },
|
|
217
227
|
});
|
|
218
228
|
expect(layout.status).to.equal(HTTP_OK);
|
|
219
|
-
|
|
229
|
+
const [button] = readBody(layout, pageLayoutBody).layout.options
|
|
230
|
+
.headerActions;
|
|
231
|
+
return button;
|
|
220
232
|
}
|
|
221
233
|
|
|
222
234
|
async function latecomerAvailability() {
|
|
@@ -230,7 +242,7 @@ export function laterPermissionSuites(): void {
|
|
|
230
242
|
|
|
231
243
|
it("serves the uploads page to the owner with the button enabled", async () => {
|
|
232
244
|
const button = await uploadButton(owner);
|
|
233
|
-
expect(button
|
|
245
|
+
expect(button?.disabled).to.not.equal(true);
|
|
234
246
|
});
|
|
235
247
|
|
|
236
248
|
it("keeps the uploads page from members: module pages are owner-only", async () => {
|
|
@@ -30,6 +30,7 @@ describe("[unit] declared content — declarations", () => {
|
|
|
30
30
|
tenantId: "default",
|
|
31
31
|
key: "helio.bad",
|
|
32
32
|
name: "a/b",
|
|
33
|
+
// @ts-expect-error "secret" is outside MediaFolderVisibility, and parseDeclaration must refuse it naming the visibility field
|
|
33
34
|
visibility: "secret",
|
|
34
35
|
},
|
|
35
36
|
declaredFolderSchema,
|
|
@@ -63,7 +64,9 @@ describe("[unit] declared content — declarations", () => {
|
|
|
63
64
|
it("keeps running a key after a failed declaration", async () => {
|
|
64
65
|
const failing = withDeclarationLock("default", "asset", "k", async () => {
|
|
65
66
|
throw new Error("boom");
|
|
66
|
-
}).catch((error:
|
|
67
|
+
}).catch((error: unknown) =>
|
|
68
|
+
error instanceof Error ? error.message : String(error),
|
|
69
|
+
);
|
|
67
70
|
const next = withDeclarationLock("default", "asset", "k", async () => "ok");
|
|
68
71
|
expect(await failing).to.equal("boom");
|
|
69
72
|
expect(await next).to.equal("ok");
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
import { HTTPResult } from "@antelopejs/interface-api";
|
|
1
2
|
import { expect } from "chai";
|
|
3
|
+
import { z } from "zod";
|
|
2
4
|
import { portableName, uniqueEntryName } from "../../../library/zip";
|
|
3
5
|
import {
|
|
4
6
|
comparableName,
|
|
5
|
-
|
|
7
|
+
parseBody,
|
|
6
8
|
updateAssetSchema,
|
|
7
9
|
} from "../../../validation/media.schema";
|
|
8
10
|
|
|
11
|
+
const HTTP_BAD_REQUEST = 400;
|
|
9
12
|
const LONG_NAME_LENGTH = 255;
|
|
10
13
|
const PORTABLE_LIMIT = 150;
|
|
11
14
|
|
|
@@ -43,13 +46,29 @@ describe("[unit] library/zip — entry names and name rules", () => {
|
|
|
43
46
|
});
|
|
44
47
|
|
|
45
48
|
it("turns validation failures into i18n keys", () => {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
const refused = (parse: () => void): HTTPResult => {
|
|
50
|
+
try {
|
|
51
|
+
parse();
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (error instanceof HTTPResult) return error;
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
throw new Error("expected the body to be refused");
|
|
57
|
+
};
|
|
58
|
+
const forbidden = refused(() =>
|
|
59
|
+
parseBody({ name: "a|b.png" }, updateAssetSchema),
|
|
50
60
|
);
|
|
51
|
-
expect(
|
|
52
|
-
|
|
61
|
+
expect(forbidden.getStatus()).to.equal(HTTP_BAD_REQUEST);
|
|
62
|
+
expect(forbidden.getBody()).to.equal("$dms_media.errors.name_forbidden");
|
|
63
|
+
const crashed = refused(() =>
|
|
64
|
+
parseBody(
|
|
65
|
+
{},
|
|
66
|
+
z.unknown().transform(() => {
|
|
67
|
+
throw new Error("boom");
|
|
68
|
+
}),
|
|
69
|
+
),
|
|
53
70
|
);
|
|
71
|
+
expect(crashed.getStatus()).to.equal(HTTP_BAD_REQUEST);
|
|
72
|
+
expect(crashed.getBody()).to.equal("$dms_media.errors.invalid_request");
|
|
54
73
|
});
|
|
55
74
|
});
|
|
@@ -69,4 +69,15 @@ describe("[unit] upload rules — free names and accepted types", () => {
|
|
|
69
69
|
expect(expectedImageFormat("image/svg+xml")).to.equal(undefined);
|
|
70
70
|
expect(expectedImageFormat("image/x-icon")).to.equal(undefined);
|
|
71
71
|
});
|
|
72
|
+
|
|
73
|
+
it("expects no decodable format for a type named like an Object.prototype member", () => {
|
|
74
|
+
for (const mimetype of [
|
|
75
|
+
"constructor",
|
|
76
|
+
"toString",
|
|
77
|
+
"__proto__",
|
|
78
|
+
"Constructor; x=y",
|
|
79
|
+
]) {
|
|
80
|
+
expect(expectedImageFormat(mimetype), mimetype).to.equal(undefined);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
72
83
|
});
|
package/src/transform-ops.ts
CHANGED
|
@@ -75,5 +75,6 @@ export function composeTransforms(
|
|
|
75
75
|
|
|
76
76
|
export function parseTransform(json: string | undefined): ImageTransformOps {
|
|
77
77
|
if (!json) return {};
|
|
78
|
+
// SAFETY: json_transform is written only as "" or the JSON.stringify of the cumulative ImageTransformOps (transform.ts), so a non-empty value is that object; a schema parse of a stored row on read is excluded by ruling.
|
|
78
79
|
return JSON.parse(json) as ImageTransformOps;
|
|
79
80
|
}
|
package/src/upload-policy.ts
CHANGED
|
@@ -34,16 +34,16 @@ const REFUSED_EXTENSIONS = new Set([
|
|
|
34
34
|
]);
|
|
35
35
|
|
|
36
36
|
/** Image formats sharp decodes: a file declared as one of them must decode. */
|
|
37
|
-
const DECODABLE_IMAGE_MIMETYPES
|
|
38
|
-
"image/jpeg"
|
|
39
|
-
"image/jpg"
|
|
40
|
-
"image/pjpeg"
|
|
41
|
-
"image/png"
|
|
42
|
-
"image/webp"
|
|
43
|
-
"image/gif"
|
|
44
|
-
"image/avif"
|
|
45
|
-
"image/tiff"
|
|
46
|
-
|
|
37
|
+
const DECODABLE_IMAGE_MIMETYPES = new Map([
|
|
38
|
+
["image/jpeg", "jpeg"],
|
|
39
|
+
["image/jpg", "jpeg"],
|
|
40
|
+
["image/pjpeg", "jpeg"],
|
|
41
|
+
["image/png", "png"],
|
|
42
|
+
["image/webp", "webp"],
|
|
43
|
+
["image/gif", "gif"],
|
|
44
|
+
["image/avif", "heif"],
|
|
45
|
+
["image/tiff", "tiff"],
|
|
46
|
+
]);
|
|
47
47
|
|
|
48
48
|
/** Mimetype of what sharp actually read, to store instead of the claim. */
|
|
49
49
|
const MIMETYPES_BY_FORMAT = new Map([
|
|
@@ -90,7 +90,7 @@ export function isUploadTypeAllowed(
|
|
|
90
90
|
|
|
91
91
|
/** sharp's format name for a declared image type it must be able to decode. */
|
|
92
92
|
export function expectedImageFormat(mimetype: string): string | undefined {
|
|
93
|
-
return DECODABLE_IMAGE_MIMETYPES
|
|
93
|
+
return DECODABLE_IMAGE_MIMETYPES.get(normalizeMimetype(mimetype));
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
export function mimetypeOfFormat(
|
|
@@ -60,13 +60,10 @@ export function comparableName(name: string): string {
|
|
|
60
60
|
return name.trim().normalize("NFC").toLocaleLowerCase();
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** Parses a request body, answering 400 with a translatable message. */
|
|
63
|
+
/**
|
|
64
|
+
* Parses a request body, answering 400 with the first validation message when
|
|
65
|
+
* it is an i18n key and a generic one otherwise.
|
|
66
|
+
*/
|
|
70
67
|
export function parseBody<Output>(
|
|
71
68
|
body: unknown,
|
|
72
69
|
schema: z.ZodType<Output, z.ZodTypeDef, unknown>,
|
|
@@ -74,7 +71,10 @@ export function parseBody<Output>(
|
|
|
74
71
|
return assertValidation(
|
|
75
72
|
body,
|
|
76
73
|
(value) => schema.parse(value),
|
|
77
|
-
|
|
74
|
+
(error) => {
|
|
75
|
+
const message = error instanceof ZodError ? error.issues[0]?.message : "";
|
|
76
|
+
return message?.startsWith("$") ? message : MEDIA_ERRORS.invalidRequest;
|
|
77
|
+
},
|
|
78
78
|
);
|
|
79
79
|
}
|
|
80
80
|
|