@antelopejs/dms-media 0.7.0 → 0.7.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.
Files changed (176) hide show
  1. package/README.md +18 -24
  2. package/dist/acl/entries.js +2 -1
  3. package/dist/acl/entries.js.map +1 -1
  4. package/dist/asset-lifecycle.js.map +1 -1
  5. package/dist/config.js.map +1 -1
  6. package/dist/db/models/mediaAssets.model.d.ts +7 -5
  7. package/dist/db/models/mediaDeclarations.model.d.ts +7 -5
  8. package/dist/db/models/mediaEvents.model.d.ts +7 -5
  9. package/dist/db/models/mediaFavorites.model.d.ts +7 -5
  10. package/dist/db/models/mediaFolders.model.d.ts +7 -5
  11. package/dist/db/models/mediaUploads.model.d.ts +7 -5
  12. package/dist/declared/assets.js +3 -7
  13. package/dist/declared/assets.js.map +1 -1
  14. package/dist/declared/records.d.ts +2 -1
  15. package/dist/declared/records.js.map +1 -1
  16. package/dist/library/activity.d.ts +1 -1
  17. package/dist/library/activity.js +2 -1
  18. package/dist/library/activity.js.map +1 -1
  19. package/dist/pages/uploads.js +1 -1
  20. package/dist/pages/uploads.js.map +1 -1
  21. package/dist/routes/media/asset-actions.js +12 -4
  22. package/dist/routes/media/asset-actions.js.map +1 -1
  23. package/dist/routes/media/manage.js +2 -2
  24. package/dist/routes/media/manage.js.map +1 -1
  25. package/dist/routes/media/overview.js +5 -1
  26. package/dist/routes/media/overview.js.map +1 -1
  27. package/dist/routes/media/storage-keys.js.map +1 -1
  28. package/dist/routes/media/upload.js +1 -3
  29. package/dist/routes/media/upload.js.map +1 -1
  30. package/dist/test/antelope.test.js +13 -6
  31. package/dist/test/antelope.test.js.map +1 -1
  32. package/dist/test/helpers/assets.d.ts +24 -5
  33. package/dist/test/helpers/assets.js +22 -7
  34. package/dist/test/helpers/assets.js.map +1 -1
  35. package/dist/test/helpers/bodies.d.ts +31 -0
  36. package/dist/test/helpers/bodies.js +16 -0
  37. package/dist/test/helpers/bodies.js.map +1 -0
  38. package/dist/test/helpers/folders.d.ts +50 -0
  39. package/dist/test/helpers/folders.js +4 -2
  40. package/dist/test/helpers/folders.js.map +1 -1
  41. package/dist/test/helpers/members.js +10 -3
  42. package/dist/test/helpers/members.js.map +1 -1
  43. package/dist/test/helpers/owner.js +6 -1
  44. package/dist/test/helpers/owner.js.map +1 -1
  45. package/dist/test/helpers/permissions-world.d.ts +132 -11
  46. package/dist/test/helpers/permissions-world.js +21 -2
  47. package/dist/test/helpers/permissions-world.js.map +1 -1
  48. package/dist/test/helpers/setup-token.d.ts +1 -0
  49. package/dist/test/helpers/setup-token.js +5 -0
  50. package/dist/test/helpers/setup-token.js.map +1 -0
  51. package/dist/test/integration/derivative-sweep-query.test.js +1 -2
  52. package/dist/test/integration/derivative-sweep-query.test.js.map +1 -1
  53. package/dist/test/integration/folder-cascade.test.js +3 -1
  54. package/dist/test/integration/folder-cascade.test.js.map +1 -1
  55. package/dist/test/integration/media-activity-overview.test.js +39 -12
  56. package/dist/test/integration/media-activity-overview.test.js.map +1 -1
  57. package/dist/test/integration/media-api.test.js +22 -21
  58. package/dist/test/integration/media-api.test.js.map +1 -1
  59. package/dist/test/integration/media-bindings.test.js +6 -5
  60. package/dist/test/integration/media-bindings.test.js.map +1 -1
  61. package/dist/test/integration/media-declared-content.test.js +2 -1
  62. package/dist/test/integration/media-declared-content.test.js.map +1 -1
  63. package/dist/test/integration/media-delivery-editing.test.js +12 -2
  64. package/dist/test/integration/media-delivery-editing.test.js.map +1 -1
  65. package/dist/test/integration/media-delivery.test.js +5 -3
  66. package/dist/test/integration/media-delivery.test.js.map +1 -1
  67. package/dist/test/integration/media-explorer-writes.test.js +27 -4
  68. package/dist/test/integration/media-explorer-writes.test.js.map +1 -1
  69. package/dist/test/integration/media-file-history.test.d.ts +1 -0
  70. package/dist/test/integration/media-file-history.test.js +33 -0
  71. package/dist/test/integration/media-file-history.test.js.map +1 -0
  72. package/dist/test/integration/media-guards.test.js +11 -16
  73. package/dist/test/integration/media-guards.test.js.map +1 -1
  74. package/dist/test/integration/media-library.test.js +73 -23
  75. package/dist/test/integration/media-library.test.js.map +1 -1
  76. package/dist/test/integration/media-linked-subfolders.test.js +38 -2
  77. package/dist/test/integration/media-linked-subfolders.test.js.map +1 -1
  78. package/dist/test/integration/media-member-access.test.js +18 -2
  79. package/dist/test/integration/media-member-access.test.js.map +1 -1
  80. package/dist/test/integration/media-permissions.test.js +7 -2
  81. package/dist/test/integration/media-permissions.test.js.map +1 -1
  82. package/dist/test/integration/media-project-field.test.js +17 -2
  83. package/dist/test/integration/media-project-field.test.js.map +1 -1
  84. package/dist/test/integration/media-search-views.test.js +24 -10
  85. package/dist/test/integration/media-search-views.test.js.map +1 -1
  86. package/dist/test/integration/media-storage-origin-unreachable.test.js +2 -1
  87. package/dist/test/integration/media-storage-origin-unreachable.test.js.map +1 -1
  88. package/dist/test/integration/media-transform.test.js +8 -9
  89. package/dist/test/integration/media-transform.test.js.map +1 -1
  90. package/dist/test/integration/media-upload-history-filters.test.d.ts +1 -0
  91. package/dist/test/integration/media-upload-history-filters.test.js +67 -0
  92. package/dist/test/integration/media-upload-history-filters.test.js.map +1 -0
  93. package/dist/test/integration/media-upload-policy.test.js +70 -20
  94. package/dist/test/integration/media-upload-policy.test.js.map +1 -1
  95. package/dist/test/integration/permissions-management.js +15 -4
  96. package/dist/test/integration/permissions-management.js.map +1 -1
  97. package/dist/test/stack-modules.json +7 -0
  98. package/dist/test/unit/declared.test.js +1 -1
  99. package/dist/test/unit/declared.test.js.map +1 -1
  100. package/dist/test/unit/library/activity-overview.test.js +9 -0
  101. package/dist/test/unit/library/activity-overview.test.js.map +1 -1
  102. package/dist/test/unit/library/zip-names.test.js +22 -4
  103. package/dist/test/unit/library/zip-names.test.js.map +1 -1
  104. package/dist/test/unit/pages/toolbar.test.js +4 -4
  105. package/dist/test/unit/pages/toolbar.test.js.map +1 -1
  106. package/dist/test/unit/upload-rules.test.js +10 -0
  107. package/dist/test/unit/upload-rules.test.js.map +1 -1
  108. package/dist/transform-ops.js.map +1 -1
  109. package/dist/upload-checks.d.ts +1 -3
  110. package/dist/upload-checks.js +12 -14
  111. package/dist/upload-checks.js.map +1 -1
  112. package/dist/upload-policy.js +11 -11
  113. package/dist/upload-policy.js.map +1 -1
  114. package/dist/validation/declared.schema.d.ts +4 -4
  115. package/dist/validation/library.schema.d.ts +10 -10
  116. package/dist/validation/media.schema.d.ts +9 -9
  117. package/dist/validation/media.schema.js +5 -6
  118. package/dist/validation/media.schema.js.map +1 -1
  119. package/frontend-vue/app/components/explorer/ExplorerShell.vue +11 -7
  120. package/frontend-vue/i18n/locales/media-en-GB.json +1 -0
  121. package/frontend-vue/i18n/locales/media-fr-FR.json +1 -0
  122. package/frontend-vue/package.json +39 -39
  123. package/package.json +14 -12
  124. package/skills/dms-media/SKILL.md +3 -3
  125. package/src/acl/entries.ts +5 -2
  126. package/src/asset-lifecycle.ts +2 -1
  127. package/src/config.ts +4 -3
  128. package/src/declared/assets.ts +8 -10
  129. package/src/declared/records.ts +5 -1
  130. package/src/library/activity.ts +9 -3
  131. package/src/pages/uploads.ts +1 -1
  132. package/src/routes/media/asset-actions.ts +24 -3
  133. package/src/routes/media/manage.ts +2 -2
  134. package/src/routes/media/overview.ts +5 -4
  135. package/src/routes/media/storage-keys.ts +1 -0
  136. package/src/routes/media/upload.ts +2 -5
  137. package/src/test/antelope.test.ts +10 -6
  138. package/src/test/helpers/assets.ts +28 -15
  139. package/src/test/helpers/bodies.ts +22 -0
  140. package/src/test/helpers/folders.ts +6 -3
  141. package/src/test/helpers/members.ts +11 -3
  142. package/src/test/helpers/owner.ts +6 -1
  143. package/src/test/helpers/permissions-world.ts +23 -19
  144. package/src/test/helpers/setup-token.ts +6 -0
  145. package/src/test/integration/derivative-sweep-query.test.ts +4 -3
  146. package/src/test/integration/folder-cascade.test.ts +3 -1
  147. package/src/test/integration/media-activity-overview.test.ts +52 -37
  148. package/src/test/integration/media-api.test.ts +25 -27
  149. package/src/test/integration/media-bindings.test.ts +10 -16
  150. package/src/test/integration/media-declared-content.test.ts +2 -1
  151. package/src/test/integration/media-delivery-editing.test.ts +13 -2
  152. package/src/test/integration/media-delivery.test.ts +8 -3
  153. package/src/test/integration/media-explorer-writes.test.ts +28 -4
  154. package/src/test/integration/media-file-history.test.ts +38 -0
  155. package/src/test/integration/media-guards.test.ts +18 -13
  156. package/src/test/integration/media-library.test.ts +101 -47
  157. package/src/test/integration/media-linked-subfolders.test.ts +48 -3
  158. package/src/test/integration/media-member-access.test.ts +22 -24
  159. package/src/test/integration/media-permissions.test.ts +11 -5
  160. package/src/test/integration/media-project-field.test.ts +21 -9
  161. package/src/test/integration/media-search-views.test.ts +35 -31
  162. package/src/test/integration/media-storage-origin-unreachable.test.ts +2 -1
  163. package/src/test/integration/media-transform.test.ts +8 -9
  164. package/src/test/integration/media-upload-history-filters.test.ts +77 -0
  165. package/src/test/integration/media-upload-policy.test.ts +84 -30
  166. package/src/test/integration/permissions-management.ts +16 -4
  167. package/src/test/stack-modules.json +7 -0
  168. package/src/test/unit/declared.test.ts +4 -1
  169. package/src/test/unit/library/activity-overview.test.ts +15 -0
  170. package/src/test/unit/library/zip-names.test.ts +26 -7
  171. package/src/test/unit/pages/toolbar.test.ts +4 -4
  172. package/src/test/unit/upload-rules.test.ts +11 -0
  173. package/src/transform-ops.ts +1 -0
  174. package/src/upload-checks.ts +22 -18
  175. package/src/upload-policy.ts +11 -11
  176. package/src/validation/media.schema.ts +9 -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 put = await axios.put(presign.data.uploadUrl, body, {
45
- headers: presign.data.headers,
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: presign.data.resourceKey,
51
+ resourceKey: presigned.resourceKey,
53
52
  filename,
54
53
  });
