@antelopejs/dms-media 0.7.3 → 0.8.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 (141) hide show
  1. package/README.md +10 -10
  2. package/dist/acl/entries.js +20 -2
  3. package/dist/acl/entries.js.map +1 -1
  4. package/dist/asset-lifecycle.js +5 -1
  5. package/dist/asset-lifecycle.js.map +1 -1
  6. package/dist/bindings.d.ts +1 -0
  7. package/dist/bindings.js +36 -25
  8. package/dist/bindings.js.map +1 -1
  9. package/dist/db/models/mediaAssets.model.d.ts +3 -3
  10. package/dist/db/models/mediaDeclarations.model.d.ts +3 -3
  11. package/dist/db/models/mediaEvents.model.d.ts +3 -3
  12. package/dist/db/models/mediaFavorites.model.d.ts +3 -3
  13. package/dist/db/models/mediaFolders.model.d.ts +3 -3
  14. package/dist/db/models/mediaUploads.model.d.ts +3 -3
  15. package/dist/declared/assets.js +39 -25
  16. package/dist/declared/assets.js.map +1 -1
  17. package/dist/declared/folders.js +27 -14
  18. package/dist/declared/folders.js.map +1 -1
  19. package/dist/declared/records.d.ts +1 -0
  20. package/dist/declared/records.js +18 -1
  21. package/dist/declared/records.js.map +1 -1
  22. package/dist/fixed-id.d.ts +1 -0
  23. package/dist/fixed-id.js +16 -0
  24. package/dist/fixed-id.js.map +1 -0
  25. package/dist/routes/media/assets.d.ts +3 -2
  26. package/dist/routes/media/assets.js +11 -6
  27. package/dist/routes/media/assets.js.map +1 -1
  28. package/dist/routes/media/storage-keys.js +10 -1
  29. package/dist/routes/media/storage-keys.js.map +1 -1
  30. package/dist/test/helpers/assets.d.ts +2 -2
  31. package/dist/test/helpers/folders.d.ts +6 -6
  32. package/dist/test/helpers/permissions-world.d.ts +6 -6
  33. package/dist/test/integration/binding-folder-race.test.d.ts +1 -0
  34. package/dist/test/integration/binding-folder-race.test.js +66 -0
  35. package/dist/test/integration/binding-folder-race.test.js.map +1 -0
  36. package/dist/test/integration/declared-asset-race.test.d.ts +1 -0
  37. package/dist/test/integration/declared-asset-race.test.js +78 -0
  38. package/dist/test/integration/declared-asset-race.test.js.map +1 -0
  39. package/dist/test/integration/declared-folder-race.test.d.ts +1 -0
  40. package/dist/test/integration/declared-folder-race.test.js +43 -0
  41. package/dist/test/integration/declared-folder-race.test.js.map +1 -0
  42. package/dist/test/integration/media-activity-overview.test.js +27 -22
  43. package/dist/test/integration/media-activity-overview.test.js.map +1 -1
  44. package/dist/test/integration/media-api.test.js +9 -5
  45. package/dist/test/integration/media-api.test.js.map +1 -1
  46. package/dist/test/integration/media-bindings.test.js +16 -13
  47. package/dist/test/integration/media-bindings.test.js.map +1 -1
  48. package/dist/test/integration/media-cleanup.test.js +14 -5
  49. package/dist/test/integration/media-cleanup.test.js.map +1 -1
  50. package/dist/test/integration/media-declared-content.test.js +107 -91
  51. package/dist/test/integration/media-declared-content.test.js.map +1 -1
  52. package/dist/test/integration/media-delivery-editing.test.js +238 -215
  53. package/dist/test/integration/media-delivery-editing.test.js.map +1 -1
  54. package/dist/test/integration/media-explorer-writes.test.js +131 -112
  55. package/dist/test/integration/media-explorer-writes.test.js.map +1 -1
  56. package/dist/test/integration/media-guards.test.js +38 -37
  57. package/dist/test/integration/media-guards.test.js.map +1 -1
  58. package/dist/test/integration/media-library.test.js +244 -224
  59. package/dist/test/integration/media-library.test.js.map +1 -1
  60. package/dist/test/integration/media-linked-subfolders.test.js +173 -158
  61. package/dist/test/integration/media-linked-subfolders.test.js.map +1 -1
  62. package/dist/test/integration/media-permissions.test.js +31 -11
  63. package/dist/test/integration/media-permissions.test.js.map +1 -1
  64. package/dist/test/integration/media-search-query.test.js +8 -6
  65. package/dist/test/integration/media-search-query.test.js.map +1 -1
  66. package/dist/test/integration/media-search-views.test.js +12 -8
  67. package/dist/test/integration/media-search-views.test.js.map +1 -1
  68. package/dist/test/integration/media-upload-policy.test.js +228 -200
  69. package/dist/test/integration/media-upload-policy.test.js.map +1 -1
  70. package/dist/test/stack-modules.json +5 -5
  71. package/dist/test/unit/acl/entries.test.js +19 -0
  72. package/dist/test/unit/acl/entries.test.js.map +1 -1
  73. package/dist/test/unit/acl/resolver.test.js +9 -1
  74. package/dist/test/unit/acl/resolver.test.js.map +1 -1
  75. package/dist/test/unit/asset-lifecycle.test.d.ts +1 -0
  76. package/dist/test/unit/asset-lifecycle.test.js +18 -0
  77. package/dist/test/unit/asset-lifecycle.test.js.map +1 -0
  78. package/dist/test/unit/routes/storage-keys.test.d.ts +1 -0
  79. package/dist/test/unit/routes/storage-keys.test.js +18 -0
  80. package/dist/test/unit/routes/storage-keys.test.js.map +1 -0
  81. package/dist/test/unit/transform-ops.test.js +19 -0
  82. package/dist/test/unit/transform-ops.test.js.map +1 -1
  83. package/dist/transform-ops.js +25 -1
  84. package/dist/transform-ops.js.map +1 -1
  85. package/dist/validation/declared.schema.d.ts +6 -6
  86. package/dist/validation/library.schema.d.ts +4 -4
  87. package/dist/validation/media.schema.d.ts +4 -4
  88. package/frontend-vue/app/components/Explorer.vue +2 -0
  89. package/frontend-vue/app/components/FileProperties.vue +1 -1
  90. package/frontend-vue/app/components/ImageEditor.vue +5 -5
  91. package/frontend-vue/app/components/RecentFiles.vue +2 -2
  92. package/frontend-vue/app/components/UploadQueue.vue +4 -4
  93. package/frontend-vue/app/components/dialogs/DeleteFilesDialog.vue +1 -1
  94. package/frontend-vue/app/components/dialogs/ShortcutsDialog.vue +1 -1
  95. package/frontend-vue/app/components/dialogs/VisibilityDialog.vue +1 -1
  96. package/frontend-vue/app/components/explorer/ExplorerInspector.vue +1 -1
  97. package/frontend-vue/app/components/explorer/ExplorerSidebar.vue +2 -2
  98. package/frontend-vue/app/components/explorer/FolderStrip.vue +1 -1
  99. package/frontend-vue/app/components/explorer/GridView.vue +1 -1
  100. package/frontend-vue/app/components/shared/AltTextField.vue +2 -2
  101. package/frontend-vue/build/backend-boundary.ts +8 -3
  102. package/frontend-vue/eslint.config.mjs +0 -1
  103. package/frontend-vue/package.json +2 -2
  104. package/frontend-vue/pnpm-lock.yaml +45 -14
  105. package/frontend-vue/tests/backend-boundary.test.ts +6 -4
  106. package/frontend-vue/tests/fixtures/serverRender.ts +3 -3
  107. package/frontend-vue/tests/registration.test.ts +5 -0
  108. package/package.json +15 -15
  109. package/src/acl/entries.ts +30 -7
  110. package/src/asset-lifecycle.ts +6 -2
  111. package/src/bindings.ts +41 -38
  112. package/src/declared/assets.ts +45 -28
  113. package/src/declared/folders.ts +30 -21
  114. package/src/declared/records.ts +31 -2
  115. package/src/fixed-id.ts +18 -0
  116. package/src/routes/media/assets.ts +14 -6
  117. package/src/routes/media/storage-keys.ts +14 -2
  118. package/src/test/integration/binding-folder-race.test.ts +82 -0
  119. package/src/test/integration/declared-asset-race.test.ts +115 -0
  120. package/src/test/integration/declared-folder-race.test.ts +50 -0
  121. package/src/test/integration/media-activity-overview.test.ts +40 -27
  122. package/src/test/integration/media-api.test.ts +9 -5
  123. package/src/test/integration/media-bindings.test.ts +17 -13
  124. package/src/test/integration/media-cleanup.test.ts +17 -5
  125. package/src/test/integration/media-declared-content.test.ts +129 -112
  126. package/src/test/integration/media-delivery-editing.test.ts +323 -299
  127. package/src/test/integration/media-explorer-writes.test.ts +161 -135
  128. package/src/test/integration/media-guards.test.ts +40 -38
  129. package/src/test/integration/media-library.test.ts +325 -296
  130. package/src/test/integration/media-linked-subfolders.test.ts +207 -186
  131. package/src/test/integration/media-permissions.test.ts +33 -14
  132. package/src/test/integration/media-search-query.test.ts +24 -8
  133. package/src/test/integration/media-search-views.test.ts +39 -32
  134. package/src/test/integration/media-upload-policy.test.ts +283 -254
  135. package/src/test/stack-modules.json +5 -5
  136. package/src/test/unit/acl/entries.test.ts +23 -0
  137. package/src/test/unit/acl/resolver.test.ts +9 -1
  138. package/src/test/unit/asset-lifecycle.test.ts +21 -0
  139. package/src/test/unit/routes/storage-keys.test.ts +23 -0
  140. package/src/test/unit/transform-ops.test.ts +29 -1
  141. package/src/transform-ops.ts +32 -2
