@antelopejs/dms-media 0.7.1 → 0.7.3

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 (84) hide show
  1. package/README.md +2 -2
  2. package/dist/config.js.map +1 -1
  3. package/dist/declared/assets.js +1 -2
  4. package/dist/declared/assets.js.map +1 -1
  5. package/dist/declared/folders.js.map +1 -1
  6. package/dist/library/activity.d.ts +1 -1
  7. package/dist/library/activity.js.map +1 -1
  8. package/dist/library/folder-stats.d.ts +1 -1
  9. package/dist/library/folder-stats.js.map +1 -1
  10. package/dist/library/listing.d.ts +2 -0
  11. package/dist/library/listing.js +14 -4
  12. package/dist/library/listing.js.map +1 -1
  13. package/dist/pages/uploads.js +1 -1
  14. package/dist/pages/uploads.js.map +1 -1
  15. package/dist/routes/media/asset-actions.js +12 -4
  16. package/dist/routes/media/asset-actions.js.map +1 -1
  17. package/dist/routes/media/assets.js +4 -4
  18. package/dist/routes/media/assets.js.map +1 -1
  19. package/dist/routes/media/bulk.js +4 -4
  20. package/dist/routes/media/bulk.js.map +1 -1
  21. package/dist/routes/media/folders.js +4 -4
  22. package/dist/routes/media/folders.js.map +1 -1
  23. package/dist/routes/media/library.js +6 -12
  24. package/dist/routes/media/library.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/upload.js +1 -3
  28. package/dist/routes/media/upload.js.map +1 -1
  29. package/dist/test/antelope.test.js +11 -6
  30. package/dist/test/antelope.test.js.map +1 -1
  31. package/dist/test/integration/media-explorer-writes.test.js +21 -0
  32. package/dist/test/integration/media-explorer-writes.test.js.map +1 -1
  33. package/dist/test/integration/media-file-history.test.d.ts +1 -0
  34. package/dist/test/integration/media-file-history.test.js +33 -0
  35. package/dist/test/integration/media-file-history.test.js.map +1 -0
  36. package/dist/test/integration/media-linked-subfolders.test.js +35 -0
  37. package/dist/test/integration/media-linked-subfolders.test.js.map +1 -1
  38. package/dist/test/integration/media-upload-policy.test.js +39 -6
  39. package/dist/test/integration/media-upload-policy.test.js.map +1 -1
  40. package/dist/test/stack-modules.json +7 -0
  41. package/dist/test/unit/library/activity-overview.test.js +9 -0
  42. package/dist/test/unit/library/activity-overview.test.js.map +1 -1
  43. package/dist/test/unit/library/zip-names.test.js +6 -3
  44. package/dist/test/unit/library/zip-names.test.js.map +1 -1
  45. package/dist/test/unit/pages/toolbar.test.js +4 -4
  46. package/dist/test/unit/pages/toolbar.test.js.map +1 -1
  47. package/dist/upload-checks.d.ts +1 -3
  48. package/dist/upload-checks.js +12 -14
  49. package/dist/upload-checks.js.map +1 -1
  50. package/dist/validation/media.schema.d.ts +2 -1
  51. package/dist/validation/media.schema.js +11 -6
  52. package/dist/validation/media.schema.js.map +1 -1
  53. package/frontend-vue/app/components/explorer/ExplorerShell.vue +11 -7
  54. package/frontend-vue/i18n/locales/media-en-GB.json +1 -0
  55. package/frontend-vue/i18n/locales/media-fr-FR.json +1 -0
  56. package/frontend-vue/package.json +39 -39
  57. package/frontend-vue/tsconfig.json +1 -2
  58. package/package.json +9 -8
  59. package/skills/dms-media/SKILL.md +1 -1
  60. package/src/config.ts +4 -3
  61. package/src/declared/assets.ts +2 -4
  62. package/src/declared/folders.ts +1 -0
  63. package/src/library/activity.ts +6 -2
  64. package/src/library/folder-stats.ts +1 -1
  65. package/src/library/listing.ts +24 -4
  66. package/src/pages/uploads.ts +1 -1
  67. package/src/routes/media/asset-actions.ts +24 -3
  68. package/src/routes/media/assets.ts +9 -5
  69. package/src/routes/media/bulk.ts +7 -5
  70. package/src/routes/media/folders.ts +9 -5
  71. package/src/routes/media/library.ts +10 -18
  72. package/src/routes/media/overview.ts +5 -4
  73. package/src/routes/media/upload.ts +2 -5
  74. package/src/test/antelope.test.ts +8 -6
  75. package/src/test/integration/media-explorer-writes.test.ts +22 -0
  76. package/src/test/integration/media-file-history.test.ts +38 -0
  77. package/src/test/integration/media-linked-subfolders.test.ts +45 -1
  78. package/src/test/integration/media-upload-policy.test.ts +45 -10
  79. package/src/test/stack-modules.json +7 -0
  80. package/src/test/unit/library/activity-overview.test.ts +15 -0
  81. package/src/test/unit/library/zip-names.test.ts +9 -7
  82. package/src/test/unit/pages/toolbar.test.ts +4 -4
  83. package/src/upload-checks.ts +22 -18
  84. package/src/validation/media.schema.ts +15 -15