55
54
  expect(confirm.status).to.equal(HTTP_OK);
56
- return confirm.data.asset.id;
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.data.id;
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
+ });
@@ -8,6 +8,7 @@ import {
8
8
  UnregisterAssetBinding,
9
9
  } from "@antelopejs/interface-dms-media";
10
10
  import sharp from "sharp";
11
+ import { z } from "zod";
11
12
  import { CONTENT_ROOT_BINDING } from "../../bindings";
12
13
  import {
13
14
  configureMediaModule,
@@ -16,7 +17,8 @@ import {
16
17
  } from "../../config";
17
18
  import { runPurgeStaging } from "../../crons/purge-staging";
18
19
  import { MediaFolderModel } from "../../db";
19
- import { uploadAsset, uploadPixelPng } from "../helpers/assets";
20
+ import { putPresigned, uploadAsset, uploadPixelPng } from "../helpers/assets";
21
+ import { createdBody, presignBody, readBody } from "../helpers/bodies";
20
22
  import { fetchFolderNodes } from "../helpers/folders";
21
23
  import { authorizedClient } from "../helpers/http";
22
24
  import { ensureOwnerSession } from "../helpers/owner";
@@ -30,6 +32,16 @@ const PDF_BINDING_ID = "upload-policy.pdf-only";
30
32
  const PDF_FOLDER_NAME = "PDF only uploads";
31
33
  const PURGE_HORIZON_MS = 25 * 60 * 60 * 1000;
32
34
  const EXIF_ROTATED_RIGHT = 6;
35
+ const LARGER_THAN_PROBE_BYTES = 33 * 1024 * 1024;
36
+
37
+ const confirmedBody = z.object({
38
+ asset: z.object({
39
+ mimetype: z.string(),
40
+ size: z.number(),
41
+ width: z.number().nullish(),
42
+ height: z.number().nullish(),
43
+ }),
44
+ });
33
45
 
34
46
  interface StagedUpload {
35
47
  resourceKey: string;
@@ -92,13 +104,10 @@ describe("[integration] media upload policy — types, quota, real content and s
92
104
  body.byteLength,
93
105
  );
94
106
  expect(presigned.status, "presign").to.equal(HTTP_OK);
95
- const put = await axios.put(presigned.data.uploadUrl, body, {
96
- headers: presigned.data.headers,
97
- validateStatus: () => true,
98
- transformRequest: [(data) => data],
99
- });
107
+ const target = readBody(presigned, presignBody);
108
+ const put = await putPresigned(target, body);
100
109
  expect(put.status, "storage PUT").to.be.lessThan(HTTP_REDIRECT_BOUNDARY);
101
- return { resourceKey: presigned.data.resourceKey };
110
+ return { resourceKey: target.resourceKey };
102
111
  }
103
112
 
104
113
  before(async function () {
@@ -114,7 +123,7 @@ describe("[integration] media upload policy — types, quota, real content and s
114
123
  name: "Upload policy",
115
124
  });
116
125
  expect(folder.status).to.equal(HTTP_OK);
117
- folderId = folder.data.id;
126
+ folderId = readBody(folder, createdBody).id;
118
127
  });
