@antelopejs/dms-media 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/README.md +18 -3
  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 +87 -0
  122. package/frontend-vue/app/build/library/libraryActions.ts +444 -0
  123. package/frontend-vue/app/build/library/libraryCore.ts +137 -0
  124. package/frontend-vue/app/components/FirstRun.vue +2 -1
  125. package/frontend-vue/app/components/ImageEditor.vue +22 -179
  126. package/frontend-vue/app/components/dialogs/DestinationDialog.vue +3 -3
  127. package/frontend-vue/app/components/field/FieldAltPopover.vue +2 -1
  128. package/frontend-vue/app/composables/library/useMediaLibrary.ts +3 -575
  129. package/frontend-vue/app/composables/useAssetFieldUploads.ts +9 -1
  130. package/frontend-vue/app/composables/useAssetLink.ts +33 -13
  131. package/frontend-vue/app/composables/useFileDetails.ts +6 -5
  132. package/frontend-vue/app/composables/useMediaApi.ts +21 -5
  133. package/frontend-vue/app/composables/useUploadFailureText.ts +24 -5
  134. package/frontend-vue/app/composables/useUploadQueue.ts +178 -44
  135. package/frontend-vue/app/composables/useUploadToasts.ts +81 -19
  136. package/frontend-vue/build/backend-boundary.ts +122 -0
  137. package/frontend-vue/dms.frontend.build.ts +3 -0
  138. package/frontend-vue/eslint.config.mjs +13 -0
  139. package/frontend-vue/package.json +4 -2
  140. package/frontend-vue/pnpm-lock.yaml +217 -61
  141. package/frontend-vue/tests/api-error-presentation.test.ts +183 -0
  142. package/frontend-vue/tests/backend-boundary.test.ts +203 -0
  143. package/frontend-vue/tests/fixtures/serverRender.ts +1 -1
  144. package/frontend-vue/tests/mediaPreviews.test.ts +39 -0
  145. package/package.json +5 -11
  146. package/skills/dms-media/SKILL.md +3 -2
  147. package/skills/dms-media/cases.json +38 -0
  148. package/src/acl/entries.ts +6 -4
  149. package/src/bindings.ts +3 -3
  150. package/src/declared/folders.ts +3 -3
  151. package/src/declared/records.ts +9 -8
  152. package/src/derivatives.ts +10 -6
  153. package/src/guards.ts +19 -0
  154. package/src/library/activity.ts +17 -9
  155. package/src/library/batches.ts +12 -9
  156. package/src/library/events.ts +7 -4
  157. package/src/library/module-readout.ts +6 -2
  158. package/src/library/realtime.ts +5 -1
  159. package/src/library/zip.ts +1 -1
  160. package/src/pages/activity.ts +6 -2
  161. package/src/routes/media/assets.ts +4 -3
  162. package/src/routes/media/bulk.ts +16 -14
  163. package/src/routes/media/delivery-headers.ts +9 -12
  164. package/src/routes/media/delivery-stream.ts +3 -2
  165. package/src/routes/media/delivery.ts +4 -2
  166. package/src/routes/media/manage.ts +4 -6
  167. package/src/routes/media/transform.ts +27 -23
  168. package/src/test/antelope.test.ts +21 -17
  169. package/src/test/helpers/folders.ts +22 -0
  170. package/src/test/helpers/pages.ts +12 -5
  171. package/src/test/helpers/permissions-world.ts +326 -0
  172. package/src/test/helpers/prototype.ts +12 -0
  173. package/src/test/integration/derivative-sweep-query.test.ts +19 -21
  174. package/src/test/integration/folder-query.test.ts +11 -11
  175. package/src/test/integration/media-bindings.test.ts +7 -7
  176. package/src/test/integration/media-cleanup.test.ts +25 -37
  177. package/src/test/integration/media-declared-content.test.ts +18 -19
  178. package/src/test/integration/media-delivery-editing.test.ts +11 -7
  179. package/src/test/integration/media-delivery.test.ts +29 -8
  180. package/src/test/integration/media-explorer-writes.test.ts +2 -7
  181. package/src/test/integration/media-guards.test.ts +21 -7
  182. package/src/test/integration/media-library.test.ts +1 -1
  183. package/src/test/integration/media-linked-subfolders.test.ts +11 -20
  184. package/src/test/integration/media-member-access.test.ts +5 -9
  185. package/src/test/integration/media-permissions.test.ts +56 -570
  186. package/src/test/integration/media-project-field.test.ts +5 -7
  187. package/src/test/integration/media-search-query.test.ts +16 -20
  188. package/src/test/integration/media-storage-origin-unreachable.test.ts +3 -2
  189. package/src/test/integration/media-upload-policy.test.ts +2 -8
  190. package/src/test/integration/permissions-management.ts +292 -0
  191. package/src/test/unit/acl/entries.test.ts +2 -1
  192. package/src/test/unit/acl/resolver.test.ts +19 -7
  193. package/src/test/unit/library/fixtures.ts +9 -3
  194. package/src/test/unit/library/library.test.ts +1 -7
  195. package/src/test/unit/library/realtime.test.ts +1 -1
  196. package/src/test/unit/library/search-facets.test.ts +2 -2
  197. package/src/test/unit/pages/toolbar.test.ts +42 -17
  198. package/src/test/unit/routes/dto.test.ts +7 -6
  199. package/src/test/unit/routes/file-page.test.ts +10 -9
  200. package/src/test/unit/routes/preset-row.test.ts +2 -2
  201. package/src/transform.ts +6 -6
  202. package/src/upload-checks.ts +12 -3
  203. package/src/upload-policy.ts +8 -8
  204. package/src/validation/declared.schema.ts +17 -12
  205. package/src/validation/media.schema.ts +6 -6
  206. package/frontend-vue/tests/engines.test.ts +0 -20
  207. package/frontend-vue/tests/locales.test.ts +0 -61