@@ -79,13 +79,328 @@ const presetsBody = z.object({
79
79
  ),
80
80
  });
81
81
 
82
- describe("[integration] media library — listings, search, bulk and overview", () => {
83
- let client: AxiosInstance;
84
- let rootId: string;
85
- let childId: string;
86
- let otherId: string;
87
- const ids: Record<string, string> = {};
82
+ let client: AxiosInstance;
83
+ let rootId: string;
84
+ let childId: string;
85
+ let otherId: string;
86
+ const ids: Record<string, string> = {};
88
87
 
88
+ function describeListings(): void {
89
+ describe("tree, listings, favorites and recent files", () => {
90
+ it("returns recursive counts, view counts and the upload limit with the tree", async () => {
91
+ const response = await client.get("/api/media/tree");
92
+ expect(response.status).to.equal(HTTP_OK);
93
+ const root = readBody(response, treeBody).folders.find(
94
+ (folder) => folder.id === rootId,
95
+ );
96
+ expect(root?.fileCount).to.equal(4);
97
+ expect(root?.size).to.be.greaterThan(0);
98
+ expect(response.data.views.missingAlt).to.be.at.least(3);
99
+ expect(response.data.maxUploadBytes).to.equal(500 * 1024 * 1024);
100
+ expect(response.data.isOwner).to.equal(true);
101
+ });
102
+
103
+ it("pages, sorts and filters a folder listing with type facets", async () => {
104
+ const page = await client.get(`/api/media/folders/${childId}/assets`, {
105
+ params: { limit: 2, sort: "name", direction: "asc" },
106
+ });
107
+ expect(page.status).to.equal(HTTP_OK);
108
+ expect(page.data.total).to.equal(4);
109
+ expect(
110
+ page.data.assets.map((asset: AssetRow) => asset.name),
111
+ ).to.deep.equal(["notes.txt", "oak-a.png"]);
112
+ expect(page.data.facets).to.include({ all: 4, image: 3, document: 1 });
113
+ const images = await client.get(`/api/media/folders/${childId}/assets`, {
114
+ params: { type: "image", sort: "name", direction: "desc", offset: 1 },
115
+ });
116
+ expect(images.data.total).to.equal(3);
117
+ expect(
118
+ images.data.assets.map((asset: AssetRow) => asset.name),
119
+ ).to.deep.equal(["oak-b.png", "oak-a.png"]);
120
+ });
121
+
122
+ it("rejects an unknown sort key", async () => {
123
+ const response = await client.get(
124
+ `/api/media/folders/${childId}/assets`,
125
+ {
126
+ params: { sort: "colour" },
127
+ },
128
+ );
129
+ expect(response.status).to.equal(HTTP_BAD_REQUEST);
130
+ });
131
+
132
+ it("stars files and folders and lists them in the starred view", async () => {
133
+ for (const body of [
134
+ { kind: "asset", targetId: ids["walnut.png"], starred: true },
135
+ { kind: "folder", targetId: childId, starred: true },
136
+ ]) {
137
+ expect(
138
+ (await client.post("/api/media/favorites", body)).status,
139
+ ).to.equal(HTTP_OK);
140
+ }
141
+ const view = await client.get("/api/media/views/starred");
142
+ expect(view.data.assets.map((asset: AssetRow) => asset.id)).to.include(
143
+ ids["walnut.png"],
144
+ );
145
+ expect(
146
+ view.data.folders.map((folder: { id: string }) => folder.id),
147
+ ).to.include(childId);
148
+ await client.post("/api/media/favorites", {
149
+ kind: "asset",
150
+ targetId: ids["walnut.png"],
151
+ starred: false,
152
+ });
153
+ const after = await client.get("/api/media/views/starred");
154
+ expect(
155
+ after.data.assets.map((asset: AssetRow) => asset.id),
156
+ ).not.to.include(ids["walnut.png"]);
157
+ });
158
+
159
+ it("lists recent files newest first and images without alt text", async () => {
160
+ const recent = await client.get("/api/media/views/recent");
161
+ expect(recent.data.assets[0].id).to.equal(ids["notes.txt"]);
162
+ await client.post(`/api/media/assets/${ids["oak-a.png"]}/update`, {
163
+ alt: "Oak desk in a bright studio",
164
+ });
165
+ const missing = await client.get("/api/media/views/missing-alt");
166
+ const names = readBody(missing, assetsBody).assets.map(
167
+ (asset) => asset.name,
168
+ );
169
+ expect(names).to.include("oak-b.png");
170
+ expect(names).not.to.include("oak-a.png");
171
+ expect(names).not.to.include("notes.txt");
172
+ });
173
+ });
174
+ }
175
+
176
+ function describeSearchAndDetails(): void {
177
+ describe("search, details and delivery links", () => {
178
+ it("searches names, alt text and folders, scoped and filtered", async () => {
179
+ const byAlt = await client.get("/api/media/search", {
180
+ params: { q: "studio" },
181
+ });
182
+ expect(byAlt.data.assets).to.have.length(1);
183
+ expect(byAlt.data.assets[0]).to.include({
184
+ id: ids["oak-a.png"],
185
+ matchedOn: "alt",
186
+ });
187
+ const byName = await client.get("/api/media/search", {
188
+ params: { q: "OAK", folderId: rootId },
189
+ });
190
+ expect(byName.data.total).to.equal(2);
191
+ expect(
192
+ byName.data.folders.map((folder: { id: string }) => folder.id),
193
+ ).to.deep.equal([childId]);
194
+ const publicOnly = await client.get("/api/media/search", {
195
+ params: { q: "oak", visibility: "public" },
196
+ });
197
+ expect(publicOnly.data.total).to.equal(0);
198
+ const elsewhere = await client.get("/api/media/search", {
199
+ params: { q: "oak", folderId: otherId },
200
+ });
201
+ expect(elsewhere.data.total).to.equal(0);
202
+ });
203
+
204
+ it("describes an asset with its path and uploader", async () => {
205
+ const response = await client.get(
206
+ `/api/media/assets/${ids["oak-a.png"]}/details`,
207
+ );
208
+ expect(response.status).to.equal(HTTP_OK);
209
+ expect(
210
+ response.data.path.map((entry: { name: string }) => entry.name),
211
+ ).to.deep.equal(["Library spec", "Oak shots"]);
212
+ expect(response.data.uploadedBy).to.equal("Test Owner");
213
+ });
214
+
215
+ it("serves the file page information list and tab counts", async () => {
216
+ const assetId = ids["oak-a.png"];
217
+ const information = await client.get(
218
+ `/api/media/assets/${assetId}/information`,
219
+ );
220
+ expect(information.status).to.equal(HTTP_OK);
221
+ expect(
222
+ information.data.items.map((item: { id: string }) => item.id),
223
+ ).to.deep.equal(["uploaded", "modified", "type"]);
224
+ expect(information.data.items[0].detail).to.equal("Test Owner");
225
+ const counts = await client.get(
226
+ `/api/media/assets/${assetId}/tab-counts`,
227
+ );
228
+ expect(counts.data).to.deep.equal({ delivery: 3 });
229
+ });
230
+
231
+ it("serves the delivery links with full URLs to copy, and how they are served", async () => {
232
+ const assetId = ids["oak-a.png"];
233
+ const links = await client.get(`/api/media/assets/${assetId}/delivery`);
234
+ expect(links.status).to.equal(HTTP_OK);
235
+ const { items } = readBody(links, deliveryBody);
236
+ expect(items.map((item) => item.id)).to.deep.equal([
237
+ "stable",
238
+ "thumb",
239
+ "preview",
240
+ "asset-id",
241
+ "presets",
242
+ ]);
243
+ const [stable] = items;
244
+ expect(items.find((item) => item.id === "asset-id")?.value).to.equal(
245
+ assetId,
246
+ );
247
+ expect(stable?.value).to.equal(`/media/${assetId}/oak-a.png`);
248
+ expect(stable?.copyValue).to.match(
249
+ new RegExp(`^https?://[^/]+/media/${assetId}/oak-a\\.png$`),
250
+ );
251
+ const notice = await client.get(
252
+ `/api/media/assets/${assetId}/delivery/notice`,
253
+ );
254
+ expect(notice.status).to.equal(HTTP_OK);
255
+ expect(notice.data.description).to.match(
256
+ /delivery_(public|private_notice)$/,
257
+ );
258
+ });
259
+ });
260
+ }
261
+
262
+ function describeBulkActions(): void {
263
+ describe("bulk actions and folder impact", () => {
264
+ it("moves, changes visibility and deletes in bulk, reporting refusals", async () => {
265
+ const moved = await client.post("/api/media/assets/bulk/move", {
266
+ ids: [ids["oak-b.png"], "missing-asset"],
267
+ folderId: otherId,
268
+ });
269
+ expect(moved.status).to.equal(HTTP_OK);
270
+ expect(moved.data.done).to.deep.equal([ids["oak-b.png"]]);
271
+ expect(moved.data.refused).to.have.length(1);
272
+ expect(moved.data.refused[0]).to.include({
273
+ id: "missing-asset",
274
+ status: HTTP_NOT_FOUND,
275
+ });
276
+ const visibility = await client.post(
277
+ "/api/media/assets/bulk/visibility",
278
+ {
279
+ ids: [ids["oak-b.png"]],
280
+ visibility: "public",
281
+ },
282
+ );
283
+ expect(visibility.data.done).to.have.length(1);
284
+ const publicOnly = await client.get("/api/media/search", {
285
+ params: { q: "oak", visibility: "public" },
286
+ });
287
+ expect(publicOnly.data.total).to.equal(1);
288
+ });
289
+
290
+ it("streams a zip of the selection", async () => {
291
+ const response = await client.post(
292
+ "/api/media/assets/zip",
293
+ { ids: [ids["oak-a.png"], ids["walnut.png"], ids["notes.txt"]] },
294
+ { responseType: "arraybuffer" },
295
+ );
296
+ expect(response.status).to.equal(HTTP_OK);
297
+ expect(response.headers["content-type"]).to.contain("application/zip");
298
+ const archive = Buffer.from(response.data);
299
+ expect(archive.readUInt32LE(0)).to.equal(ZIP_LOCAL_SIGNATURE);
300
+ const end = archive.subarray(archive.length - ZIP_END_RECORD_SIZE);
301
+ expect(end.readUInt32LE(0)).to.equal(ZIP_END_SIGNATURE);
302
+ expect(end.readUInt16LE(ZIP_ENTRY_COUNT_OFFSET)).to.equal(3);
303
+ });
304
+
305
+ it("summarizes what deleting a folder removes", async () => {
306
+ const response = await client.get(`/api/media/folders/${rootId}/impact`);
307
+ expect(response.status).to.equal(HTTP_OK);
308
+ expect(response.data).to.include({
309
+ subfolders: 2,
310
+ files: 4,
311
+ publicFiles: 1,
312
+ linkedSubfolders: 0,
313
+ });
314
+ });
315
+ });
316
+ }
317
+
318
+ function describeOverview(): void {
319
+ describe("overview, upload batches and presets", () => {
320
+ it("serves the overview blocks", async () => {
321
+ const kpis = await client.get("/api/media/stats/kpis");
322
+ expect(
323
+ kpis.data.items.map((item: { id: string }) => item.id),
324
+ ).to.deep.equal(["files", "storage", "public", "missing-alt"]);
325
+ expect(kpis.data.items[0].detail.key).to.equal(
326
+ "dms_media.overview.kpis.files_detail",
327
+ );
328
+ expect(kpis.data.items[0].detail.params.files.type).to.equal("count");
329
+ expect(kpis.data.items[1].value.key).to.match(/^dms_media\.units\./);
330
+ const storage = await client.get("/api/media/stats/storage");
331
+ expect(storage.data.segments.length).to.be.at.least(2);
332
+ expect(storage.data.valueLabel.key).to.match(/^dms_media\.units\./);
333
+ expect(storage.data.hint.params.files.type).to.equal("count");
334
+ const attention = await client.get("/api/media/stats/attention");
335
+ expect(
336
+ attention.data.items.map((item: { id: string }) => item.id),
337
+ ).to.include("missing-alt");
338
+ const recent = await client.get("/api/media/stats/recent");
339
+ expect(recent.data.assets.length).to.be.at.most(6);
340
+ });
341
+
342
+ it("folds one upload batch into a single activity entry", async () => {
343
+ const response = await client.get("/api/media/activity", {
344
+ params: { limit: 50 },
345
+ });
346
+ expect(response.status).to.equal(HTTP_OK);
347
+ const batch = readBody(response, activityBody).items.find(
348
+ (item) =>
349
+ item.title === "$dms_media.activity.asset_upload" &&
350
+ item.params.count?.value === BATCH_FILES,
351
+ );
352
+ expect(batch).to.not.equal(undefined);
353
+ const history = await client.get(
354
+ `/api/media/assets/${ids["oak-b.png"]}/history`,
355
+ );
356
+ const titles = readBody(history, historyBody).items.map(
357
+ (item) => item.title,
358
+ );
359
+ expect(titles).to.include("$dms_media.activity.asset_move");
360
+ expect(titles).to.include("$dms_media.activity.asset_visibility_public");
361
+ expect(titles).to.include("$dms_media.activity.asset_upload");
362
+ });
363
+
364
+ it("records a batch summary and lists upload batches", async () => {
365
+ const report = await client.post("/api/media/upload/batches", {
366
+ batchId: BATCH_ID,
367
+ folderId: childId,
368
+ total: 4,
369
+ uploaded: 3,
370
+ failed: 1,
371
+ size: 300,
372
+ });
373
+ expect(report.status).to.equal(HTTP_OK);
374
+ const batches = await client.get("/api/media/upload/batches");
375
+ const row = readBody(batches, batchesBody).results.find(
376
+ (entry) => entry._id === BATCH_ID,
377
+ );
378
+ expect(row).to.include({ files: 3, failed: 1, result: "partial" });
379
+ expect(row?.folder).to.equal("Library spec › Oak shots");
380
+ });
381
+
382
+ it("lists delivery presets with their cache keys", async () => {
383
+ await client.get(`/api/media/previews?ids=${ids["oak-a.png"]}`);
384
+ const response = await client.get("/api/media/presets");
385
+ expect(response.status).to.equal(HTTP_OK);
386
+ const thumb = readBody(response, presetsBody).presets.find(
387
+ (preset) => preset.id === "thumb",
388
+ );
389
+ expect(thumb?.cacheKey).to.match(/^thumb\./);
390
+ expect(thumb?.rendered).to.be.at.least(1);
391
+ expect(response.data.cache.schedule).to.equal("0 4 * * *");
392
+ });
393
+
394
+ it("refuses starter folders that clash with a root folder", async () => {
395
+ const response = await client.post("/api/media/folders/starter", {
396
+ folders: [{ name: "Library spec", visibility: "private" }],
397
+ });
398
+ expect(response.status).to.equal(HTTP_CONFLICT);
399
+ });
400
+ });
401
+ }
402
+
403
+ describe("[integration] media library — listings, search, bulk and overview", () => {
89
404
  before(async function () {
90
405
  this.timeout(30_000);
91
406
  const session = await ensureOwnerSession();
@@ -124,294 +439,8 @@ describe("[integration] media library — listings, search, bulk and overview",
124
439
  await client.delete(`/api/media/folders/${rootId}`);
125
440
  });
126
441
 
127
- it("returns recursive counts, view counts and the upload limit with the tree", async () => {
128
- const response = await client.get("/api/media/tree");
129
- expect(response.status).to.equal(HTTP_OK);
130
- const root = readBody(response, treeBody).folders.find(
131
- (folder) => folder.id === rootId,
132
- );
133
- expect(root?.fileCount).to.equal(4);
134
- expect(root?.size).to.be.greaterThan(0);
135
- expect(response.data.views.missingAlt).to.be.at.least(3);
136
- expect(response.data.maxUploadBytes).to.equal(500 * 1024 * 1024);
137
- expect(response.data.isOwner).to.equal(true);
138
- });
139
-
140
- it("pages, sorts and filters a folder listing with type facets", async () => {
141
- const page = await client.get(`/api/media/folders/${childId}/assets`, {
142
- params: { limit: 2, sort: "name", direction: "asc" },
143
- });
144
- expect(page.status).to.equal(HTTP_OK);
145
- expect(page.data.total).to.equal(4);
146
- expect(page.data.assets.map((asset: AssetRow) => asset.name)).to.deep.equal(
147
- ["notes.txt", "oak-a.png"],
148
- );
149
- expect(page.data.facets).to.include({ all: 4, image: 3, document: 1 });
150
- const images = await client.get(`/api/media/folders/${childId}/assets`, {
151
- params: { type: "image", sort: "name", direction: "desc", offset: 1 },
152
- });
153
- expect(images.data.total).to.equal(3);
154
- expect(
155
- images.data.assets.map((asset: AssetRow) => asset.name),
156
- ).to.deep.equal(["oak-b.png", "oak-a.png"]);
157
- });
158
-
159
- it("rejects an unknown sort key", async () => {
160
- const response = await client.get(`/api/media/folders/${childId}/assets`, {
161
- params: { sort: "colour" },
162
- });
163
- expect(response.status).to.equal(HTTP_BAD_REQUEST);
164
- });
165
-
166
- it("stars files and folders and lists them in the starred view", async () => {
167
- for (const body of [
168
- { kind: "asset", targetId: ids["walnut.png"], starred: true },
169
- { kind: "folder", targetId: childId, starred: true },
170
- ]) {
171
- expect((await client.post("/api/media/favorites", body)).status).to.equal(
172
- HTTP_OK,
173
- );
174
- }
175
- const view = await client.get("/api/media/views/starred");
176
- expect(view.data.assets.map((asset: AssetRow) => asset.id)).to.include(
177
- ids["walnut.png"],
178
- );
179
- expect(
180
- view.data.folders.map((folder: { id: string }) => folder.id),
181
- ).to.include(childId);
182
- await client.post("/api/media/favorites", {
183
- kind: "asset",
184
- targetId: ids["walnut.png"],
185
- starred: false,
186
- });
187
- const after = await client.get("/api/media/views/starred");
188
- expect(after.data.assets.map((asset: AssetRow) => asset.id)).not.to.include(
189
- ids["walnut.png"],
190
- );
191
- });
192
-
193
- it("lists recent files newest first and images without alt text", async () => {
194
- const recent = await client.get("/api/media/views/recent");
195
- expect(recent.data.assets[0].id).to.equal(ids["notes.txt"]);
196
- await client.post(`/api/media/assets/${ids["oak-a.png"]}/update`, {
197
- alt: "Oak desk in a bright studio",
198
- });
199
- const missing = await client.get("/api/media/views/missing-alt");
200
- const names = readBody(missing, assetsBody).assets.map(
201
- (asset) => asset.name,
202
- );
203
- expect(names).to.include("oak-b.png");
204
- expect(names).not.to.include("oak-a.png");
205
- expect(names).not.to.include("notes.txt");
206
- });
207
-
208
- it("searches names, alt text and folders, scoped and filtered", async () => {
209
- const byAlt = await client.get("/api/media/search", {
210
- params: { q: "studio" },
211
- });
212
- expect(byAlt.data.assets).to.have.length(1);
213
- expect(byAlt.data.assets[0]).to.include({
214
- id: ids["oak-a.png"],
215
- matchedOn: "alt",
216
- });
217
- const byName = await client.get("/api/media/search", {
218
- params: { q: "OAK", folderId: rootId },
219
- });
220
- expect(byName.data.total).to.equal(2);
221
- expect(
222
- byName.data.folders.map((folder: { id: string }) => folder.id),
223
- ).to.deep.equal([childId]);
224
- const publicOnly = await client.get("/api/media/search", {
225
- params: { q: "oak", visibility: "public" },
226
- });
227
- expect(publicOnly.data.total).to.equal(0);
228
- const elsewhere = await client.get("/api/media/search", {
229
- params: { q: "oak", folderId: otherId },
230
- });
231
- expect(elsewhere.data.total).to.equal(0);
232
- });
233
-
234
- it("describes an asset with its path and uploader", async () => {
235
- const response = await client.get(
236
- `/api/media/assets/${ids["oak-a.png"]}/details`,
237
- );
238
- expect(response.status).to.equal(HTTP_OK);
239
- expect(
240
- response.data.path.map((entry: { name: string }) => entry.name),
241
- ).to.deep.equal(["Library spec", "Oak shots"]);
242
- expect(response.data.uploadedBy).to.equal("Test Owner");
243
- });
244
-
245
- it("serves the file page information list and tab counts", async () => {
246
- const assetId = ids["oak-a.png"];
247
- const information = await client.get(
248
- `/api/media/assets/${assetId}/information`,
249
- );
250
- expect(information.status).to.equal(HTTP_OK);
251
- expect(
252
- information.data.items.map((item: { id: string }) => item.id),
253
- ).to.deep.equal(["uploaded", "modified", "type"]);
254
- expect(information.data.items[0].detail).to.equal("Test Owner");
255
- const counts = await client.get(`/api/media/assets/${assetId}/tab-counts`);
256
- expect(counts.data).to.deep.equal({ delivery: 3 });
257
- });
258
-
259
- it("serves the delivery links with full URLs to copy, and how they are served", async () => {
260
- const assetId = ids["oak-a.png"];
261
- const links = await client.get(`/api/media/assets/${assetId}/delivery`);
262
- expect(links.status).to.equal(HTTP_OK);
263
- const { items } = readBody(links, deliveryBody);
264
- expect(items.map((item) => item.id)).to.deep.equal([
265
- "stable",
266
- "thumb",
267
- "preview",
268
- "asset-id",
269
- "presets",
270
- ]);
271
- const [stable] = items;
272
- expect(items.find((item) => item.id === "asset-id")?.value).to.equal(
273
- assetId,
274
- );
275
- expect(stable?.value).to.equal(`/media/${assetId}/oak-a.png`);
276
- expect(stable?.copyValue).to.match(
277
- new RegExp(`^https?://[^/]+/media/${assetId}/oak-a\\.png$`),
278
- );
279
- const notice = await client.get(
280
- `/api/media/assets/${assetId}/delivery/notice`,
281
- );
282
- expect(notice.status).to.equal(HTTP_OK);
283
- expect(notice.data.description).to.match(
284
- /delivery_(public|private_notice)$/,
285
- );
286
- });
287
-
288
- it("moves, changes visibility and deletes in bulk, reporting refusals", async () => {
289
- const moved = await client.post("/api/media/assets/bulk/move", {
290
- ids: [ids["oak-b.png"], "missing-asset"],
291
- folderId: otherId,
292
- });
293
- expect(moved.status).to.equal(HTTP_OK);
294
- expect(moved.data.done).to.deep.equal([ids["oak-b.png"]]);
295
- expect(moved.data.refused).to.have.length(1);
296
- expect(moved.data.refused[0]).to.include({
297
- id: "missing-asset",
298
- status: HTTP_NOT_FOUND,
299
- });
300
- const visibility = await client.post("/api/media/assets/bulk/visibility", {
301
- ids: [ids["oak-b.png"]],
302
- visibility: "public",
303
- });
304
- expect(visibility.data.done).to.have.length(1);
305
- const publicOnly = await client.get("/api/media/search", {
306
- params: { q: "oak", visibility: "public" },
307
- });
308
- expect(publicOnly.data.total).to.equal(1);
309
- });
310
-
311
- it("streams a zip of the selection", async () => {
312
- const response = await client.post(
313
- "/api/media/assets/zip",
314
- { ids: [ids["oak-a.png"], ids["walnut.png"], ids["notes.txt"]] },
315
- { responseType: "arraybuffer" },
316
- );
317
- expect(response.status).to.equal(HTTP_OK);
318
- expect(response.headers["content-type"]).to.contain("application/zip");
319
- const archive = Buffer.from(response.data);
320
- expect(archive.readUInt32LE(0)).to.equal(ZIP_LOCAL_SIGNATURE);
321
- const end = archive.subarray(archive.length - ZIP_END_RECORD_SIZE);
322
- expect(end.readUInt32LE(0)).to.equal(ZIP_END_SIGNATURE);
323
- expect(end.readUInt16LE(ZIP_ENTRY_COUNT_OFFSET)).to.equal(3);
324
- });
325
-
326
- it("summarizes what deleting a folder removes", async () => {
327
- const response = await client.get(`/api/media/folders/${rootId}/impact`);
328
- expect(response.status).to.equal(HTTP_OK);
329
- expect(response.data).to.include({
330
- subfolders: 2,
331
- files: 4,
332
- publicFiles: 1,
333
- linkedSubfolders: 0,
334
- });
335
- });
336
-
337
- it("serves the overview blocks", async () => {
338
- const kpis = await client.get("/api/media/stats/kpis");
339
- expect(
340
- kpis.data.items.map((item: { id: string }) => item.id),
341
- ).to.deep.equal(["files", "storage", "public", "missing-alt"]);
342
- expect(kpis.data.items[0].detail.key).to.equal(
343
- "dms_media.overview.kpis.files_detail",
344
- );
345
- expect(kpis.data.items[0].detail.params.files.type).to.equal("count");
346
- expect(kpis.data.items[1].value.key).to.match(/^dms_media\.units\./);
347
- const storage = await client.get("/api/media/stats/storage");
348
- expect(storage.data.segments.length).to.be.at.least(2);
349
- expect(storage.data.valueLabel.key).to.match(/^dms_media\.units\./);
350
- expect(storage.data.hint.params.files.type).to.equal("count");
351
- const attention = await client.get("/api/media/stats/attention");
352
- expect(
353
- attention.data.items.map((item: { id: string }) => item.id),
354
- ).to.include("missing-alt");
355
- const recent = await client.get("/api/media/stats/recent");
356
- expect(recent.data.assets.length).to.be.at.most(6);
357
- });
358
-
359
- it("folds one upload batch into a single activity entry", async () => {
360
- const response = await client.get("/api/media/activity", {
361
- params: { limit: 50 },
362
- });
363
- expect(response.status).to.equal(HTTP_OK);
364
- const batch = readBody(response, activityBody).items.find(
365
- (item) =>
366
- item.title === "$dms_media.activity.asset_upload" &&
367
- item.params.count?.value === BATCH_FILES,
368
- );
369
- expect(batch).to.not.equal(undefined);
370
- const history = await client.get(
371
- `/api/media/assets/${ids["oak-b.png"]}/history`,
372
- );
373
- const titles = readBody(history, historyBody).items.map(
374
- (item) => item.title,
375
- );
376
- expect(titles).to.include("$dms_media.activity.asset_move");
377
- expect(titles).to.include("$dms_media.activity.asset_visibility_public");
378
- expect(titles).to.include("$dms_media.activity.asset_upload");
379
- });
380
-
381
- it("records a batch summary and lists upload batches", async () => {
382
- const report = await client.post("/api/media/upload/batches", {
383
- batchId: BATCH_ID,
384
- folderId: childId,
385
- total: 4,
386
- uploaded: 3,
387
- failed: 1,
388
- size: 300,
389
- });
390
- expect(report.status).to.equal(HTTP_OK);
391
- const batches = await client.get("/api/media/upload/batches");
392
- const row = readBody(batches, batchesBody).results.find(
393
- (entry) => entry._id === BATCH_ID,
394
- );
395
- expect(row).to.include({ files: 3, failed: 1, result: "partial" });
396
- expect(row?.folder).to.equal("Library spec › Oak shots");
397
- });
398
-
399
- it("lists delivery presets with their cache keys", async () => {
400
- await client.get(`/api/media/previews?ids=${ids["oak-a.png"]}`);
401
- const response = await client.get("/api/media/presets");
402
- expect(response.status).to.equal(HTTP_OK);
403
- const thumb = readBody(response, presetsBody).presets.find(
404
- (preset) => preset.id === "thumb",
405
- );
406
- expect(thumb?.cacheKey).to.match(/^thumb\./);
407
- expect(thumb?.rendered).to.be.at.least(1);
408
- expect(response.data.cache.schedule).to.equal("0 4 * * *");
409
- });
410
-
411
- it("refuses starter folders that clash with a root folder", async () => {
412
- const response = await client.post("/api/media/folders/starter", {
413
- folders: [{ name: "Library spec", visibility: "private" }],
414
- });
415
- expect(response.status).to.equal(HTTP_CONFLICT);
416
- });
442
+ describeListings();
443
+ describeSearchAndDetails();
444
+ describeBulkActions();
445
+ describeOverview();
417
446
  });