119
128
 
120
129
  after(async () => {
@@ -212,20 +221,66 @@ describe("[integration] media upload policy — types, quota, real content and s
212
221
  }
213
222
  });
214
223
 
215
- it("refuses a fake image at confirm and deletes its staged file", async () => {
216
- const staged = await stage(
217
- "fake.png",
218
- "image/png",
219
- Buffer.from("this is not a png"),
220
- );
224
+ it("refuses a fake image at confirm, whatever the case of its type, and deletes its staged file", async () => {
225
+ for (const mimetype of ["image/png", "Image/PNG"]) {
226
+ const staged = await stage(
227
+ "fake.png",
228
+ mimetype,
229
+ Buffer.from("this is not a png"),
230
+ );
231
+ const confirm = await client.post("/api/media/upload/confirm", {
232
+ folderId,
233
+ resourceKey: staged.resourceKey,
234
+ filename: "fake.png",
235
+ });
236
+ expect(confirm.status, mimetype).to.equal(HTTP_UNPROCESSABLE_ENTITY);
237
+ expect(confirm.data.reason, mimetype).to.equal("invalid_image");
238
+ expect(await FileExists(staged.resourceKey), mimetype).to.equal(false);
239
+ }
240
+ });
241
+
242
+ it("stores an image too large to probe, without its size", async function () {
243
+ this.timeout(60_000);
244
+ const jpeg = await sharp({
245
+ create: { width: 8, height: 6, channels: 3, background: "#808080" },
246
+ })
247
+ .jpeg()
248
+ .toBuffer();
249
+ const large = Buffer.concat([jpeg, Buffer.alloc(LARGER_THAN_PROBE_BYTES)]);
250
+ const staged = await stage("large.jpg", "image/jpeg", large);
221
251
  const confirm = await client.post("/api/media/upload/confirm", {
222
252
  folderId,
223
253
  resourceKey: staged.resourceKey,
224
- filename: "fake.png",
254
+ filename: "large.jpg",
225
255
  });
226
- expect(confirm.status).to.equal(HTTP_UNPROCESSABLE_ENTITY);
227
- expect(confirm.data.reason).to.equal("invalid_image");
228
- expect(await FileExists(staged.resourceKey)).to.equal(false);
256
+ expect(confirm.status, JSON.stringify(confirm.data)).to.equal(HTTP_OK);
257
+ const { asset } = readBody(confirm, confirmedBody);
258
+ expect(asset.mimetype).to.equal("image/jpeg");
259
+ expect(asset.size).to.equal(large.byteLength);
260
+ expect(asset.width ?? undefined).to.equal(undefined);
261
+ expect(asset.height ?? undefined).to.equal(undefined);
262
+ });
263
+
264
+ it("confirms a text file declared with the name of an Object.prototype member", async () => {
265
+ configureMediaModule({ ...initialConfig, allowedMimetypes: ["*"] });
266
+ try {
267
+ for (const mimetype of ["constructor", "__proto__"]) {
268
+ const filename = `${mimetype.replaceAll("_", "")}.txt`;
269
+ const staged = await stage(
270
+ filename,
271
+ mimetype,
272
+ Buffer.from("plain text"),
273
+ );
274
+ const confirm = await client.post("/api/media/upload/confirm", {
275
+ folderId,
276
+ resourceKey: staged.resourceKey,
277
+ filename,
278
+ });
279
+ expect(confirm.status, mimetype).to.equal(HTTP_OK);
280
+ }
281
+ } finally {
282
+ configureMediaModule(initialConfig);
283
+ }
229
284
  });
230
285
 
231
286
  it("deletes the staged file when the folder disappeared before confirm", async () => {
@@ -233,24 +288,23 @@ describe("[integration] media upload policy — types, quota, real content and s
233
288
  name: "Doomed upload target",
234
289
  });
235
290
  const body = Buffer.from("bytes");
236
- const presigned = await presign(
237
- doomed.data.id,
238
- "x.txt",
239
- "text/plain",
240
- body.byteLength,
291
+ const doomedId = readBody(doomed, createdBody).id;
292
+ const presigned = readBody(
293
+ await presign(doomedId, "x.txt", "text/plain", body.byteLength),
294
+ presignBody,
241
295
  );
242
- await axios.put(presigned.data.uploadUrl, body, {
243
- headers: presigned.data.headers,
244
- transformRequest: [(data) => data],
296
+ await axios.put(presigned.uploadUrl, body, {
297
+ headers: presigned.headers,
298
+ transformRequest: [(data: Buffer) => data],
245
299
  });
246
- await client.delete(`/api/media/folders/${doomed.data.id}`);
300
+ await client.delete(`/api/media/folders/${doomedId}`);
247
301
  const confirm = await client.post("/api/media/upload/confirm", {
248
- folderId: doomed.data.id,
249
- resourceKey: presigned.data.resourceKey,
302
+ folderId: doomedId,
303
+ resourceKey: presigned.resourceKey,
250
304
  filename: "x.txt",
251
305
  });
252
306
  expect(confirm.status).to.be.greaterThanOrEqual(400);
253
- expect(await FileExists(presigned.data.resourceKey)).to.equal(false);
307
+ expect(await FileExists(presigned.resourceKey)).to.equal(false);
254
308
  });
255
309
 
256
310
  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.data.id;
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.data.id;
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
- return layout.data.layout.options.headerActions[0];
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.disabled).to.not.equal(true);
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 () => {
@@ -0,0 +1,7 @@
1
+ {
2
+ "@antelopejs/mongodb": "1.6.2",
3
+ "@antelopejs/auth-jwt": "1.1.0",
4
+ "@antelopejs/api": "1.7.0",
5
+ "@antelopejs/file-storage-local": "0.2.0",
6
+ "@antelopejs/nodemailer": "0.0.6"
7
+ }
@@ -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: Error) => error.message);
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");
@@ -274,4 +274,19 @@ describe("[unit] library/presets-page — image sizes", () => {
274
274
  expect(pickExampleImage([svg, photo], () => true)?._id).to.equal("photo");
275
275
  expect(pickExampleImage([svg], () => true)).to.equal(undefined);
276
276
  });
277
+
278
+ it("shows sizes on the newest public photo, else on the newest private one", () => {
279
+ const oldPublic = asset("old-public", { createdAt: at(1) });
280
+ const newPrivate = asset("new-private", { createdAt: at(5) });
281
+ const olderPrivate = asset("older-private", { createdAt: at(3) });
282
+ const isPublic = (candidate: { _id: string }) =>
283
+ candidate._id === "old-public";
284
+ expect(pickExampleImage([newPrivate, oldPublic], isPublic)?._id).to.equal(
285
+ "old-public",
286
+ );
287
+ expect(
288
+ pickExampleImage([olderPrivate, newPrivate], isPublic)?._id,
289
+ ).to.equal("new-private");
290
+ expect(pickExampleImage([], isPublic)).to.equal(undefined);
291
+ });
277
292
  });
