@antelopejs/dms-media 0.8.2 → 0.8.3-next.167.g8bd8349

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 (133) hide show
  1. package/dist/test/antelope.test.js +1 -0
  2. package/dist/test/antelope.test.js.map +1 -1
  3. package/dist/test/helpers/config.d.ts +2 -0
  4. package/dist/test/helpers/config.js +16 -0
  5. package/dist/test/helpers/config.js.map +1 -0
  6. package/dist/test/helpers/delivery.d.ts +9 -0
  7. package/dist/test/helpers/delivery.js +47 -0
  8. package/dist/test/helpers/delivery.js.map +1 -0
  9. package/dist/test/helpers/derivative-storage.d.ts +3 -0
  10. package/dist/test/helpers/derivative-storage.js +22 -0
  11. package/dist/test/helpers/derivative-storage.js.map +1 -0
  12. package/dist/test/helpers/media-config.d.ts +2 -0
  13. package/dist/test/helpers/media-config.js +16 -0
  14. package/dist/test/helpers/media-config.js.map +1 -0
  15. package/dist/test/helpers/member-rights.d.ts +99 -0
  16. package/dist/test/helpers/member-rights.js +85 -0
  17. package/dist/test/helpers/member-rights.js.map +1 -0
  18. package/dist/test/helpers/png.d.ts +1 -0
  19. package/dist/test/helpers/png.js +15 -0
  20. package/dist/test/helpers/png.js.map +1 -0
  21. package/dist/test/helpers/renderings.d.ts +27 -0
  22. package/dist/test/helpers/renderings.js +106 -0
  23. package/dist/test/helpers/renderings.js.map +1 -0
  24. package/dist/test/helpers/uploads.d.ts +26 -0
  25. package/dist/test/helpers/uploads.js +48 -0
  26. package/dist/test/helpers/uploads.js.map +1 -0
  27. package/dist/test/helpers/zip.d.ts +6 -0
  28. package/dist/test/helpers/zip.js +50 -0
  29. package/dist/test/helpers/zip.js.map +1 -0
  30. package/dist/test/integration/media-activity-overview.test.js +109 -0
  31. package/dist/test/integration/media-activity-overview.test.js.map +1 -1
  32. package/dist/test/integration/media-api.test.js +101 -0
  33. package/dist/test/integration/media-api.test.js.map +1 -1
  34. package/dist/test/integration/media-bindings.test.js +259 -0
  35. package/dist/test/integration/media-bindings.test.js.map +1 -1
  36. package/dist/test/integration/media-bulk-writes.test.d.ts +1 -0
  37. package/dist/test/integration/media-bulk-writes.test.js +159 -0
  38. package/dist/test/integration/media-bulk-writes.test.js.map +1 -0
  39. package/dist/test/integration/media-declared-rules.test.d.ts +1 -0
  40. package/dist/test/integration/media-declared-rules.test.js +297 -0
  41. package/dist/test/integration/media-declared-rules.test.js.map +1 -0
  42. package/dist/test/integration/media-declared-sources.test.d.ts +1 -0
  43. package/dist/test/integration/media-declared-sources.test.js +194 -0
  44. package/dist/test/integration/media-declared-sources.test.js.map +1 -0
  45. package/dist/test/integration/media-delivery-active-content.test.d.ts +1 -0
  46. package/dist/test/integration/media-delivery-active-content.test.js +138 -0
  47. package/dist/test/integration/media-delivery-active-content.test.js.map +1 -0
  48. package/dist/test/integration/media-delivery-editing.test.js +41 -51
  49. package/dist/test/integration/media-delivery-editing.test.js.map +1 -1
  50. package/dist/test/integration/media-delivery.test.js +145 -0
  51. package/dist/test/integration/media-delivery.test.js.map +1 -1
  52. package/dist/test/integration/media-explorer-writes.test.js +173 -18
  53. package/dist/test/integration/media-explorer-writes.test.js.map +1 -1
  54. package/dist/test/integration/media-file-reads.test.d.ts +1 -0
  55. package/dist/test/integration/media-file-reads.test.js +147 -0
  56. package/dist/test/integration/media-file-reads.test.js.map +1 -0
  57. package/dist/test/integration/media-guards.test.js +1 -0
  58. package/dist/test/integration/media-guards.test.js.map +1 -1
  59. package/dist/test/integration/media-library-views.test.d.ts +1 -0
  60. package/dist/test/integration/media-library-views.test.js +377 -0
  61. package/dist/test/integration/media-library-views.test.js.map +1 -0
  62. package/dist/test/integration/media-linked-subfolders.test.js +2 -0
  63. package/dist/test/integration/media-linked-subfolders.test.js.map +1 -1
  64. package/dist/test/integration/media-member-access.test.js +96 -0
  65. package/dist/test/integration/media-member-access.test.js.map +1 -1
  66. package/dist/test/integration/media-permissions.test.js +7 -0
  67. package/dist/test/integration/media-permissions.test.js.map +1 -1
  68. package/dist/test/integration/media-preset-delivery.test.d.ts +1 -0
  69. package/dist/test/integration/media-preset-delivery.test.js +161 -0
  70. package/dist/test/integration/media-preset-delivery.test.js.map +1 -0
  71. package/dist/test/integration/media-presets.test.d.ts +1 -0
  72. package/dist/test/integration/media-presets.test.js +223 -0
  73. package/dist/test/integration/media-presets.test.js.map +1 -0
  74. package/dist/test/integration/media-transform.test.js +105 -10
  75. package/dist/test/integration/media-transform.test.js.map +1 -1
  76. package/dist/test/integration/media-upload-content.test.d.ts +1 -0
  77. package/dist/test/integration/media-upload-content.test.js +142 -0
  78. package/dist/test/integration/media-upload-content.test.js.map +1 -0
  79. package/dist/test/integration/media-upload-policy.test.js +13 -12
  80. package/dist/test/integration/media-upload-policy.test.js.map +1 -1
  81. package/dist/test/integration/media-upload-types.test.d.ts +1 -0
  82. package/dist/test/integration/media-upload-types.test.js +176 -0
  83. package/dist/test/integration/media-upload-types.test.js.map +1 -0
  84. package/dist/test/integration/permission-levels.d.ts +1 -0
  85. package/dist/test/integration/permission-levels.js +207 -0
  86. package/dist/test/integration/permission-levels.js.map +1 -0
  87. package/dist/test/integration/permission-reach.d.ts +1 -0
  88. package/dist/test/integration/permission-reach.js +209 -0
  89. package/dist/test/integration/permission-reach.js.map +1 -0
  90. package/dist/test/integration/permissions-management.js +7 -0
  91. package/dist/test/integration/permissions-management.js.map +1 -1
  92. package/dist/test/unit/asset-type.test.d.ts +1 -0
  93. package/dist/test/unit/asset-type.test.js +63 -0
  94. package/dist/test/unit/asset-type.test.js.map +1 -0
  95. package/frontend-vue/package.json +1 -1
  96. package/frontend-vue/pnpm-lock.yaml +11 -11
  97. package/package.json +10 -8
  98. package/src/test/antelope.test.ts +1 -0
  99. package/src/test/helpers/config.ts +14 -0
  100. package/src/test/helpers/delivery.ts +83 -0
  101. package/src/test/helpers/derivative-storage.ts +25 -0
  102. package/src/test/helpers/media-config.ts +16 -0
  103. package/src/test/helpers/member-rights.ts +116 -0
  104. package/src/test/helpers/png.ts +10 -0
  105. package/src/test/helpers/renderings.ts +147 -0
  106. package/src/test/helpers/uploads.ts +92 -0
  107. package/src/test/helpers/zip.ts +62 -0
  108. package/src/test/integration/media-activity-overview.test.ts +170 -0
  109. package/src/test/integration/media-api.test.ts +135 -1
  110. package/src/test/integration/media-bindings.test.ts +316 -2
  111. package/src/test/integration/media-bulk-writes.test.ts +180 -0
  112. package/src/test/integration/media-declared-rules.test.ts +405 -0
  113. package/src/test/integration/media-declared-sources.test.ts +228 -0
  114. package/src/test/integration/media-delivery-active-content.test.ts +185 -0
  115. package/src/test/integration/media-delivery-editing.test.ts +24 -46
  116. package/src/test/integration/media-delivery.test.ts +217 -1
  117. package/src/test/integration/media-explorer-writes.test.ts +253 -23
  118. package/src/test/integration/media-file-reads.test.ts +226 -0
  119. package/src/test/integration/media-guards.test.ts +1 -0
  120. package/src/test/integration/media-library-views.test.ts +478 -0
  121. package/src/test/integration/media-linked-subfolders.test.ts +2 -0
  122. package/src/test/integration/media-member-access.test.ts +146 -0
  123. package/src/test/integration/media-permissions.test.ts +10 -1
  124. package/src/test/integration/media-preset-delivery.test.ts +261 -0
  125. package/src/test/integration/media-presets.test.ts +304 -0
  126. package/src/test/integration/media-transform.test.ts +152 -10
  127. package/src/test/integration/media-upload-content.test.ts +192 -0
  128. package/src/test/integration/media-upload-policy.test.ts +20 -18
  129. package/src/test/integration/media-upload-types.test.ts +267 -0
  130. package/src/test/integration/permission-levels.ts +332 -0
  131. package/src/test/integration/permission-reach.ts +302 -0
  132. package/src/test/integration/permissions-management.ts +7 -0
  133. package/src/test/unit/asset-type.test.ts +87 -0
