@antelopejs/dms-media 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/README.md +16 -1
  2. package/dist/acl/entries.js +1 -2
  3. package/dist/acl/entries.js.map +1 -1
  4. package/dist/bindings.js +1 -3
  5. package/dist/bindings.js.map +1 -1
  6. package/dist/declared/folders.js +3 -2
  7. package/dist/declared/folders.js.map +1 -1
  8. package/dist/declared/records.d.ts +2 -2
  9. package/dist/declared/records.js +3 -2
  10. package/dist/declared/records.js.map +1 -1
  11. package/dist/derivatives.js +9 -6
  12. package/dist/derivatives.js.map +1 -1
  13. package/dist/guards.d.ts +4 -0
  14. package/dist/guards.js +19 -0
  15. package/dist/guards.js.map +1 -0
  16. package/dist/library/activity.js +7 -5
  17. package/dist/library/activity.js.map +1 -1
  18. package/dist/library/batches.js +6 -3
  19. package/dist/library/batches.js.map +1 -1
  20. package/dist/library/events.js +4 -4
  21. package/dist/library/events.js.map +1 -1
  22. package/dist/library/module-readout.js +5 -2
  23. package/dist/library/module-readout.js.map +1 -1
  24. package/dist/library/realtime.js.map +1 -1
  25. package/dist/pages/activity.js +1 -1
  26. package/dist/pages/activity.js.map +1 -1
  27. package/dist/routes/media/assets.d.ts +1 -1
  28. package/dist/routes/media/assets.js +5 -5
  29. package/dist/routes/media/assets.js.map +1 -1
  30. package/dist/routes/media/bulk.js +17 -13
  31. package/dist/routes/media/bulk.js.map +1 -1
  32. package/dist/routes/media/delivery-headers.js +9 -9
  33. package/dist/routes/media/delivery-headers.js.map +1 -1
  34. package/dist/routes/media/delivery-stream.js.map +1 -1
  35. package/dist/routes/media/delivery.js.map +1 -1
  36. package/dist/routes/media/manage.js.map +1 -1
  37. package/dist/routes/media/transform.js +13 -8
  38. package/dist/routes/media/transform.js.map +1 -1
  39. package/dist/test/antelope.test.js +13 -12
  40. package/dist/test/antelope.test.js.map +1 -1
  41. package/dist/test/helpers/folders.d.ts +27 -0
  42. package/dist/test/helpers/folders.js +15 -0
  43. package/dist/test/helpers/folders.js.map +1 -1
  44. package/dist/test/helpers/pages.js +10 -6
  45. package/dist/test/helpers/pages.js.map +1 -1
  46. package/dist/test/helpers/permissions-world.d.ts +98 -0
  47. package/dist/test/helpers/permissions-world.js +205 -0
  48. package/dist/test/helpers/permissions-world.js.map +1 -0
  49. package/dist/test/helpers/prototype.d.ts +1 -0
  50. package/dist/test/helpers/prototype.js +11 -0
  51. package/dist/test/helpers/prototype.js.map +1 -0
  52. package/dist/test/integration/derivative-sweep-query.test.js +13 -16
  53. package/dist/test/integration/derivative-sweep-query.test.js.map +1 -1
  54. package/dist/test/integration/folder-query.test.js +5 -9
  55. package/dist/test/integration/folder-query.test.js.map +1 -1
  56. package/dist/test/integration/media-bindings.test.js +2 -2
  57. package/dist/test/integration/media-bindings.test.js.map +1 -1
  58. package/dist/test/integration/media-cleanup.test.js +14 -17
  59. package/dist/test/integration/media-cleanup.test.js.map +1 -1
  60. package/dist/test/integration/media-declared-content.test.js +2 -1
  61. package/dist/test/integration/media-declared-content.test.js.map +1 -1
  62. package/dist/test/integration/media-delivery-editing.test.js +7 -5
  63. package/dist/test/integration/media-delivery-editing.test.js.map +1 -1
  64. package/dist/test/integration/media-delivery.test.js +19 -5
  65. package/dist/test/integration/media-delivery.test.js.map +1 -1
  66. package/dist/test/integration/media-explorer-writes.test.js +2 -2
  67. package/dist/test/integration/media-explorer-writes.test.js.map +1 -1
  68. package/dist/test/integration/media-guards.test.js +18 -7
  69. package/dist/test/integration/media-guards.test.js.map +1 -1
  70. package/dist/test/integration/media-library.test.js +1 -1
  71. package/dist/test/integration/media-library.test.js.map +1 -1
  72. package/dist/test/integration/media-linked-subfolders.test.js +5 -5
  73. package/dist/test/integration/media-linked-subfolders.test.js.map +1 -1
  74. package/dist/test/integration/media-member-access.test.js +2 -5
  75. package/dist/test/integration/media-member-access.test.js.map +1 -1
  76. package/dist/test/integration/media-permissions.test.js +142 -473
  77. package/dist/test/integration/media-permissions.test.js.map +1 -1
  78. package/dist/test/integration/media-project-field.test.js +3 -5
  79. package/dist/test/integration/media-project-field.test.js.map +1 -1
  80. package/dist/test/integration/media-search-query.test.js +11 -16
  81. package/dist/test/integration/media-search-query.test.js.map +1 -1
  82. package/dist/test/integration/media-storage-origin-unreachable.test.js +1 -0
  83. package/dist/test/integration/media-storage-origin-unreachable.test.js.map +1 -1
  84. package/dist/test/integration/media-upload-policy.test.js +2 -2
  85. package/dist/test/integration/media-upload-policy.test.js.map +1 -1
  86. package/dist/test/integration/permissions-management.d.ts +2 -0
  87. package/dist/test/integration/permissions-management.js +189 -0
  88. package/dist/test/integration/permissions-management.js.map +1 -0
  89. package/dist/test/unit/acl/entries.test.js +2 -1
  90. package/dist/test/unit/acl/entries.test.js.map +1 -1
  91. package/dist/test/unit/acl/resolver.test.js +10 -3
  92. package/dist/test/unit/acl/resolver.test.js.map +1 -1
  93. package/dist/test/unit/library/fixtures.d.ts +1 -1
  94. package/dist/test/unit/library/fixtures.js +6 -1
  95. package/dist/test/unit/library/fixtures.js.map +1 -1
  96. package/dist/test/unit/library/library.test.js +0 -1
  97. package/dist/test/unit/library/library.test.js.map +1 -1
  98. package/dist/test/unit/library/realtime.test.js.map +1 -1
  99. package/dist/test/unit/library/search-facets.test.js +2 -2
  100. package/dist/test/unit/library/search-facets.test.js.map +1 -1
  101. package/dist/test/unit/pages/toolbar.test.js +24 -7
  102. package/dist/test/unit/pages/toolbar.test.js.map +1 -1
  103. package/dist/test/unit/routes/dto.test.js +7 -6
  104. package/dist/test/unit/routes/dto.test.js.map +1 -1
  105. package/dist/test/unit/routes/file-page.test.js +5 -7
  106. package/dist/test/unit/routes/file-page.test.js.map +1 -1
  107. package/dist/test/unit/routes/preset-row.test.js +2 -1
  108. package/dist/test/unit/routes/preset-row.test.js.map +1 -1
  109. package/dist/transform.js +6 -6
  110. package/dist/transform.js.map +1 -1
  111. package/dist/upload-checks.d.ts +8 -2
  112. package/dist/upload-checks.js.map +1 -1
  113. package/dist/upload-policy.js +8 -8
  114. package/dist/upload-policy.js.map +1 -1
  115. package/dist/validation/declared.schema.js +14 -8
  116. package/dist/validation/declared.schema.js.map +1 -1
  117. package/dist/validation/media.schema.d.ts +1 -1
  118. package/dist/validation/media.schema.js +2 -2
  119. package/dist/validation/media.schema.js.map +1 -1
  120. package/frontend-vue/app/build/imageEditor/editorShapes.ts +118 -0
  121. package/frontend-vue/app/build/imageEditor/useEditorSaving.ts +86 -0
  122. package/frontend-vue/app/build/library/libraryActions.ts +444 -0
  123. package/frontend-vue/app/build/library/libraryCore.ts +136 -0
  124. package/frontend-vue/app/components/ImageEditor.vue +22 -179
  125. package/frontend-vue/app/composables/library/useMediaLibrary.ts +3 -575
  126. package/frontend-vue/app/composables/useMediaApi.ts +21 -5
  127. package/frontend-vue/build/backend-boundary.ts +122 -0
  128. package/frontend-vue/dms.frontend.build.ts +3 -0
  129. package/frontend-vue/eslint.config.mjs +13 -0
  130. package/frontend-vue/package.json +3 -1
  131. package/frontend-vue/pnpm-lock.yaml +217 -61
  132. package/frontend-vue/tests/backend-boundary.test.ts +203 -0
  133. package/frontend-vue/tests/mediaPreviews.test.ts +39 -0
  134. package/package.json +4 -10
  135. package/skills/dms-media/SKILL.md +1 -0
  136. package/skills/dms-media/cases.json +38 -0
  137. package/src/acl/entries.ts +6 -4
  138. package/src/bindings.ts +3 -3
  139. package/src/declared/folders.ts +3 -3
  140. package/src/declared/records.ts +9 -8
  141. package/src/derivatives.ts +10 -6
  142. package/src/guards.ts +19 -0
  143. package/src/library/activity.ts +17 -9
  144. package/src/library/batches.ts +12 -9
  145. package/src/library/events.ts +7 -4
  146. package/src/library/module-readout.ts +6 -2
  147. package/src/library/realtime.ts +5 -1
  148. package/src/library/zip.ts +1 -1
  149. package/src/pages/activity.ts +6 -2
  150. package/src/routes/media/assets.ts +4 -3
  151. package/src/routes/media/bulk.ts +16 -14
  152. package/src/routes/media/delivery-headers.ts +9 -12
  153. package/src/routes/media/delivery-stream.ts +3 -2
  154. package/src/routes/media/delivery.ts +4 -2
  155. package/src/routes/media/manage.ts +4 -6
  156. package/src/routes/media/transform.ts +27 -23
  157. package/src/test/antelope.test.ts +21 -17
  158. package/src/test/helpers/folders.ts +22 -0
  159. package/src/test/helpers/pages.ts +12 -5
  160. package/src/test/helpers/permissions-world.ts +326 -0
  161. package/src/test/helpers/prototype.ts +12 -0
  162. package/src/test/integration/derivative-sweep-query.test.ts +19 -21
  163. package/src/test/integration/folder-query.test.ts +11 -11
  164. package/src/test/integration/media-bindings.test.ts +7 -7
  165. package/src/test/integration/media-cleanup.test.ts +25 -37
  166. package/src/test/integration/media-declared-content.test.ts +18 -19
  167. package/src/test/integration/media-delivery-editing.test.ts +11 -7
  168. package/src/test/integration/media-delivery.test.ts +29 -8
  169. package/src/test/integration/media-explorer-writes.test.ts +2 -7
  170. package/src/test/integration/media-guards.test.ts +21 -7
  171. package/src/test/integration/media-library.test.ts +1 -1
  172. package/src/test/integration/media-linked-subfolders.test.ts +11 -20
  173. package/src/test/integration/media-member-access.test.ts +5 -9
  174. package/src/test/integration/media-permissions.test.ts +56 -570
  175. package/src/test/integration/media-project-field.test.ts +5 -7
  176. package/src/test/integration/media-search-query.test.ts +16 -20
  177. package/src/test/integration/media-storage-origin-unreachable.test.ts +3 -2
  178. package/src/test/integration/media-upload-policy.test.ts +2 -8
  179. package/src/test/integration/permissions-management.ts +292 -0
  180. package/src/test/unit/acl/entries.test.ts +2 -1
  181. package/src/test/unit/acl/resolver.test.ts +19 -7
  182. package/src/test/unit/library/fixtures.ts +9 -3
  183. package/src/test/unit/library/library.test.ts +1 -7
  184. package/src/test/unit/library/realtime.test.ts +1 -1
  185. package/src/test/unit/library/search-facets.test.ts +2 -2
  186. package/src/test/unit/pages/toolbar.test.ts +42 -17
  187. package/src/test/unit/routes/dto.test.ts +7 -6
  188. package/src/test/unit/routes/file-page.test.ts +10 -9
  189. package/src/test/unit/routes/preset-row.test.ts +2 -2
  190. package/src/transform.ts +6 -6
  191. package/src/upload-checks.ts +12 -3
  192. package/src/upload-policy.ts +8 -8
  193. package/src/validation/declared.schema.ts +17 -12
  194. package/src/validation/media.schema.ts +6 -6
  195. package/frontend-vue/tests/engines.test.ts +0 -20
  196. package/frontend-vue/tests/locales.test.ts +0 -61