@@ -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,
@@ -31,6 +32,16 @@ const PDF_BINDING_ID = "upload-policy.pdf-only";
31
32
  const PDF_FOLDER_NAME = "PDF only uploads";
32
33
  const PURGE_HORIZON_MS = 25 * 60 * 60 * 1000;
33
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
+ });
34
45
 
35
46
  interface StagedUpload {
36
47
  resourceKey: string;
@@ -210,20 +221,44 @@ describe("[integration] media upload policy — types, quota, real content and s
210
221
  }
211
222
  });
212
223
 
213
- it("refuses a fake image at confirm and deletes its staged file", async () => {
214
- const staged = await stage(
215
- "fake.png",
216
- "image/png",
217
- Buffer.from("this is not a png"),
218
- );
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);
219
251
  const confirm = await client.post("/api/media/upload/confirm", {
220
252
  folderId,
221
253
  resourceKey: staged.resourceKey,
222
- filename: "fake.png",
254
+ filename: "large.jpg",
223
255
  });
224
- expect(confirm.status).to.equal(HTTP_UNPROCESSABLE_ENTITY);
225
- expect(confirm.data.reason).to.equal("invalid_image");
226
- 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);
227
262
  });
228
263
 
229
264
  it("confirms a text file declared with the name of an Object.prototype member", 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
+ }
@@ -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
  });
@@ -4,7 +4,7 @@ import { z } from "zod";
4
4
  import { portableName, uniqueEntryName } from "../../../library/zip";
5
5
  import {
6
6
  comparableName,
7
- parseBody,
7
+ rejectInvalid,
8
8
  updateAssetSchema,
9
9
  } from "../../../validation/media.schema";
10
10
 
@@ -56,16 +56,18 @@ describe("[unit] library/zip — entry names and name rules", () => {
56
56
  throw new Error("expected the body to be refused");
57
57
  };
58
58
  const forbidden = refused(() =>
59
- parseBody({ name: "a|b.png" }, updateAssetSchema),
59
+ rejectInvalid(() => updateAssetSchema.parse({ name: "a|b.png" })),
60
60
  );
61
61
  expect(forbidden.getStatus()).to.equal(HTTP_BAD_REQUEST);
62
62
  expect(forbidden.getBody()).to.equal("$dms_media.errors.name_forbidden");
63
63
  const crashed = refused(() =>
64
- parseBody(
65
- {},
66
- z.unknown().transform(() => {
67
- throw new Error("boom");
68
- }),
64
+ rejectInvalid(() =>
65
+ z
66
+ .unknown()
67
+ .transform(() => {
68
+ throw new Error("boom");
69
+ })
70
+ .parse({}),
69
71
  ),
70
72
  );
71
73
  expect(crashed.getStatus()).to.equal(HTTP_BAD_REQUEST);
@@ -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
  });
@@ -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. */
@@ -1,6 +1,7 @@
1
- import { assertValidation } from "@antelopejs/interface-api-util";
1
+ import { HTTPResult } from "@antelopejs/interface-api";
2
2
  import { z, ZodError } from "zod";
3
3
 
4
+ const HTTP_BAD_REQUEST = 400;
4
5
  const MAX_NAME_LENGTH = 255;
5
6
  const MIN_PRINTABLE_CHAR_CODE = 32;
6
7
  const PATH_SEPARATORS = new Set(["/", "\\"]);
@@ -17,6 +18,7 @@ export const MEDIA_ERRORS = {
17
18
  nameTaken: `${ERRORS}.name_taken`,
18
19
  folderNameTaken: `${ERRORS}.folder_name_taken`,
19
20
  boundParent: `${ERRORS}.bound_parent`,
21
+ fieldType: `${ERRORS}.field_type`,
20
22
  altTooLong: `${ERRORS}.alt_too_long`,
21
23
  } as const;
22
24
 
@@ -61,21 +63,19 @@ export function comparableName(name: string): string {
61
63
  }
62
64
 
63
65
  /**
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
+ * Runs a schema parse of a request body, answering 400 with the first
67
+ * validation message when it is an i18n key and a generic one otherwise.
66
68
  */
67
- export function parseBody<Output>(
68
- body: unknown,
69
- schema: z.ZodType<Output, z.ZodTypeDef, unknown>,
70
- ): Output {
71
- return assertValidation(
72
- body,
73
- (value) => schema.parse(value),
74
- (error) => {
75
- const message = error instanceof ZodError ? error.issues[0]?.message : "";
76
- return message?.startsWith("$") ? message : MEDIA_ERRORS.invalidRequest;
77
- },
78
- );
69
+ export function rejectInvalid<Output>(parse: () => Output): Output {
70
+ try {
71
+ return parse();
72
+ } catch (error) {
73
+ const message = error instanceof ZodError ? error.issues[0]?.message : "";
74
+ throw new HTTPResult(
75
+ HTTP_BAD_REQUEST,
76
+ message?.startsWith("$") ? message : MEDIA_ERRORS.invalidRequest,
77
+ );
78
+ }
79
79
  }
80
80
 
81
81
  export const createFolderSchema = z.object({