@@ -4,10 +4,12 @@ import sharp from "sharp";
4
4
  import { z } from "zod";
5
5
  import { putPresigned } from "../helpers/assets";
6
6
  import { createdBody, presignBody, readBody } from "../helpers/bodies";
7
+ import { follow } from "../helpers/delivery";
7
8
  import { authorizedClient } from "../helpers/http";
8
9
  import { ensureOwnerSession } from "../helpers/owner";
9
10
 
10
11
  const HTTP_OK = 200;
12
+ const HTTP_BAD_REQUEST = 400;
11
13
  const HTTP_CONFLICT = 409;
12
14
  const HTTP_UNPROCESSABLE_ENTITY = 422;
13
15
  const IMAGE_NAME = "banner.png";
@@ -16,17 +18,32 @@ const IMAGE_HEIGHT = 10;
16
18
  const TEST_SVG =
17
19
  '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><rect width="10" height="10"/></svg>';
18
20
 
19
- async function buildTestImage(): Promise<Buffer> {
21
+ function solidImage(width: number, height: number): sharp.Sharp {
20
22
  return sharp({
21
- create: {
22
- width: IMAGE_WIDTH,
23
- height: IMAGE_HEIGHT,
24
- channels: 3,
25
- background: { r: 255, g: 0, b: 0 },
26
- },
27
- })
28
- .png()
29
- .toBuffer();
23
+ create: { width, height, channels: 3, background: { r: 255, g: 0, b: 0 } },
24
+ });
25
+ }
26
+
27
+ async function buildTestImage(): Promise<Buffer> {
28
+ return solidImage(IMAGE_WIDTH, IMAGE_HEIGHT).png().toBuffer();
29
+ }
30
+
31
+ async function storedBytes(client: AxiosInstance): Promise<number> {
32
+ const meter = await client.get("/api/media/stats/storage");
33
+ return readBody(meter, z.object({ value: z.number() })).value;
34
+ }
35
+
36
+ async function servedImage(
37
+ path: string,
38
+ token: string,
39
+ ): Promise<{ bytes: Buffer; width: number; height: number }> {
40
+ const delivered = await follow(path, { Authorization: `Bearer ${token}` });
41
+ const metadata = await sharp(delivered.body).metadata();
42
+ return {
43
+ bytes: delivered.body,
44
+ width: metadata.width ?? 0,
45
+ height: metadata.height ?? 0,
46
+ };
30
47
  }