@@ -13,9 +13,13 @@ let pendingDueAt = 0;
13
13
  let pendingChanges = 0;
14
14
  let version = 0;
15
15
 
16
+ /**
17
+ * Publishes the changes waiting to be announced as one message whose
18
+ * `payload.count` says how many it stands for: a paused page counts that many
19
+ * missed changes, not one per announcement.
20
+ */
16
21
  async function publishNow(): Promise<void> {
17
22
  pending = undefined;
18
- // A paused page counts `payload.count` as that many missed changes, not one per announcement.
19
23
  const count = pendingChanges;
20
24
  pendingChanges = 0;
21
25
  try {
@@ -23,7 +23,7 @@ interface CentralEntry {
23
23
 
24
24
  export type ZipChunkWriter = (chunk: Buffer) => void;
25
25
 
26
- function dosDateTime(date: Date): { time: number; date: number } {
26
+ function dosDateTime(date: Date): Pick<CentralEntry, "time" | "date"> {
27
27
  const year = Math.max(date.getFullYear(), DOS_EPOCH_YEAR);
28
28
  return {
29
29
  time:
@@ -4,7 +4,11 @@ import { DefaultLayout } from "@antelopejs/interface-dms/base/layouts";
4
4
  import { Tab } from "@antelopejs/interface-dms/base/tab";
5
5
  import { PageController, RegisterPage } from "@antelopejs/interface-dms/page";
6
6
  import { MEDIA_LIBRARY_TOPIC } from "../constants";
7
- import { ACTIVITY_FILTERS, type ActivityFilter } from "../library/activity";
7
+ import {
8
+ ACTIVITY_FILTERS,
9
+ type ActivityFilter,
10
+ isActivityFilter,
11
+ } from "../library/activity";
8
12
  import { libraryCategory, MEDIA_MODULE_ID } from "./module";
9
13
  import { blockMeta } from "./texts";
10
14
  import { MEDIA_LIVE, mediaPageToolbar } from "./toolbar";
@@ -14,7 +18,7 @@ const FEED_LENGTH = 50;
14
18
  const SKELETON_ROWS = 8;
15
19
  const ALL_SLOT = "all";
16
20
 
17
- const FILTERS = Object.keys(ACTIVITY_FILTERS) as ActivityFilter[];
21
+ const FILTERS = Object.keys(ACTIVITY_FILTERS).filter(isActivityFilter);
18
22
 
19
23
  function feed(filter?: ActivityFilter) {
20
24
  const query = filter ? `&type=${filter}` : "";
@@ -9,6 +9,7 @@ import {
9
9
  Delete,
10
10
  Get,
11
11
  JSONBody,
12
+ MultiParameter,
12
13
  Parameter,
13
14
  Post,
14
15
  } from "@antelopejs/interface-api";
@@ -131,9 +132,9 @@ export class MediaAssetsController extends MediaApiController {
131
132
  return { assets, truncated };
132
133
  }
133
134
 
134
- @Post("/previews")
135
- async previews(@JSONBody() body: unknown) {
136
- const { ids } = parseBody(body, previewIdsSchema);
135
+ @Get("/previews")
136
+ async previews(@MultiParameter("ids", "query") queryIds: string[]) {
137
+ const { ids } = parseBody({ ids: queryIds }, previewIdsSchema);
137
138
  const context = await this.resolveContext();
138
139
  const { presets } = getMediaConfig();
139
140
  const thumb = presets.get(THUMB_PRESET_ID);
@@ -23,6 +23,7 @@ import {
23
23
  type MediaRequestContext,
24
24
  requireFolderRight,
25
25
  } from "./context";
26
+ import { isString } from "../../guards";
26
27
 
27
28
  const HTTP_OK = 200;
28
29
  const HTTP_INTERNAL_ERROR = 500;
@@ -55,19 +56,6 @@ export interface BulkOutcome {
55
56
  refused: BulkRefusal[];
56
57
  }
57
58
 
58
- function describeFailure(id: string, error: unknown): BulkRefusal {
59
- if (error instanceof HTTPResult) {
60
- const body: unknown = error.getBody();
61
- const message = typeof body === "string" ? body : JSON.stringify(body);
62
- return { id, status: error.getStatus(), message: message ?? "" };
63
- }
64
- return {
65
- id,
66
- status: HTTP_INTERNAL_ERROR,
67
- message: error instanceof Error ? error.message : String(error),
68
- };
69
- }
70
-
71
59
  /** Runs one operation per asset in order, keeping going past the ones refused. */
72
60
  async function applyToEach(
73
61
  context: MediaRequestContext,
@@ -81,7 +69,21 @@ async function applyToEach(
81
69
  await operation(context, asset);
82
70
  outcome.done.push(id);
83
71
  } catch (error) {
84
- outcome.refused.push(describeFailure(id, error));
72
+ if (error instanceof HTTPResult) {
73
+ const body: unknown = error.getBody();
74
+ const message = isString(body) ? body : JSON.stringify(body);
75
+ outcome.refused.push({
76
+ id,
77
+ status: error.getStatus(),
78
+ message: message ?? "",
79
+ });
80
+ } else {
81
+ outcome.refused.push({
82
+ id,
83
+ status: HTTP_INTERNAL_ERROR,
84
+ message: error instanceof Error ? error.message : String(error),
85
+ });
86
+ }
85
87
  }
86
88
  }
87
89
  return outcome;
@@ -12,13 +12,13 @@ type Disposition = "inline" | "attachment";
12
12
  * Types a browser would run as a page from the API origin. SVG stays inline
13
13
  * (it is an image) but sandboxed; documents are only ever downloaded.
14
14
  */
15
- const ACTIVE_CONTENT_DISPOSITIONS: Record<string, Disposition> = {
16
- "image/svg+xml": "inline",
17
- "text/html": "attachment",
18
- "application/xhtml+xml": "attachment",
19
- "text/xml": "attachment",
20
- "application/xml": "attachment",
21
- };
15
+ const ACTIVE_CONTENT_DISPOSITIONS = new Map<string, Disposition>([
16
+ ["image/svg+xml", "inline"],
17
+ ["text/html", "attachment"],
18
+ ["application/xhtml+xml", "attachment"],
19
+ ["text/xml", "attachment"],
20
+ ["application/xml", "attachment"],
21
+ ]);
22
22
 
23
23
  export function normalizedMimetype(mimetype: string): string {
24
24
  const essence = mimetype
@@ -29,10 +29,7 @@ export function normalizedMimetype(mimetype: string): string {
29
29
  }
30
30
 
31
31
  export function isActiveContent(mimetype: string): boolean {
32
- return Object.hasOwn(
33
- ACTIVE_CONTENT_DISPOSITIONS,
34
- normalizedMimetype(mimetype),
35
- );
32
+ return ACTIVE_CONTENT_DISPOSITIONS.has(normalizedMimetype(mimetype));
36
33
  }
37
34
 
38
35
  function asciiFilename(filename: string): string {
@@ -47,7 +44,7 @@ function asciiFilename(filename: string): string {
47
44
 
48
45
  export function contentDisposition(mimetype: string, filename: string): string {
49
46
  const disposition =
50
- ACTIVE_CONTENT_DISPOSITIONS[normalizedMimetype(mimetype)] ?? "inline";
47
+ ACTIVE_CONTENT_DISPOSITIONS.get(normalizedMimetype(mimetype)) ?? "inline";
51
48
  const extended = encodeURIComponent(filename).replace(
52
49
  /['()*]/g,
53
50
  (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`,
@@ -79,6 +79,9 @@ function addRepresentationHeaders(
79
79
  * or the attachment disposition these files need, every other file is
80
80
  * redirected to the storage so its bandwidth never goes through Node.
81
81
  * Byte ranges are not served: these files are small and rendered whole.
82
+ * The bytes are read from the storage itself, not through its read URL: that
83
+ * URL is the public origin, which the server may not reach (private network,
84
+ * egress policy).
82
85
  */
83
86
  export async function streamStoredFile(
84
87
  ctx: RequestContext,
@@ -92,8 +95,6 @@ export async function streamStoredFile(
92
95
  response.setBody("");
93
96
  return response;
94
97
  }
95
- // Read from the storage itself: its read URL is the public origin, which
96
- // the server may not reach (private network, egress policy).
97
98
  const stored = await ReadFile(file.storageKey, file.storage).catch(
98
99
  () => undefined,
99
100
  );
@@ -312,6 +312,10 @@ export class MediaDeliveryController extends Controller("/media") {
312
312
  return deliverAsset(ctx, resolved);
313
313
  }
314
314
 
315
+ /**
316
+ * Resolves (and authorizes) the asset before it touches the preset, so an
317
+ * unauthenticated caller cannot probe which preset IDs are configured.
318
+ */
315
319
  @Get("/:assetId/:presetId/:filename")
316
320
  async deliverDerivative(
317
321
  @Context() ctx: RequestContext,
@@ -320,8 +324,6 @@ export class MediaDeliveryController extends Controller("/media") {
320
324
  @IfAuthUser() user?: User,
321
325
  ) {
322
326
  assertNamedSegment(ctx);
323
- // Resolve (and authorize) the asset before touching the preset so an
324
- // unauthenticated caller cannot probe which preset IDs are configured.
325
327
  const resolved = await guardSignIn(
326
328
  ctx,
327
329
  resolveDeliverableAsset(ctx, assetId, user),
@@ -4,6 +4,7 @@ import { getMediaConfig } from "../../config";
4
4
  import { getLastSweep, SWEEP_DERIVATIVES_SCHEDULE } from "../../crons";
5
5
  import type { MediaAsset } from "../../db";
6
6
  import { buildUploadBatches, type UploadBatchRow } from "../../library/batches";
7
+ import type { MediaEventDetails } from "../../library/events";
7
8
  import { loadUploadHistoryEvents } from "../../library/upload-history";
8
9
  import { presetsConfigSnippet } from "../../library/snippets";
9
10
  import { loadAssetsInFolders } from "../../library/listing";
@@ -60,8 +61,8 @@ function matchesFilters(
60
61
  );
61
62
  }
62
63
 
63
- function batchDetails(summary: BatchSummary): Record<string, string | number> {
64
- const details: Record<string, string | number> = {
64
+ function batchDetails(summary: BatchSummary): MediaEventDetails {
65
+ const details: MediaEventDetails = {
65
66
  batchId: summary.batchId,
66
67
  total: summary.total,
67
68
  failed: summary.failed,
@@ -110,10 +111,7 @@ function readSourcePage(query: Record<string, string>): SourcePage {
110
111
  return { offset, limit };
111
112
  }
112
113
 
113
- function pageRows<T>(
114
- rows: T[],
115
- page: SourcePage,
116
- ): { results: T[]; total: number } {
114
+ function pageRows<T>(rows: T[], page: SourcePage) {
117
115
  const results = page.limit
118
116
  ? rows.slice(page.offset, page.offset + page.limit)
119
117
  : rows.slice(page.offset);
@@ -24,23 +24,27 @@ const HTTP_BAD_REQUEST = 400;
24
24
  const HTTP_CONFLICT = 409;
25
25
  const HTTP_UNPROCESSABLE_ENTITY = 422;
26
26
 
27
- function translateTransformError(error: unknown): never {
28
- assert(
29
- !(error instanceof AnimatedImageTransformError),
30
- HTTP_UNPROCESSABLE_ENTITY,
31
- "Animated images cannot be edited",
32
- );
33
- assert(
34
- !(error instanceof OversizedImageTransformError),
35
- HTTP_UNPROCESSABLE_ENTITY,
36
- "This image is too large to be edited",
37
- );
38
- assert(
39
- !(error instanceof MediaAssetChangedError),
40
- HTTP_CONFLICT,
41
- "This image was changed by someone else in the meantime. Reload the page to see the latest version.",
42
- );
43
- throw error;
27
+ async function translatingTransformErrors<T>(work: Promise<T>): Promise<T> {
28
+ try {
29
+ return await work;
30
+ } catch (error) {
31
+ assert(
32
+ !(error instanceof AnimatedImageTransformError),
33
+ HTTP_UNPROCESSABLE_ENTITY,
34
+ "Animated images cannot be edited",
35
+ );
36
+ assert(
37
+ !(error instanceof OversizedImageTransformError),
38
+ HTTP_UNPROCESSABLE_ENTITY,
39
+ "This image is too large to be edited",
40
+ );
41
+ assert(
42
+ !(error instanceof MediaAssetChangedError),
43
+ HTTP_CONFLICT,
44
+ "This image was changed by someone else in the meantime. Reload the page to see the latest version.",
45
+ );
46
+ throw error;
47
+ }
44
48
  }
45
49
 
46
50
  async function requireEditableAsset(
@@ -106,8 +110,8 @@ export class MediaTransformController extends MediaApiController {
106
110
  const ops = assertValidation(body, (v) => transformSchema.parse(v));
107
111
  const context = await this.resolveContext();
108
112
  const asset = await requireEditableAsset(context, assetId);
109
- await applyImageTransform(context.assetModel, asset, ops).catch(
110
- translateTransformError,
113
+ await translatingTransformErrors(
114
+ applyImageTransform(context.assetModel, asset, ops),
111
115
  );
112
116
  const updated = await context.assetModel.get(assetId);
113
117
  assert(updated, HTTP_CONFLICT, "Asset disappeared during transform");
@@ -132,8 +136,8 @@ export class MediaTransformController extends MediaApiController {
132
136
  const ops = assertValidation(body, (v) => transformSchema.parse(v));
133
137
  const context = await this.resolveContext();
134
138
  const asset = await requireEditableAsset(context, assetId);
135
- const copy = await createEditedCopy(context, asset, ops).catch(
136
- translateTransformError,
139
+ const copy = await translatingTransformErrors(
140
+ createEditedCopy(context, asset, ops),
137
141
  );
138
142
  await this.record(context, {
139
143
  kind: "asset.upload",
@@ -156,8 +160,8 @@ export class MediaTransformController extends MediaApiController {
156
160
  HTTP_CONFLICT,
157
161
  "Asset has no original to revert to",
158
162
  );
159
- await revertImageTransform(context.assetModel, asset).catch(
160
- translateTransformError,
163
+ await translatingTransformErrors(
164
+ revertImageTransform(context.assetModel, asset),
161
165
  );
162
166
  const updated = await context.assetModel.get(assetId);
163
167
  assert(updated, HTTP_CONFLICT, "Asset disappeared during revert");
@@ -4,6 +4,7 @@ import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
5
  import { defineConfig } from "@antelopejs/interface-core/config";
6
6
  import { MongoMemoryReplSet } from "mongodb-memory-server-core";
7
+ import { isString } from "../guards";
7
8
 
8
9
  const API_PORT = 5019;
9
10
  const LOCAL_BUILD_COMMAND = process.env.DMS_PREBUILT ? [] : ["pnpm build"];
@@ -13,16 +14,16 @@ const MONGO_BINARY_VERSION = "8.0.8";
13
14
  const SMTP_HOST = "127.0.0.1";
14
15
  const EPHEMERAL_PORT = 0;
15
16
  const TEST_SENDER = "dms-media@test.local";
16
- const SMTP_RESPONSES: Record<string, string> = {
17
- EHLO: "250-dms-media.test\r\n250 PIPELINING\r\n",
18
- HELO: "250 dms-media.test\r\n",
19
- MAIL: "250 OK\r\n",
20
- RCPT: "250 OK\r\n",
21
- DATA: "354 End data with <CR><LF>.<CR><LF>\r\n",
22
- RSET: "250 OK\r\n",
23
- NOOP: "250 OK\r\n",
24
- QUIT: "221 Bye\r\n",
25
- };
17
+ const SMTP_RESPONSES = new Map([
18
+ ["EHLO", "250-dms-media.test\r\n250 PIPELINING\r\n"],
19
+ ["HELO", "250 dms-media.test\r\n"],
20
+ ["MAIL", "250 OK\r\n"],
21
+ ["RCPT", "250 OK\r\n"],
22
+ ["DATA", "354 End data with <CR><LF>.<CR><LF>\r\n"],
23
+ ["RSET", "250 OK\r\n"],
24
+ ["NOOP", "250 OK\r\n"],
25
+ ["QUIT", "221 Bye\r\n"],
26
+ ]);
26
27
 
27
28
  interface SmtpConnectionState {
28
29
  pending: string;
@@ -47,7 +48,7 @@ function processSmtpLine(
47
48
  }
48
49
  const command = line.split(" ", 1)[0]?.toUpperCase() ?? "";
49
50
  state.isReadingData = command === "DATA";
50
- const response = SMTP_RESPONSES[command] ?? "250 OK\r\n";
51
+ const response = SMTP_RESPONSES.get(command) ?? "250 OK\r\n";
51
52
  if (command === "QUIT") socket.end(response);
52
53
  else socket.write(response);
53
54
  }
@@ -77,8 +78,7 @@ async function startSmtpFixture(): Promise<number> {
77
78
  });
78
79
  });
79
80
  const address = smtpServer.address();
80
- if (!address || typeof address === "string")
81
- throw new Error("Invalid SMTP address");
81
+ if (!address || isString(address)) throw new Error("Invalid SMTP address");
82
82
  return address.port;
83
83
  }
84
84
 
@@ -113,14 +113,18 @@ export default defineConfig({
113
113
  version: ">=0.11.0 <1.0.0",
114
114
  },
115
115
  config: {
116
- // No frontend server runs here: the dashboard URL is the API, whose
117
- // paths the front proxy serves unchanged.
116
+ /**
117
+ * No frontend server runs here: the dashboard URL is the API, whose
118
+ * paths the front proxy serves unchanged.
119
+ */
118
120
  clientBaseUrl: `http://127.0.0.1:${API_PORT}`,
119
121
  auth: {
120
122
  jwtSecret: JWT_SECRET,
121
123
  },
122
- // Outside development, which the test run is not, dms 0.10 refuses
123
- // to start without a render secret of its own.
124
+ /**
125
+ * Outside development, which the test run is not, dms 0.10 refuses
126
+ * to start without a render secret of its own.
127
+ */
124
128
  htmlRender: {
125
129
  serviceSecret: HTML_RENDER_SECRET,
126
130
  },
@@ -1,5 +1,7 @@
1
1
  import { GetModel } from "@antelopejs/interface-database-decorators";
2
2
  import { DEFAULT_TENANT_ID } from "@antelopejs/interface-dms/constants";
3
+ import type { AxiosInstance } from "axios";
4
+ import { z } from "zod";
3
5
  import { parseFolderAcl, serializeAcl } from "../../acl";
4
6
  import { MediaFolderModel } from "../../db";
5
7
  import type { AclEntry } from "../../types";
@@ -23,3 +25,23 @@ export async function writeFolderAcl(
23
25
  json_acl: serializeAcl(entries ?? undefined) ?? "",
24
26
  });
25
27
  }
28
+
29
+ const folderNodeSchema = z.object({
30
+ id: z.string(),
31
+ name: z.string(),
32
+ parentId: z.string().nullable(),
33
+ binding: z.string().nullable(),
34
+ acceptsSubfolders: z.boolean(),
35
+ accepts: z.array(z.string()).nullable(),
36
+ });
37
+
38
+ export type FolderNode = z.infer<typeof folderNodeSchema>;
39
+
40
+ /** The folders `/api/media/tree` answers, checked against the fields the suites read. */
41
+ export async function fetchFolderNodes(
42
+ client: AxiosInstance,
43
+ ): Promise<FolderNode[]> {
44
+ const response = await client.get("/api/media/tree");
45
+ return z.object({ folders: z.array(folderNodeSchema) }).parse(response.data)
46
+ .folders;
47
+ }
@@ -1,5 +1,6 @@
1
1
  import { pageRoutePath } from "@antelopejs/interface-dms/page";
2
2
  import type { AxiosInstance } from "axios";
3
+ import { z } from "zod";
3
4
 
4
5
  const HTTP_OK = 200;
5
6
  const PAGE_LAYOUT_ROUTE = "/pagelayout";
@@ -15,10 +16,16 @@ export interface PageAccess {
15
16
  servedBlocks: number;
16
17
  }
17
18
 
18
- function countBlocks(components: unknown): number {
19
- if (Array.isArray(components)) return components.length;
20
- return Object.keys(components ?? {}).length;
21
- }
19
+ const layoutSchema = z.object({
20
+ components: z
21
+ .union([z.array(z.unknown()), z.record(z.unknown())])
22
+ .nullish()
23
+ .transform((components) =>
24
+ Array.isArray(components)
25
+ ? components.length
26
+ : Object.keys(components ?? {}).length,
27
+ ),
28
+ });
22
29
 
23
30
  /** Reads a page through its guarded route, its page entry and its by-slug layout. */
24
31
  export async function readPageAccess(
@@ -40,6 +47,6 @@ export async function readPageAccess(
40
47
  return {
41
48
  ownRouteStatus: ownRoute.status,
42
49
  hasAccess: page.data.route?.hasAccess === true,
43
- servedBlocks: countBlocks(layout.data.components),
50
+ servedBlocks: layoutSchema.parse(layout.data).components,
44
51
  };
45
52
  }