@@ -32,7 +32,8 @@ export class UnreadableImageError extends Error {}
32
32
 
33
33
  interface GenerationFailure {
34
34
  failedAt: number;
35
- error: unknown;
35
+ /** Set when the stored bytes could not be decoded: that error is rethrown while the failure is remembered. */
36
+ unreadable?: UnreadableImageError;
36
37
  }
37
38
 
38
39
  const generationLocks = new Map<string, Promise<string>>();
@@ -241,15 +242,15 @@ export function partitionDerivatives(
241
242
  return { fresh, stale };
242
243
  }
243
244
 
244
- function failureRetryDelay(error: unknown): number {
245
- return error instanceof UnreadableImageError
245
+ function failureRetryDelay(failure: GenerationFailure): number {
246
+ return failure.unreadable
246
247
  ? UNREADABLE_IMAGE_RETRY_MS
247
248
  : GENERATION_FAILURE_RETRY_MS;
248
249
  }
249
250
 
250
251
  function pruneExpiredGenerationFailures(now: number): void {
251
252
  for (const [lockKey, failure] of generationFailures) {
252
- if (now - failure.failedAt >= failureRetryDelay(failure.error)) {
253
+ if (now - failure.failedAt >= failureRetryDelay(failure)) {
253
254
  generationFailures.delete(lockKey);
254
255
  }
255
256
  }
@@ -259,7 +260,7 @@ function assertNoRecentGenerationFailure(lockKey: string): void {
259
260
  pruneExpiredGenerationFailures(Date.now());
260
261
  const failure = generationFailures.get(lockKey);
261
262
  if (!failure) return;
262
- if (failure.error instanceof UnreadableImageError) throw failure.error;
263
+ if (failure.unreadable) throw failure.unreadable;
263
264
  throw new Error("Derivative generation recently failed");
264
265
  }
265
266
 
@@ -284,7 +285,10 @@ export async function ensureDerivative(
284
285
  return storageKey;
285
286
  })
286
287
  .catch((error: unknown) => {
287
- generationFailures.set(lockKey, { failedAt: Date.now(), error });
288
+ generationFailures.set(lockKey, {
289
+ failedAt: Date.now(),
290
+ unreadable: error instanceof UnreadableImageError ? error : undefined,
291
+ });
288
292
  throw error;
289
293
  })
290
294
  .finally(() => generationLocks.delete(lockKey));
package/src/guards.ts ADDED
@@ -0,0 +1,19 @@
1
+ /** Whether `value` is a string. */
2
+ export function isString(value: unknown): value is string {
3
+ return typeof value === "string";
4
+ }
5
+
6
+ /** Whether `value` is a non-null object, arrays included. */
7
+ export function isObject(value: unknown): value is object {
8
+ return typeof value === "object" && value !== null;
9
+ }
10
+
11
+ /** Whether `value` can carry properties of its own: a non-null object or a function. */
12
+ export function isObjectLike(value: unknown): value is object {
13
+ return isObject(value) || isCallable(value);
14
+ }
15
+
16
+ /** Whether `typeof` reports `value` as a function: classes included, as TypeScript narrows it. */
17
+ export function isCallable(value: unknown): value is Function {
18
+ return typeof value === "function";
19
+ }
@@ -1,5 +1,4 @@
1
1
  import type { ActivityFeedItem } from "@antelopejs/interface-dms/base/activity-feed";
2
- import type { ComposedTextParam } from "@antelopejs/interface-dms/base/types";
3
2
  import type { Tone } from "@antelopejs/interface-dms/base/types/tone";
4
3
  import type { MediaEvent, MediaFolder } from "../db";
5
4
  import { countParam } from "./composed-text";
@@ -67,6 +66,11 @@ const EVENT_PRESENTATIONS: Record<MediaEventKind, EventPresentation> = {
67
66
  "folder.visibility": { icon: "i-ph-globe", tone: "success" },
68
67
  };
69
68
 
69
+ /** Whether a stored event kind is one this release records and presents. */
70
+ function isMediaEventKind(kind: string): kind is MediaEventKind {
71
+ return Object.hasOwn(EVENT_PRESENTATIONS, kind);
72
+ }
73
+
70
74
  const NEUTRAL_PRESENTATION: EventPresentation = {
71
75
  icon: "i-ph-clock-counter-clockwise",
72
76
  tone: "neutral",
@@ -163,9 +167,12 @@ function visibleDetails(details: MediaEventDetails): MediaEventDetails {
163
167
  );
164
168
  }
165
169
 
166
- function toParams(entry: ActivityEntry): Record<string, ComposedTextParam> {
170
+ /** The parameters of a feed item's title and meta texts. */
171
+ type FeedParams = NonNullable<ActivityFeedItem["params"]>;
172
+
173
+ function toParams(entry: ActivityEntry): FeedParams {
167
174
  const details = visibleDetails(readEventDetails(entry.event));
168
- const params: Record<string, ComposedTextParam> = {
175
+ const params: FeedParams = {
169
176
  actor: entry.event.actorName,
170
177
  name: entry.event.targetName,
171
178
  count: countParam(entry.count),
@@ -186,7 +193,7 @@ function titleSuffix(event: MediaEvent): string {
186
193
  return `_${visibility.replace(VISIBILITY_KEY_PREFIX, "")}`;
187
194
  }
188
195
 
189
- function batchParams(event: MediaEvent): Record<string, ComposedTextParam> {
196
+ function batchParams(event: MediaEvent): FeedParams {
190
197
  const details = readEventDetails(event);
191
198
  return {
192
199
  uploaded: countParam(event.count ?? 0),
@@ -200,11 +207,12 @@ function presentEntry(
200
207
  context: ActivityContext,
201
208
  ): ActivityFeedItem {
202
209
  const { event } = entry;
203
- const kind = event.kind as MediaEventKind;
210
+ const { kind } = event;
211
+ const known = isMediaEventKind(kind) ? kind : undefined;
204
212
  const isReport = kind === BATCH_REPORT_KIND;
205
213
  const presentation = isReport
206
214
  ? BATCH_PRESENTATIONS[batchOutcome(event)]
207
- : (EVENT_PRESENTATIONS[kind] ?? NEUTRAL_PRESENTATION);
215
+ : ((known && EVENT_PRESENTATIONS[known]) ?? NEUTRAL_PRESENTATION);
208
216
  const path = folderPath(subjectFolderId(event), context.foldersById);
209
217
  const isGone = Boolean(
210
218
  event.assetId && context.deletedAssetIds.has(event.assetId),
@@ -300,9 +308,9 @@ function foldBulkActions(entries: ActivityEntry[]): ActivityEntry[] {
300
308
 
301
309
  function deletedAssets(events: MediaEvent[]): Set<string> {
302
310
  return new Set(
303
- events
304
- .filter((event) => event.kind === "asset.delete" && event.assetId)
305
- .map((event) => event.assetId as string),
311
+ events.flatMap((event) =>
312
+ event.kind === "asset.delete" && event.assetId ? [event.assetId] : [],
313
+ ),
306
314
  );
307
315
  }
308
316
 
@@ -8,6 +8,8 @@ import {
8
8
  readEventDetails,
9
9
  UPLOAD_KIND,
10
10
  } from "./events";
11
+ import { z } from "zod";
12
+ import { isString } from "../guards";
11
13
 
12
14
  export interface UploadBatchRow {
13
15
  _id: string;
@@ -33,10 +35,11 @@ type BatchAttention = "yes" | "no";
33
35
  /** How long a failed upload keeps asking for attention. */
34
36
  export const FAILURE_WINDOW_MS = 24 * 60 * 60 * 1000;
35
37
 
36
- interface UploadFailure {
37
- name: string;
38
- reason?: string;
39
- }
38
+ const uploadFailuresSchema = z.array(
39
+ z.object({ name: z.string(), reason: z.string().optional() }),
40
+ );
41
+
42
+ type UploadFailures = z.infer<typeof uploadFailuresSchema>;
40
43
 
41
44
  const HISTORY_TEXTS = "dms_media.uploads.history";
42
45
  const FAILURES_SHOWN = 3;
@@ -51,7 +54,7 @@ interface BatchAccumulator {
51
54
  by: string;
52
55
  files: number;
53
56
  failed: number;
54
- failures: UploadFailure[];
57
+ failures: UploadFailures;
55
58
  size: number;
56
59
  finishedAt: Date;
57
60
  reportedAt?: Date;
@@ -71,12 +74,12 @@ function newBatch(key: string, event: MediaEvent): BatchAccumulator {
71
74
  }
72
75
 
73
76
  /** The files a batch report names as failed, with their reasons. */
74
- function readBatchFailures(event: MediaEvent): UploadFailure[] {
77
+ function readBatchFailures(event: MediaEvent): UploadFailures {
75
78
  const raw = readEventDetails(event).failures;
76
- if (typeof raw !== "string") return [];
79
+ if (!isString(raw)) return [];
77
80
  try {
78
- const parsed: unknown = JSON.parse(raw);
79
- return Array.isArray(parsed) ? (parsed as UploadFailure[]) : [];
81
+ const parsed = uploadFailuresSchema.safeParse(JSON.parse(raw));
82
+ return parsed.success ? parsed.data : [];
80
83
  } catch {
81
84
  return [];
82
85
  }
@@ -2,6 +2,7 @@ import { GetModel } from "@antelopejs/interface-database-decorators";
2
2
  import { Logging } from "@antelopejs/interface-core/logging";
3
3
  import type { User } from "@antelopejs/interface-dms/auth/db";
4
4
  import { type MediaEvent, MediaEventModel } from "../db";
5
+ import { z } from "zod";
5
6
  import { announceLibraryChange, UPLOAD_ANNOUNCE_WINDOW_MS } from "./realtime";
6
7
 
7
8
  const MEDIA_EVENT_KINDS = [
@@ -25,6 +26,10 @@ export type MediaEventKind = (typeof MEDIA_EVENT_KINDS)[number];
25
26
 
26
27
  export type MediaEventDetails = Record<string, string | number>;
27
28
 
29
+ const eventDetailsSchema: z.ZodType<MediaEventDetails> = z.record(
30
+ z.union([z.string(), z.number()]),
31
+ );
32
+
28
33
  export interface MediaEventInput {
29
34
  kind: MediaEventKind;
30
35
  targetName: string;
@@ -77,10 +82,8 @@ export async function recordMediaEvent(
77
82
  export function readEventDetails(event: MediaEvent): MediaEventDetails {
78
83
  if (!event.json_details) return {};
79
84
  try {
80
- const parsed: unknown = JSON.parse(event.json_details);
81
- return parsed && typeof parsed === "object"
82
- ? (parsed as MediaEventDetails)
83
- : {};
85
+ const parsed = eventDetailsSchema.safeParse(JSON.parse(event.json_details));
86
+ return parsed.success ? parsed.data : {};
84
87
  } catch {
85
88
  return {};
86
89
  }
@@ -13,6 +13,7 @@ import { loadAssetsInFolders } from "./listing";
13
13
  import { storedSize } from "./overview";
14
14
  import { isDescribableImage } from "./type-groups";
15
15
  import { loadUploadHistoryEvents } from "./upload-history";
16
+ import { isObject, isString } from "../guards";
16
17
 
17
18
  const TEXTS = "$dms_media.readout";
18
19
  const DEFAULT_LANGUAGE = "en";
@@ -38,8 +39,11 @@ export function readModuleVersion(): string | undefined {
38
39
  const manifest: unknown = JSON.parse(
39
40
  readFileSync(PACKAGE_MANIFEST, "utf8"),
40
41
  );
41
- const version = (manifest as Record<string, unknown>).version;
42
- return typeof version === "string" ? version : undefined;
42
+ const version =
43
+ isObject(manifest) && "version" in manifest
44
+ ? manifest.version
45
+ : undefined;
46
+ return isString(version) ? version : undefined;
43
47
  } catch {
44
48
  return undefined;
45
49
  }
@@ -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
  },