@@ -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
- describeValidationError,
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 failure = updateAssetSchema.safeParse({ name: "a|b.png" });
47
- expect(failure.success).to.equal(false);
48
- expect(describeValidationError(failure.error)).to.equal(
49
- "$dms_media.errors.name_forbidden",
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(describeValidationError(new Error("boom"))).to.equal(
52
- "$dms_media.errors.invalid_request",
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
  });
@@ -109,9 +109,9 @@ describe("[unit] pages — toolbar", () => {
109
109
  });
110
110
  }
111
111
 
112
- it("holds the upload history while the page is paused", () => {
113
- expect(MediaUploadsPage.history.serializeSync().options).to.include({
114
- liveHold: true,
115
- });
112
+ it("holds the upload history only while the page is paused, not while Live shows it", () => {
113
+ expect(MediaUploadsPage.history.serializeSync().options)
114
+ .to.have.property("liveHold")
115
+ .that.deep.equals({ whileOnScreen: false });
116
116
  });
117
117
  });
@@ -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
  });
@@ -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
  }
@@ -48,11 +48,11 @@ export class UploadRefusedError extends Error {
48
48
  }
49
49
  }
50
50
 
51
+ /** An image's displayed size and decoded format, each absent when unknown. */
51
52
  export interface ImageProbe {
52
53
  width?: number;
53
54
  height?: number;
54
55
  format?: string;
55
- isReadable: boolean;
56
56
  }