31
48
 
32
49
  async function uploadAsset(
@@ -178,3 +195,128 @@ describe("[integration] media transform — crop, rotate, revert", () => {
178
195
  await client.post(`/api/media/assets/${assetId}/revert`);
179
196
  });
180
197
  });
198
+
199
+ describe("[integration] media transform — what the same link serves after an edit", () => {
200
+ let client: AxiosInstance;
201
+ let token: string;
202
+ let folderId: string;
203
+
204
+ before(async function () {
205
+ this.timeout(40_000);
206
+ const session = await ensureOwnerSession();
207
+ token = session.accessToken;
208
+ client = authorizedClient(token);
209
+ const folder = await client.post("/api/media/folders", {
210
+ name: "Edit contract",
211
+ });
212
+ expect(folder.status).to.equal(HTTP_OK);
213
+ folderId = readBody(folder, createdBody).id;
214
+ });
215
+
216
+ after(async () => {
217
+ await client.delete(`/api/media/folders/${folderId}`);
218
+ });
219
+
220
+ it("serves the rotated image on the same link and in its thumb, counts the original in the storage and serves it again on revert", async () => {
221
+ const landscape = await solidImage(400, 200).png().toBuffer();
222
+ const id = await uploadAsset(
223
+ client,
224
+ folderId,
225
+ landscape,
226
+ "paysage.png",
227
+ "image/png",
228
+ );
229
+ const path = `/media/${id}/paysage.png`;
230
+ const thumbPath = `/media/${id}/thumb/paysage.png`;
231
+ const thumbBefore = await servedImage(thumbPath, token);
232
+ const storageBefore = await storedBytes(client);
233
+ const rotated = await client.post(`/api/media/assets/${id}/transform`, {
234
+ rotate: 90,
235
+ });
236
+ expect(rotated.status).to.equal(HTTP_OK);
237
+ expect(rotated.data.asset.hasOriginal).to.equal(true);
238
+ const afterRotate = await servedImage(path, token);
239
+ expect([afterRotate.width, afterRotate.height]).to.deep.equal([200, 400]);
240
+ const thumbAfter = await servedImage(thumbPath, token);
241
+ expect(thumbBefore.width).to.be.greaterThan(thumbBefore.height);
242
+ expect(thumbAfter.height).to.be.greaterThan(thumbAfter.width);
243
+ expect(thumbAfter.bytes.equals(thumbBefore.bytes)).to.equal(false);
244
+ const storageAfter = await storedBytes(client);
245
+ expect(storageAfter).to.be.at.least(storageBefore + landscape.byteLength);
246
+ const cropped = await client.post(`/api/media/assets/${id}/transform`, {
247
+ crop: { x: 0, y: 0, width: 0.5, height: 1 },
248
+ });
249
+ expect(cropped.data.asset.hasOriginal).to.equal(true);
250
+ const afterCrop = await servedImage(path, token);
251
+ expect([afterCrop.width, afterCrop.height]).to.deep.equal([100, 400]);
252
+ const reverted = await client.post(`/api/media/assets/${id}/revert`);
253
+ expect(reverted.status).to.equal(HTTP_OK);
254
+ expect(reverted.data.asset.width).to.equal(400);
255
+ const afterRevert = await servedImage(path, token);
256
+ expect(afterRevert.bytes.equals(landscape)).to.equal(true);
257
+ });
258
+
259
+ it("edits JPEG, PNG, WebP and AVIF, turns by quarter steps, and refuses a GIF, a tilt or an empty request without changing the file", async () => {
260
+ const formats = ["jpeg", "png", "webp", "avif"] as const;
261
+ for (const format of formats) {
262
+ const id = await uploadAsset(
263
+ client,
264
+ folderId,
265
+ await solidImage(20, 10).toFormat(format).toBuffer(),
266
+ `x.${format}`,
267
+ `image/${format}`,
268
+ );
269
+ const answer = await client.post(`/api/media/assets/${id}/transform`, {
270
+ rotate: 90,
271
+ });
272
+ expect(answer.status, format).to.equal(HTTP_OK);
273
+ expect(answer.data.asset.width, format).to.equal(10);
274
+ }
275
+ const turned = await uploadAsset(
276
+ client,
277
+ folderId,
278
+ await solidImage(30, 10).png().toBuffer(),
279
+ "t.png",
280
+ "image/png",
281
+ );
282
+ const half = await client.post(`/api/media/assets/${turned}/transform`, {
283
+ rotate: 180,
284
+ });
285
+ expect([half.data.asset.width, half.data.asset.height]).to.deep.equal([
286
+ 30, 10,
287
+ ]);
288
+ const threeQuarters = await client.post(
289
+ `/api/media/assets/${turned}/transform`,
290
+ { rotate: 270 },
291
+ );
292
+ expect([
293
+ threeQuarters.data.asset.width,
294
+ threeQuarters.data.asset.height,
295
+ ]).to.deep.equal([10, 30]);
296
+ const gif = await uploadAsset(
297
+ client,
298
+ folderId,
299
+ await solidImage(10, 10).gif().toBuffer(),
300
+ "g.gif",
301
+ "image/gif",
302
+ );
303
+ const gifEdit = await client.post(`/api/media/assets/${gif}/transform`, {
304
+ rotate: 90,
305
+ });
306
+ expect(gifEdit.status).to.equal(HTTP_UNPROCESSABLE_ENTITY);
307
+ const untouched = await uploadAsset(
308
+ client,
309
+ folderId,
310
+ await solidImage(10, 10).png().toBuffer(),
311
+ "p.png",
312
+ "image/png",
313
+ );
314
+ const tilted = await client.post(
315
+ `/api/media/assets/${untouched}/transform`,
316
+ { rotate: 45 },
317
+ );
318
+ expect(tilted.status).to.equal(HTTP_BAD_REQUEST);
319
+ const read = await client.get(`/api/media/assets/${untouched}`);
320
+ expect(read.data.asset.hasOriginal).to.equal(false);
321
+ });
322
+ });
@@ -0,0 +1,192 @@
1
+ import type { AxiosInstance } from "axios";
2
+ import { assert, expect } from "chai";
3
+ import { FileExists } from "@antelopejs/interface-file-storage";
4
+ import sharp from "sharp";
5
+ import { z } from "zod";
6
+ import { putPresigned } from "../helpers/assets";
7
+ import { createdBody, presignBody, readBody, urlBody } from "../helpers/bodies";
8
+ import { authorizedClient } from "../helpers/http";
9
+ import { ensureOwnerSession } from "../helpers/owner";
10
+ import { confirm, expectRefusal, presign, stage } from "../helpers/uploads";
11
+
12
+ const HTTP_OK = 200;
13
+ const HTTP_BAD_REQUEST = 400;
14
+ const HTTP_UNPROCESSABLE_ENTITY = 422;
15
+ const HTTP_REDIRECT_BOUNDARY = 300;
16
+ const STAGING_PREFIX = "__staging__/";
17
+ const STORAGE_UPLOAD_PATH = "/file-storage/upload/";
18
+ const LONG_TEXT_LINES = 60_000;
19
+ const JPEG_WIDTH = 10;
20
+ const JPEG_HEIGHT = 6;
21
+ const BROKEN_IMAGE_FORMATS = ["png", "jpeg", "webp", "gif", "avif", "tiff"];
22
+
23
+ const confirmedBody = z.object({
24
+ asset: z.object({
25
+ mimetype: z.string(),
26
+ width: z.number().nullish(),
27
+ height: z.number().nullish(),
28
+ }),
29
+ });
30
+ const listedBody = z.object({
31
+ assets: z.array(
32
+ z.object({ id: z.string(), name: z.string(), size: z.number() }),
33
+ ),
34
+ });
35
+
36
+ let client: AxiosInstance;
37
+ let folderId: string;
38
+
39
+ function describeDecoding(): void {
40
+ describe("a declared image must decode", () => {
41
+ it("refuses a broken image of each decodable format and deletes its staged file", async () => {
42
+ for (const format of BROKEN_IMAGE_FORMATS) {
43
+ const filename = `broken.${format}`;
44
+ const staged = await stage(client, folderId, {
45
+ filename,
46
+ mimetype: `image/${format}`,
47
+ body: Buffer.from("not an image at all"),
48
+ });
49
+ const response = await confirm(
50
+ client,
51
+ folderId,
52
+ staged.resourceKey,
53
+ filename,
54
+ );
55
+ expectRefusal(
56
+ response,
57
+ { status: HTTP_UNPROCESSABLE_ENTITY, reason: "invalid_image" },
58
+ format,
59
+ );
60
+ expect(await FileExists(staged.resourceKey), format).to.equal(false);
61
+ }
62
+ });
63
+
64
+ it("stores the decoded type of a JPEG declared as PNG, and accepts a BMP sharp does not decode", async () => {
65
+ const jpeg = await sharp({
66
+ create: {
67
+ width: JPEG_WIDTH,
68
+ height: JPEG_HEIGHT,
69
+ channels: 3,
70
+ background: "#808080",
71
+ },
72
+ })
73
+ .jpeg()
74
+ .toBuffer();
75
+ const claimed = await stage(client, folderId, {
76
+ filename: "photo.png",
77
+ mimetype: "image/png",
78
+ body: jpeg,
79
+ });
80
+ const stored = await confirm(
81
+ client,
82
+ folderId,
83
+ claimed.resourceKey,
84
+ "photo.png",
85
+ );
86
+ expect(stored.status).to.equal(HTTP_OK);
87
+ const { asset } = readBody(stored, confirmedBody);
88
+ expect(asset.mimetype).to.equal("image/jpeg");
89
+ expect([asset.width, asset.height]).to.deep.equal([
90
+ JPEG_WIDTH,
91
+ JPEG_HEIGHT,
92
+ ]);
93
+ const bmp = await stage(client, folderId, {
94
+ filename: "old.bmp",
95
+ mimetype: "image/bmp",
96
+ body: Buffer.from("BM not decoded"),
97
+ });
98
+ const accepted = await confirm(
99
+ client,
100
+ folderId,
101
+ bmp.resourceKey,
102
+ "old.bmp",
103
+ );
104
+ expect(accepted.status).to.equal(HTTP_OK);
105
+ expect(readBody(accepted, confirmedBody).asset.mimetype).to.equal(
106
+ "image/bmp",
107
+ );
108
+ });
109
+ });
110
+ }
111
+
112
+ function describeThreeSteps(): void {
113
+ describe("the three steps of an upload", () => {
114
+ it("keeps every byte and the non-ASCII name of a multi-chunk upload, staged on the storage's own origin", async () => {
115
+ const name = "Rapport annuel — été 2026 (東京).txt";
116
+ const bytes = Buffer.from(
117
+ Array.from(
118
+ { length: LONG_TEXT_LINES },
119
+ (_, line) => `ligne ${line} — été 東京\n`,
120
+ ).join(""),
121
+ );
122
+ const presigned = await presign(
123
+ client,
124
+ folderId,
125
+ name,
126
+ "text/plain",
127
+ bytes.byteLength,
128
+ );
129
+ const target = readBody(presigned, presignBody);
130
+ expect(target.resourceKey.startsWith(STAGING_PREFIX)).to.equal(true);
131
+ expect(target.uploadUrl).to.contain(STORAGE_UPLOAD_PATH);
132
+ expect(target.uploadUrl).to.not.contain("/api/media");
133
+ const put = await putPresigned(target, bytes);
134
+ expect(put.status).to.be.lessThan(HTTP_REDIRECT_BOUNDARY);
135
+ const done = await confirm(client, folderId, target.resourceKey, name);
136
+ expect(done.status).to.equal(HTTP_OK);
137
+ const listing = await client.get(`/api/media/folders/${folderId}/assets`);
138
+ const listed = readBody(listing, listedBody).assets.find(
139
+ (asset) => asset.name === name,
140
+ );
141
+ assert.isDefined(listed);
142
+ expect(listed.size).to.equal(bytes.byteLength);
143
+ const url = await client.get(`/api/media/assets/${listed.id}/read-url`);
144
+ const read = await fetch(readBody(url, urlBody).url);
145
+ expect(Buffer.from(await read.arrayBuffer()).equals(bytes)).to.equal(
146
+ true,
147
+ );
148
+ });
149
+
150
+ it("confirms a key only in the folder it was presigned for", async () => {
151
+ const staged = await stage(client, folderId, {
152
+ filename: "other.txt",
153
+ mimetype: "text/plain",
154
+ body: Buffer.from("x"),
155
+ });
156
+ const elsewhere = readBody(
157
+ await client.post("/api/media/folders", { name: "Elsewhere" }),
158
+ createdBody,
159
+ ).id;
160
+ try {
161
+ const wrong = await confirm(
162
+ client,
163
+ elsewhere,
164
+ staged.resourceKey,
165
+ "other.txt",
166
+ );
167
+ expect(wrong.status).to.equal(HTTP_BAD_REQUEST);
168
+ } finally {
169
+ await client.delete(`/api/media/folders/${elsewhere}`);
170
+ }
171
+ });
172
+ });
173
+ }
174
+
175
+ describe("[integration] media upload content — decoding and the three steps", () => {
176
+ before(async function () {
177
+ this.timeout(40_000);
178
+ client = authorizedClient((await ensureOwnerSession()).accessToken);
179
+ const folder = await client.post("/api/media/folders", {
180
+ name: "Upload content",
181
+ });
182
+ expect(folder.status).to.equal(HTTP_OK);
183
+ folderId = readBody(folder, createdBody).id;
184
+ });
185
+
186
+ after(async () => {
187
+ await client.delete(`/api/media/folders/${folderId}`);
188
+ });
189
+
190
+ describeDecoding();
191
+ describeThreeSteps();
192
+ });
@@ -10,18 +10,16 @@ import {
10
10
  import sharp from "sharp";
11
11
  import { z } from "zod";
12
12
  import { CONTENT_ROOT_BINDING } from "../../bindings";
13
- import {
14
- configureMediaModule,
15
- type DmsMediaConfig,
16
- getMediaConfig,
17
- } from "../../config";
13
+ import { configureMediaModule, type DmsMediaConfig } from "../../config";
18
14
  import { runPurgeStaging } from "../../crons/purge-staging";
19
15
  import { MediaFolderModel } from "../../db";
20
16
  import { putPresigned, uploadAsset, uploadPixelPng } from "../helpers/assets";
21
17
  import { createdBody, presignBody, readBody } from "../helpers/bodies";
18
+ import { snapshotConfig } from "../helpers/config";
22
19
  import { fetchFolderNodes } from "../helpers/folders";
23
20
  import { authorizedClient } from "../helpers/http";
24
21
  import { ensureOwnerSession } from "../helpers/owner";
22
+ import { expectRefusal } from "../helpers/uploads";
25
23
 
26
24
  const HTTP_OK = 200;
27
25
  const HTTP_PAYLOAD_TOO_LARGE = 413;
@@ -47,18 +45,6 @@ interface StagedUpload {
47
45
  resourceKey: string;
48
46
  }
49
47
 
50
- /** The configuration in force, in the shape `configureMediaModule` takes back. */
51
- function snapshotConfig(): DmsMediaConfig {
52
- const current = getMediaConfig();
53
- return {
54
- rootAcl: current.rootAcl,
55
- storage: current.storage,
56
- presets: [...current.presets.values()],
57
- storageQuotaBytes: current.storageQuotaBytes,
58
- allowedMimetypes: [...current.allowedMimetypes],
59
- };
60
- }
61
-
62
48
  /** Bound folders are locked through the API: later suites expect an empty library. */
63
49
  async function removeLinkedFolders(): Promise<void> {
64
50
  const folderModel = GetModel(MediaFolderModel, DEFAULT_TENANT_ID);
@@ -157,7 +143,11 @@ function describeTypeRules(): void {
157
143
  expect(linked, "linked folder").to.not.equal(undefined);
158
144
  const image = await presign(linked!.id, "photo.png", "image/png");
159
145
  expect(image.status).to.equal(HTTP_UNSUPPORTED_MEDIA_TYPE);
160
- expect(image.data.reason).to.equal("field_type");
146
+ expectRefusal(
147
+ image,
148
+ { status: HTTP_UNSUPPORTED_MEDIA_TYPE, reason: "field_type" },
149
+ "photo.png",
150
+ );
161
151
  expect(image.data.accepted).to.deep.equal(["application/pdf"]);
162
152
  expect(
163
153
  (await presign(linked!.id, "sheet.pdf", "application/pdf")).status,
@@ -308,6 +298,18 @@ function describeStaging(): void {
308
298
  });
309
299
  expect(abort.status).to.equal(HTTP_OK);
310
300
  expect(await FileExists(staged.resourceKey)).to.equal(false);
301
+ const late = await client.post("/api/media/upload/confirm", {
302
+ folderId,
303
+ resourceKey: staged.resourceKey,
304
+ filename: "cancelled.txt",
305
+ });
306
+ expect(late.status).to.not.equal(HTTP_OK);
307
+ const listing = await client.get(`/api/media/folders/${folderId}/assets`);
308
+ const names = readBody(
309
+ listing,
310
+ z.object({ assets: z.array(z.object({ name: z.string() })) }),
311
+ ).assets.map((asset) => asset.name);
312
+ expect(names).to.not.include("cancelled.txt");
311
313
  });
312
314
 
313
315
  it("purges staged uploads abandoned for more than a day", async () => {