57
57
 
58
58
  /** Displayed size: sharp reports stored pixels, EXIF orientations 5-8 swap them. */
@@ -62,36 +62,40 @@ function orientedSize(metadata: sharp.Metadata): ImageProbe {
62
62
  width: isSwapped ? metadata.height : metadata.width,
63
63
  height: isSwapped ? metadata.width : metadata.height,
64
64
  format: metadata.format,
65
- isReadable: true,
66
65
  };
67
66
  }
68
67
 
69
- /** Reads an image's displayed size; any other file is readable as is. */
70
- export async function probeImageBytes(
71
- read: () => Promise<Buffer | undefined>,
72
- mimetype: string,
73
- size: number,
74
- ): Promise<ImageProbe> {
75
- if (!mimetype.startsWith("image/") || size > MAX_PROBE_SIZE_BYTES)
76
- return { isReadable: true };
68
+ async function readMetadata(
69
+ read: () => Promise<Buffer>,
70
+ ): Promise<sharp.Metadata | undefined> {
77
71
  try {
78
- const buffer = await read();
79
- if (!buffer) return { isReadable: true };
80
- return orientedSize(await sharp(buffer).metadata());
72
+ return await sharp(await read()).metadata();
81
73
  } catch {
82
- return { isReadable: false };
74
+ return undefined;
83
75
  }
84
76
  }
85
77
 
86
- /** A file declared as a raster type sharp decodes must actually decode. */
87
- export function assertReadableImage(probe: ImageProbe, mimetype: string): void {
88
- const isDecodable = Boolean(expectedImageFormat(mimetype));
89
- if (isDecodable && (!probe.isReadable || !probe.format))
78
+ /**
79
+ * Reads an image's displayed size. A file declared as a raster type sharp
80
+ * decodes must decode; any other file, and an image too large to probe, has
81
+ * no size.
82
+ */
83
+ export async function probeImage(
84
+ read: () => Promise<Buffer>,
85
+ mimetype: string,
86
+ size: number,
87
+ ): Promise<ImageProbe> {
88
+ if (!mimetypeMatches(mimetype, ["image/*"]) || size > MAX_PROBE_SIZE_BYTES)
89
+ return {};
90
+ const metadata = await readMetadata(read);
91
+ if (metadata?.format) return orientedSize(metadata);
92
+ if (expectedImageFormat(mimetype))
90
93
  throw new UploadRefusedError(
91
94
  HTTP_UNPROCESSABLE_ENTITY,
92
95
  "invalid_image",
93
96
  "This file is not a readable image",
94
97
  );
98
+ return {};
95
99
  }
96
100
 
97
101
  /** The library's types, then those of the asset field the folder feeds. */
@@ -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: Record<string, string> = {
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
- };
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[normalizeMimetype(mimetype)];
93
+ return DECODABLE_IMAGE_MIMETYPES.get(normalizeMimetype(mimetype));
94
94
  }
95
95
 
96
96
  export function mimetypeOfFormat(
@@ -17,6 +17,7 @@ export const MEDIA_ERRORS = {
17
17
  nameTaken: `${ERRORS}.name_taken`,
18
18
  folderNameTaken: `${ERRORS}.folder_name_taken`,
19
19
  boundParent: `${ERRORS}.bound_parent`,
20
+ fieldType: `${ERRORS}.field_type`,
20
21
  altTooLong: `${ERRORS}.alt_too_long`,
21
22
  } as const;
22
23
 
@@ -60,13 +61,10 @@ export function comparableName(name: string): string {
60
61
  return name.trim().normalize("NFC").toLocaleLowerCase();
61
62
  }
62
63
 
63
- /** The first validation message when it is an i18n key, a generic one otherwise. */
64
- export function describeValidationError(error: unknown): string {
65
- const message = error instanceof ZodError ? error.issues[0]?.message : "";
66
- return message?.startsWith("$") ? message : MEDIA_ERRORS.invalidRequest;
67
- }
68
-
69
- /** Parses a request body, answering 400 with a translatable message. */
64
+ /**
65
+ * Parses a request body, answering 400 with the first validation message when
66
+ * it is an i18n key and a generic one otherwise.
67
+ */
70
68
  export function parseBody<Output>(
71
69
  body: unknown,
72
70
  schema: z.ZodType<Output, z.ZodTypeDef, unknown>,
@@ -74,7 +72,10 @@ export function parseBody<Output>(
74
72
  return assertValidation(
75
73
  body,
76
74
  (value) => schema.parse(value),
77
- describeValidationError,
75
+ (error) => {
76
+ const message = error instanceof ZodError ? error.issues[0]?.message : "";
77
+ return message?.startsWith("$") ? message : MEDIA_ERRORS.invalidRequest;
78
+ },
78
79
  );
79
80
  }
80
81