@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.
- package/dist/test/antelope.test.js +1 -0
- package/dist/test/antelope.test.js.map +1 -1
- package/dist/test/helpers/config.d.ts +2 -0
- package/dist/test/helpers/config.js +16 -0
- package/dist/test/helpers/config.js.map +1 -0
- package/dist/test/helpers/delivery.d.ts +9 -0
- package/dist/test/helpers/delivery.js +47 -0
- package/dist/test/helpers/delivery.js.map +1 -0
- package/dist/test/helpers/derivative-storage.d.ts +3 -0
- package/dist/test/helpers/derivative-storage.js +22 -0
- package/dist/test/helpers/derivative-storage.js.map +1 -0
- package/dist/test/helpers/media-config.d.ts +2 -0
- package/dist/test/helpers/media-config.js +16 -0
- package/dist/test/helpers/media-config.js.map +1 -0
- package/dist/test/helpers/member-rights.d.ts +99 -0
- package/dist/test/helpers/member-rights.js +85 -0
- package/dist/test/helpers/member-rights.js.map +1 -0
- package/dist/test/helpers/png.d.ts +1 -0
- package/dist/test/helpers/png.js +15 -0
- package/dist/test/helpers/png.js.map +1 -0
- package/dist/test/helpers/renderings.d.ts +27 -0
- package/dist/test/helpers/renderings.js +106 -0
- package/dist/test/helpers/renderings.js.map +1 -0
- package/dist/test/helpers/uploads.d.ts +26 -0
- package/dist/test/helpers/uploads.js +48 -0
- package/dist/test/helpers/uploads.js.map +1 -0
- package/dist/test/helpers/zip.d.ts +6 -0
- package/dist/test/helpers/zip.js +50 -0
- package/dist/test/helpers/zip.js.map +1 -0
- package/dist/test/integration/media-activity-overview.test.js +109 -0
- package/dist/test/integration/media-activity-overview.test.js.map +1 -1
- package/dist/test/integration/media-api.test.js +101 -0
- package/dist/test/integration/media-api.test.js.map +1 -1
- package/dist/test/integration/media-bindings.test.js +259 -0
- package/dist/test/integration/media-bindings.test.js.map +1 -1
- package/dist/test/integration/media-bulk-writes.test.d.ts +1 -0
- package/dist/test/integration/media-bulk-writes.test.js +159 -0
- package/dist/test/integration/media-bulk-writes.test.js.map +1 -0
- package/dist/test/integration/media-declared-rules.test.d.ts +1 -0
- package/dist/test/integration/media-declared-rules.test.js +297 -0
- package/dist/test/integration/media-declared-rules.test.js.map +1 -0
- package/dist/test/integration/media-declared-sources.test.d.ts +1 -0
- package/dist/test/integration/media-declared-sources.test.js +194 -0
- package/dist/test/integration/media-declared-sources.test.js.map +1 -0
- package/dist/test/integration/media-delivery-active-content.test.d.ts +1 -0
- package/dist/test/integration/media-delivery-active-content.test.js +138 -0
- package/dist/test/integration/media-delivery-active-content.test.js.map +1 -0
- package/dist/test/integration/media-delivery-editing.test.js +41 -51
- package/dist/test/integration/media-delivery-editing.test.js.map +1 -1
- package/dist/test/integration/media-delivery.test.js +145 -0
- package/dist/test/integration/media-delivery.test.js.map +1 -1
- package/dist/test/integration/media-explorer-writes.test.js +173 -18
- package/dist/test/integration/media-explorer-writes.test.js.map +1 -1
- package/dist/test/integration/media-file-reads.test.d.ts +1 -0
- package/dist/test/integration/media-file-reads.test.js +147 -0
- package/dist/test/integration/media-file-reads.test.js.map +1 -0
- package/dist/test/integration/media-guards.test.js +1 -0
- package/dist/test/integration/media-guards.test.js.map +1 -1
- package/dist/test/integration/media-library-views.test.d.ts +1 -0
- package/dist/test/integration/media-library-views.test.js +377 -0
- package/dist/test/integration/media-library-views.test.js.map +1 -0
- package/dist/test/integration/media-linked-subfolders.test.js +2 -0
- package/dist/test/integration/media-linked-subfolders.test.js.map +1 -1
- package/dist/test/integration/media-member-access.test.js +96 -0
- package/dist/test/integration/media-member-access.test.js.map +1 -1
- package/dist/test/integration/media-permissions.test.js +7 -0
- package/dist/test/integration/media-permissions.test.js.map +1 -1
- package/dist/test/integration/media-preset-delivery.test.d.ts +1 -0
- package/dist/test/integration/media-preset-delivery.test.js +161 -0
- package/dist/test/integration/media-preset-delivery.test.js.map +1 -0
- package/dist/test/integration/media-presets.test.d.ts +1 -0
- package/dist/test/integration/media-presets.test.js +223 -0
- package/dist/test/integration/media-presets.test.js.map +1 -0
- package/dist/test/integration/media-transform.test.js +105 -10
- package/dist/test/integration/media-transform.test.js.map +1 -1
- package/dist/test/integration/media-upload-content.test.d.ts +1 -0
- package/dist/test/integration/media-upload-content.test.js +142 -0
- package/dist/test/integration/media-upload-content.test.js.map +1 -0
- package/dist/test/integration/media-upload-policy.test.js +13 -12
- package/dist/test/integration/media-upload-policy.test.js.map +1 -1
- package/dist/test/integration/media-upload-types.test.d.ts +1 -0
- package/dist/test/integration/media-upload-types.test.js +176 -0
- package/dist/test/integration/media-upload-types.test.js.map +1 -0
- package/dist/test/integration/permission-levels.d.ts +1 -0
- package/dist/test/integration/permission-levels.js +207 -0
- package/dist/test/integration/permission-levels.js.map +1 -0
- package/dist/test/integration/permission-reach.d.ts +1 -0
- package/dist/test/integration/permission-reach.js +209 -0
- package/dist/test/integration/permission-reach.js.map +1 -0
- package/dist/test/integration/permissions-management.js +7 -0
- package/dist/test/integration/permissions-management.js.map +1 -1
- package/dist/test/unit/asset-type.test.d.ts +1 -0
- package/dist/test/unit/asset-type.test.js +63 -0
- package/dist/test/unit/asset-type.test.js.map +1 -0
- package/frontend-vue/package.json +1 -1
- package/frontend-vue/pnpm-lock.yaml +11 -11
- package/package.json +10 -8
- package/src/test/antelope.test.ts +1 -0
- package/src/test/helpers/config.ts +14 -0
- package/src/test/helpers/delivery.ts +83 -0
- package/src/test/helpers/derivative-storage.ts +25 -0
- package/src/test/helpers/media-config.ts +16 -0
- package/src/test/helpers/member-rights.ts +116 -0
- package/src/test/helpers/png.ts +10 -0
- package/src/test/helpers/renderings.ts +147 -0
- package/src/test/helpers/uploads.ts +92 -0
- package/src/test/helpers/zip.ts +62 -0
- package/src/test/integration/media-activity-overview.test.ts +170 -0
- package/src/test/integration/media-api.test.ts +135 -1
- package/src/test/integration/media-bindings.test.ts +316 -2
- package/src/test/integration/media-bulk-writes.test.ts +180 -0
- package/src/test/integration/media-declared-rules.test.ts +405 -0
- package/src/test/integration/media-declared-sources.test.ts +228 -0
- package/src/test/integration/media-delivery-active-content.test.ts +185 -0
- package/src/test/integration/media-delivery-editing.test.ts +24 -46
- package/src/test/integration/media-delivery.test.ts +217 -1
- package/src/test/integration/media-explorer-writes.test.ts +253 -23
- package/src/test/integration/media-file-reads.test.ts +226 -0
- package/src/test/integration/media-guards.test.ts +1 -0
- package/src/test/integration/media-library-views.test.ts +478 -0
- package/src/test/integration/media-linked-subfolders.test.ts +2 -0
- package/src/test/integration/media-member-access.test.ts +146 -0
- package/src/test/integration/media-permissions.test.ts +10 -1
- package/src/test/integration/media-preset-delivery.test.ts +261 -0
- package/src/test/integration/media-presets.test.ts +304 -0
- package/src/test/integration/media-transform.test.ts +152 -10
- package/src/test/integration/media-upload-content.test.ts +192 -0
- package/src/test/integration/media-upload-policy.test.ts +20 -18
- package/src/test/integration/media-upload-types.test.ts +267 -0
- package/src/test/integration/permission-levels.ts +332 -0
- package/src/test/integration/permission-reach.ts +302 -0
- package/src/test/integration/permissions-management.ts +7 -0
- package/src/test/unit/asset-type.test.ts +87 -0
|
@@ -9,11 +9,17 @@ import {
|
|
|
9
9
|
} from "@antelopejs/interface-dms-media";
|
|
10
10
|
import { CONTENT_ROOT_BINDING } from "../../bindings";
|
|
11
11
|
import { MediaEventModel, MediaFolderModel } from "../../db";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
uploadAsset,
|
|
14
|
+
uploadPixelPng,
|
|
15
|
+
uploadTextAsset,
|
|
16
|
+
} from "../helpers/assets";
|
|
13
17
|
import { createdBody, readBody } from "../helpers/bodies";
|
|
14
18
|
import { fetchFolderNodes } from "../helpers/folders";
|
|
15
19
|
import { authorizedClient } from "../helpers/http";
|
|
16
20
|
import { ensureOwnerSession } from "../helpers/owner";
|
|
21
|
+
import { solidPng } from "../helpers/png";
|
|
22
|
+
import { readZip } from "../helpers/zip";
|
|
17
23
|
|
|
18
24
|
const HTTP_OK = 200;
|
|
19
25
|
const HTTP_BAD_REQUEST = 400;
|
|
@@ -22,31 +28,42 @@ const HTTP_NOT_FOUND = 404;
|
|
|
22
28
|
const HTTP_CONFLICT = 409;
|
|
23
29
|
const BINDING_ID = "explorer.linked";
|
|
24
30
|
const ERRORS = "$dms_media.errors";
|
|
25
|
-
const CENTRAL_DIRECTORY_SIGNATURE = 0x02014b50;
|
|
26
|
-
const CENTRAL_NAME_LENGTH_OFFSET = 28;
|
|
27
|
-
const CENTRAL_EXTRA_LENGTH_OFFSET = 30;
|
|
28
|
-
const CENTRAL_COMMENT_LENGTH_OFFSET = 32;
|
|
29
|
-
const CENTRAL_HEADER_SIZE = 46;
|
|
30
31
|
const ALT_LIMIT = 255;
|
|
32
|
+
const NAME_LIMIT = 255;
|
|
33
|
+
const ZIP_FILE_LIMIT = 200;
|
|
34
|
+
const HTTP_PAYLOAD_TOO_LARGE = 413;
|
|
35
|
+
const UPLOAD_BATCH = 20;
|
|
36
|
+
const NFD_SUMMER = "Été".normalize("NFD");
|
|
37
|
+
|
|
38
|
+
function textLines(count: number): Buffer {
|
|
39
|
+
return Buffer.from(
|
|
40
|
+
Array.from(
|
|
41
|
+
{ length: count },
|
|
42
|
+
(_, index) => `ligne ${index} — été 東京`,
|
|
43
|
+
).join("\n"),
|
|
44
|
+
);
|
|
45
|
+
}
|
|
31
46
|
|
|
32
|
-
/**
|
|
33
|
-
function
|
|
34
|
-
const
|
|
35
|
-
let
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
/** Uploads `count` small text files into a folder, a few at a time, and answers their ids. */
|
|
48
|
+
async function uploadMany(folderId: string, count: number): Promise<string[]> {
|
|
49
|
+
const ids: string[] = [];
|
|
50
|
+
for (let first = 0; first < count; first += UPLOAD_BATCH) {
|
|
51
|
+
const batch = await Promise.all(
|
|
52
|
+
Array.from(
|
|
53
|
+
{ length: Math.min(UPLOAD_BATCH, count - first) },
|
|
54
|
+
(_, offset) =>
|
|
55
|
+
uploadAsset(
|
|
56
|
+
client,
|
|
57
|
+
folderId,
|
|
58
|
+
`f${first + offset}.txt`,
|
|
59
|
+
"text/plain",
|
|
60
|
+
Buffer.from(String(first + offset)),
|
|
61
|
+
),
|
|
62
|
+
),
|
|
44
63
|
);
|
|
45
|
-
|
|
46
|
-
names.push(zip.subarray(start, start + nameLength).toString("utf8"));
|
|
47
|
-
offset = start + nameLength + extraLength + commentLength;
|
|
64
|
+
ids.push(...batch.map((asset) => asset.id));
|
|
48
65
|
}
|
|
49
|
-
return
|
|
66
|
+
return ids;
|
|
50
67
|
}
|
|
51
68
|
|
|
52
69
|
async function removeLinkedFolders(): Promise<void> {
|
|
@@ -66,6 +83,18 @@ let client: AxiosInstance;
|
|
|
66
83
|
let rootId: string;
|
|
67
84
|
let otherId: string;
|
|
68
85
|
|
|
86
|
+
async function folderIdOf(name: string, parentId?: string): Promise<string> {
|
|
87
|
+
const created = await client.post("/api/media/folders", { name, parentId });
|
|
88
|
+
expect(created.status, name).to.equal(HTTP_OK);
|
|
89
|
+
return readBody(created, createdBody).id;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function removeFolder(folderId: string): Promise<void> {
|
|
93
|
+
expect(
|
|
94
|
+
(await client.delete(`/api/media/folders/${folderId}`)).status,
|
|
95
|
+
).to.equal(HTTP_OK);
|
|
96
|
+
}
|
|
97
|
+
|
|
69
98
|
function describeFolderNames(): void {
|
|
70
99
|
describe("folder names and linked folders", () => {
|
|
71
100
|
it("refuses a sibling folder name whatever its case, with a translatable message", async () => {
|
|
@@ -86,6 +115,63 @@ function describeFolderNames(): void {
|
|
|
86
115
|
expect(created.data).to.equal(`${ERRORS}.name_forbidden`);
|
|
87
116
|
});
|
|
88
117
|
|
|
118
|
+
it("refuses a sibling name taken ignoring case and Unicode form on create, rename and move, and allows it in another folder", async () => {
|
|
119
|
+
const parent = await folderIdOf("Unicode siblings", rootId);
|
|
120
|
+
await folderIdOf("Été", parent);
|
|
121
|
+
for (const name of ["ÉTÉ", NFD_SUMMER]) {
|
|
122
|
+
const twin = await client.post("/api/media/folders", {
|
|
123
|
+
name,
|
|
124
|
+
parentId: parent,
|
|
125
|
+
});
|
|
126
|
+
expect(twin.status, name).to.equal(HTTP_CONFLICT);
|
|
127
|
+
expect(twin.data, name).to.equal(`${ERRORS}.folder_name_taken`);
|
|
128
|
+
}
|
|
129
|
+
const winter = await folderIdOf("Hiver", parent);
|
|
130
|
+
const rename = await client.post(`/api/media/folders/${winter}/rename`, {
|
|
131
|
+
name: "été",
|
|
132
|
+
});
|
|
133
|
+
expect(rename.status).to.equal(HTTP_CONFLICT);
|
|
134
|
+
expect(rename.data).to.equal(`${ERRORS}.folder_name_taken`);
|
|
135
|
+
const elsewhere = await folderIdOf("Été");
|
|
136
|
+
try {
|
|
137
|
+
const move = await client.post(`/api/media/folders/${elsewhere}/move`, {
|
|
138
|
+
parentId: parent,
|
|
139
|
+
});
|
|
140
|
+
expect(move.status).to.equal(HTTP_CONFLICT);
|
|
141
|
+
} finally {
|
|
142
|
+
await removeFolder(elsewhere);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("refuses every name Windows or macOS cannot save with an error key, and keeps a name of 255 characters", async () => {
|
|
147
|
+
const forbidden = [
|
|
148
|
+
"a/b",
|
|
149
|
+
"a\\b",
|
|
150
|
+
"a<b",
|
|
151
|
+
"a>b",
|
|
152
|
+
"a:b",
|
|
153
|
+
'a"b',
|
|
154
|
+
"a|b",
|
|
155
|
+
"a?b",
|
|
156
|
+
"a*b",
|
|
157
|
+
"a\u0001b",
|
|
158
|
+
"x".repeat(NAME_LIMIT + 1),
|
|
159
|
+
" ",
|
|
160
|
+
];
|
|
161
|
+
for (const name of forbidden) {
|
|
162
|
+
const created = await client.post("/api/media/folders", {
|
|
163
|
+
name,
|
|
164
|
+
parentId: rootId,
|
|
165
|
+
});
|
|
166
|
+
const label = JSON.stringify(name.slice(0, 20));
|
|
167
|
+
expect(created.status, label).to.equal(HTTP_BAD_REQUEST);
|
|
168
|
+
expect(created.data, label).to.match(/^\$dms_media\.errors\./);
|
|
169
|
+
}
|
|
170
|
+
const longest = `${"y".repeat(NAME_LIMIT - " été".length)} été`;
|
|
171
|
+
expect(longest).to.have.length(NAME_LIMIT);
|
|
172
|
+
await folderIdOf(longest, rootId);
|
|
173
|
+
});
|
|
174
|
+
|
|
89
175
|
it("records the created folder's id on its activity event", async () => {
|
|
90
176
|
const created = await client.post("/api/media/folders", {
|
|
91
177
|
name: "Traced",
|
|
@@ -172,6 +258,37 @@ function describeFileNames(): void {
|
|
|
172
258
|
await client.delete(`/api/media/assets/${mover.id}`);
|
|
173
259
|
});
|
|
174
260
|
|
|
261
|
+
it("refuses a file name taken ignoring Unicode form, and reads back a name, an alt and an alt of 255 characters", async () => {
|
|
262
|
+
const folder = await folderIdOf("File names", rootId);
|
|
263
|
+
await uploadTextAsset(client, folder, "Été.txt");
|
|
264
|
+
const file = await uploadTextAsset(client, folder, "a.txt");
|
|
265
|
+
const update = (body: Record<string, string>) =>
|
|
266
|
+
client.post(`/api/media/assets/${file.id}/update`, body);
|
|
267
|
+
const taken = await update({ name: "ÉTÉ.txt" });
|
|
268
|
+
expect(taken.status).to.equal(HTTP_CONFLICT);
|
|
269
|
+
expect(taken.data).to.equal(`${ERRORS}.name_taken`);
|
|
270
|
+
const alt = "Un toit au soleil, 東京";
|
|
271
|
+
expect((await update({ name: "b é.txt", alt })).status).to.equal(HTTP_OK);
|
|
272
|
+
const read = await client.get(`/api/media/assets/${file.id}`);
|
|
273
|
+
expect(read.data.asset).to.include({ name: "b é.txt", alt });
|
|
274
|
+
expect((await update({ alt: "a".repeat(ALT_LIMIT) })).status).to.equal(
|
|
275
|
+
HTTP_OK,
|
|
276
|
+
);
|
|
277
|
+
const longest = await client.get(`/api/media/assets/${file.id}`);
|
|
278
|
+
expect(longest.data.asset.alt).to.have.length(ALT_LIMIT);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it("refuses a file name Windows or macOS cannot save, like a folder name", async () => {
|
|
282
|
+
const file = await uploadTextAsset(client, rootId, "portable.txt");
|
|
283
|
+
const update = (name: string) =>
|
|
284
|
+
client.post(`/api/media/assets/${file.id}/update`, { name });
|
|
285
|
+
expect((await update("a:b?.txt")).status).to.equal(HTTP_BAD_REQUEST);
|
|
286
|
+
const slash = await update("a/b.txt");
|
|
287
|
+
expect(slash.status).to.equal(HTTP_BAD_REQUEST);
|
|
288
|
+
expect(slash.data).to.equal(`${ERRORS}.name_forbidden`);
|
|
289
|
+
await client.delete(`/api/media/assets/${file.id}`);
|
|
290
|
+
});
|
|
291
|
+
|
|
175
292
|
it("answers validation errors with i18n keys instead of zod dumps", async () => {
|
|
176
293
|
const asset = await uploadPixelPng(client, rootId);
|
|
177
294
|
const tooLong = await client.post(
|
|
@@ -200,6 +317,80 @@ function describeFileNames(): void {
|
|
|
200
317
|
|
|
201
318
|
function describeZip(): void {
|
|
202
319
|
describe("folder zip", () => {
|
|
320
|
+
it("zips a selection as media.zip and a folder under its own name, every byte of each file kept", async () => {
|
|
321
|
+
const folder = await folderIdOf("Été 2026");
|
|
322
|
+
try {
|
|
323
|
+
const sub = await folderIdOf("Sous-dossier", folder);
|
|
324
|
+
const notes = textLines(20_000);
|
|
325
|
+
const png = await solidPng(30, 30);
|
|
326
|
+
const first = await uploadAsset(
|
|
327
|
+
client,
|
|
328
|
+
folder,
|
|
329
|
+
"notes été.txt",
|
|
330
|
+
"text/plain",
|
|
331
|
+
notes,
|
|
332
|
+
);
|
|
333
|
+
const second = await uploadAsset(
|
|
334
|
+
client,
|
|
335
|
+
sub,
|
|
336
|
+
"image.png",
|
|
337
|
+
"image/png",
|
|
338
|
+
png,
|
|
339
|
+
);
|
|
340
|
+
const selection = await client.post(
|
|
341
|
+
"/api/media/assets/zip",
|
|
342
|
+
{ ids: [first.id, second.id] },
|
|
343
|
+
{ responseType: "arraybuffer" },
|
|
344
|
+
);
|
|
345
|
+
expect(selection.status).to.equal(HTTP_OK);
|
|
346
|
+
expect(selection.headers["content-type"]).to.match(/^application\/zip/);
|
|
347
|
+
expect(selection.headers["content-disposition"]).to.contain(
|
|
348
|
+
'filename="media.zip"',
|
|
349
|
+
);
|
|
350
|
+
const selected = readZip(readBody(selection, z.instanceof(Buffer)));
|
|
351
|
+
expect(selected.map((entry) => entry.name).sort()).to.deep.equal([
|
|
352
|
+
"image.png",
|
|
353
|
+
"notes été.txt",
|
|
354
|
+
]);
|
|
355
|
+
expect(
|
|
356
|
+
selected
|
|
357
|
+
.find((entry) => entry.name === "notes été.txt")
|
|
358
|
+
?.bytes.equals(notes),
|
|
359
|
+
).to.equal(true);
|
|
360
|
+
expect(
|
|
361
|
+
selected
|
|
362
|
+
.find((entry) => entry.name === "image.png")
|
|
363
|
+
?.bytes.equals(png),
|
|
364
|
+
).to.equal(true);
|
|
365
|
+
|
|
366
|
+
const whole = await client.post(
|
|
367
|
+
`/api/media/folders/${folder}/zip`,
|
|
368
|
+
undefined,
|
|
369
|
+
{ responseType: "arraybuffer" },
|
|
370
|
+
);
|
|
371
|
+
expect(whole.headers["content-disposition"]).to.contain(
|
|
372
|
+
`filename*=UTF-8''${encodeURIComponent("Été 2026.zip")}`,
|
|
373
|
+
);
|
|
374
|
+
const entries = readZip(readBody(whole, z.instanceof(Buffer)));
|
|
375
|
+
expect(entries.map((entry) => entry.name).sort()).to.deep.equal([
|
|
376
|
+
"Sous-dossier/image.png",
|
|
377
|
+
"notes été.txt",
|
|
378
|
+
]);
|
|
379
|
+
expect(
|
|
380
|
+
entries
|
|
381
|
+
.find((entry) => entry.name === "Sous-dossier/image.png")
|
|
382
|
+
?.bytes.equals(png),
|
|
383
|
+
).to.equal(true);
|
|
384
|
+
expect(
|
|
385
|
+
entries
|
|
386
|
+
.find((entry) => entry.name === "notes été.txt")
|
|
387
|
+
?.bytes.equals(notes),
|
|
388
|
+
).to.equal(true);
|
|
389
|
+
} finally {
|
|
390
|
+
await removeFolder(folder);
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
|
|
203
394
|
it("zips a folder with its subfolders under portable names", async () => {
|
|
204
395
|
const zipped = await client.post(
|
|
205
396
|
`/api/media/folders/${rootId}/zip`,
|
|
@@ -212,7 +403,9 @@ function describeZip(): void {
|
|
|
212
403
|
expect(zipped.headers["content-disposition"]).to.contain(
|
|
213
404
|
"Explorer writes.zip",
|
|
214
405
|
);
|
|
215
|
-
const names =
|
|
406
|
+
const names = readZip(readBody(zipped, z.instanceof(Buffer))).map(
|
|
407
|
+
(entry) => entry.name,
|
|
408
|
+
);
|
|
216
409
|
expect(names).to.include.members([
|
|
217
410
|
"Notes.txt",
|
|
218
411
|
"other.txt",
|
|
@@ -222,6 +415,42 @@ function describeZip(): void {
|
|
|
222
415
|
});
|
|
223
416
|
}
|
|
224
417
|
|
|
418
|
+
function describeZipLimits(): void {
|
|
419
|
+
describe("zip limits", () => {
|
|
420
|
+
it("zips at most 200 files, and lists 500 files in one page", async function () {
|
|
421
|
+
this.timeout(180_000);
|
|
422
|
+
const many = await folderIdOf("Many files");
|
|
423
|
+
try {
|
|
424
|
+
const ids = await uploadMany(many, ZIP_FILE_LIMIT + 1);
|
|
425
|
+
const zipIds = (selection: string[]) =>
|
|
426
|
+
client.post(
|
|
427
|
+
"/api/media/assets/zip",
|
|
428
|
+
{ ids: selection },
|
|
429
|
+
{ responseType: "arraybuffer" },
|
|
430
|
+
);
|
|
431
|
+
expect((await zipIds(ids)).status).to.equal(HTTP_PAYLOAD_TOO_LARGE);
|
|
432
|
+
const atMost = await zipIds(ids.slice(0, ZIP_FILE_LIMIT));
|
|
433
|
+
expect(atMost.status).to.equal(HTTP_OK);
|
|
434
|
+
expect(readZip(readBody(atMost, z.instanceof(Buffer)))).to.have.length(
|
|
435
|
+
ZIP_FILE_LIMIT,
|
|
436
|
+
);
|
|
437
|
+
const folderZip = await client.post(
|
|
438
|
+
`/api/media/folders/${many}/zip`,
|
|
439
|
+
undefined,
|
|
440
|
+
{ responseType: "arraybuffer" },
|
|
441
|
+
);
|
|
442
|
+
expect(folderZip.status).to.equal(HTTP_PAYLOAD_TOO_LARGE);
|
|
443
|
+
const listing = await client.get(`/api/media/folders/${many}/assets`, {
|
|
444
|
+
params: { limit: 500 },
|
|
445
|
+
});
|
|
446
|
+
expect(listing.data.assets).to.have.length(ZIP_FILE_LIMIT + 1);
|
|
447
|
+
} finally {
|
|
448
|
+
await removeFolder(many);
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
|
|
225
454
|
describe("[integration] media explorer writes — names, linked folders, zips", () => {
|
|
226
455
|
before(async () => {
|
|
227
456
|
RegisterAssetBinding({ id: BINDING_ID, folderName: "Explorer linked" });
|
|
@@ -247,4 +476,5 @@ describe("[integration] media explorer writes — names, linked folders, zips",
|
|
|
247
476
|
describeFolderNames();
|
|
248
477
|
describeFileNames();
|
|
249
478
|
describeZip();
|
|
479
|
+
describeZipLimits();
|
|
250
480
|
});
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import type { AxiosInstance } from "axios";
|
|
2
|
+
import { expect } from "chai";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { PNG_MIMETYPE, uploadAsset } from "../helpers/assets";
|
|
5
|
+
import { createdBody, readBody, urlBody } from "../helpers/bodies";
|
|
6
|
+
import { signedLifetimeSeconds } from "../helpers/delivery";
|
|
7
|
+
import { authorizedClient, getBaseUrl } from "../helpers/http";
|
|
8
|
+
import { withMediaConfig } from "../helpers/media-config";
|
|
9
|
+
import { ensureOwnerSession } from "../helpers/owner";
|
|
10
|
+
import { solidPng } from "../helpers/png";
|
|
11
|
+
|
|
12
|
+
const HTTP_OK = 200;
|
|
13
|
+
const CDN = "https://cdn.example.org";
|
|
14
|
+
const DMS_ORIGIN = "http://127.0.0.1:5010";
|
|
15
|
+
|
|
16
|
+
const deliveryBody = z.object({
|
|
17
|
+
items: z.array(
|
|
18
|
+
z.object({ id: z.string(), copyValue: z.string().optional() }),
|
|
19
|
+
),
|
|
20
|
+
});
|
|
21
|
+
const previewsBody = z.object({ previews: z.record(z.unknown()) });
|
|
22
|
+
const historyBody = z.object({
|
|
23
|
+
items: z.array(z.object({ title: z.string() })),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
let client: AxiosInstance;
|
|
27
|
+
|
|
28
|
+
async function scratchFolder(name: string): Promise<string> {
|
|
29
|
+
const created = await client.post("/api/media/folders", { name });
|
|
30
|
+
expect(created.status, name).to.equal(HTTP_OK);
|
|
31
|
+
return readBody(created, createdBody).id;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function describeReadUrls(): void {
|
|
35
|
+
describe("read URLs, previews and asset search", () => {
|
|
36
|
+
it("serves a read URL of five minutes for the original and a size, previews images only, and searches by name and type", async () => {
|
|
37
|
+
const folder = await scratchFolder("Read URLs");
|
|
38
|
+
try {
|
|
39
|
+
const bytes = await solidPng(500, 400);
|
|
40
|
+
const photo = await uploadAsset(
|
|
41
|
+
client,
|
|
42
|
+
folder,
|
|
43
|
+
"Toiture été.png",
|
|
44
|
+
PNG_MIMETYPE,
|
|
45
|
+
bytes,
|
|
46
|
+
);
|
|
47
|
+
const document = await uploadAsset(
|
|
48
|
+
client,
|
|
49
|
+
folder,
|
|
50
|
+
"toiture.pdf",
|
|
51
|
+
"application/pdf",
|
|
52
|
+
Buffer.from("%PDF-1.4\n%%EOF\n"),
|
|
53
|
+
);
|
|
54
|
+
const original = readBody(
|
|
55
|
+
await client.get(`/api/media/assets/${photo.id}/read-url`),
|
|
56
|
+
urlBody,
|
|
57
|
+
).url;
|
|
58
|
+
const thumb = readBody(
|
|
59
|
+
await client.get(`/api/media/assets/${photo.id}/read-url`, {
|
|
60
|
+
params: { preset: "thumb" },
|
|
61
|
+
}),
|
|
62
|
+
urlBody,
|
|
63
|
+
).url;
|
|
64
|
+
for (const url of [original, thumb]) {
|
|
65
|
+
const lifetime = await signedLifetimeSeconds(url);
|
|
66
|
+
expect(lifetime).to.be.within(241, 300);
|
|
67
|
+
}
|
|
68
|
+
const served = await fetch(new URL(original, getBaseUrl()));
|
|
69
|
+
expect(Buffer.from(await served.arrayBuffer()).equals(bytes)).to.equal(
|
|
70
|
+
true,
|
|
71
|
+
);
|
|
72
|
+
const rendered = await fetch(new URL(thumb, getBaseUrl()));
|
|
73
|
+
expect(rendered.status).to.equal(HTTP_OK);
|
|
74
|
+
const renderedBytes = Buffer.from(await rendered.arrayBuffer());
|
|
75
|
+
expect(renderedBytes.byteLength).to.be.greaterThan(0);
|
|
76
|
+
expect(renderedBytes.equals(bytes)).to.equal(false);
|
|
77
|
+
|
|
78
|
+
const previews = await client.get(
|
|
79
|
+
`/api/media/previews?ids=${photo.id}&ids=${document.id}`,
|
|
80
|
+
);
|
|
81
|
+
expect(
|
|
82
|
+
Object.keys(readBody(previews, previewsBody).previews),
|
|
83
|
+
).to.deep.equal([photo.id]);
|
|
84
|
+
|
|
85
|
+
const search = await client.get("/api/media/assets/search", {
|
|
86
|
+
params: { q: "toiture", mime: "application/", folderId: folder },
|
|
87
|
+
});
|
|
88
|
+
expect(
|
|
89
|
+
readBody(
|
|
90
|
+
search,
|
|
91
|
+
z.object({ assets: z.array(createdBody) }),
|
|
92
|
+
).assets.map((asset) => asset.id),
|
|
93
|
+
).to.deep.equal([document.id]);
|
|
94
|
+
} finally {
|
|
95
|
+
await client.delete(`/api/media/folders/${folder}`);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function describeFileTabs(): void {
|
|
102
|
+
describe("file tabs and delivery link origin", () => {
|
|
103
|
+
async function linksOf(assetId: string) {
|
|
104
|
+
const origin = z
|
|
105
|
+
.object({ origin: z.string() })
|
|
106
|
+
.parse((await client.get("/api/media/links/origin")).data).origin;
|
|
107
|
+
const delivery = readBody(
|
|
108
|
+
await client.get(`/api/media/assets/${assetId}/delivery`),
|
|
109
|
+
deliveryBody,
|
|
110
|
+
).items;
|
|
111
|
+
const presets = readBody(
|
|
112
|
+
await client.get("/api/media/presets"),
|
|
113
|
+
z.object({
|
|
114
|
+
presets: z.array(
|
|
115
|
+
z.object({ id: z.string(), exampleUrl: z.string().nullable() }),
|
|
116
|
+
),
|
|
117
|
+
}),
|
|
118
|
+
).presets;
|
|
119
|
+
return {
|
|
120
|
+
origin,
|
|
121
|
+
copy: Object.fromEntries(
|
|
122
|
+
delivery.map((item) => [item.id, item.copyValue]),
|
|
123
|
+
),
|
|
124
|
+
example: presets.find((preset) => preset.id === "thumb")?.exampleUrl,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
it("reads a renamed file's details and history, with delivery links on the public origin for the original and each size", async () => {
|
|
129
|
+
const folder = await scratchFolder("File tabs");
|
|
130
|
+
try {
|
|
131
|
+
const photo = await uploadAsset(
|
|
132
|
+
client,
|
|
133
|
+
folder,
|
|
134
|
+
"onglets.png",
|
|
135
|
+
PNG_MIMETYPE,
|
|
136
|
+
await solidPng(40, 30),
|
|
137
|
+
);
|
|
138
|
+
await client.post(`/api/media/assets/${photo.id}/update`, {
|
|
139
|
+
name: "onglets 2.png",
|
|
140
|
+
});
|
|
141
|
+
const { origin, copy } = await linksOf(photo.id);
|
|
142
|
+
expect(origin).to.equal(DMS_ORIGIN);
|
|
143
|
+
const details = await client.get(
|
|
144
|
+
`/api/media/assets/${photo.id}/details`,
|
|
145
|
+
);
|
|
146
|
+
expect(details.data.asset.name).to.equal("onglets 2.png");
|
|
147
|
+
const history = readBody(
|
|
148
|
+
await client.get(`/api/media/assets/${photo.id}/history`),
|
|
149
|
+
historyBody,
|
|
150
|
+
);
|
|
151
|
+
expect(history.items.map((item) => item.title)).to.deep.equal([
|
|
152
|
+
"$dms_media.activity.asset_rename",
|
|
153
|
+
"$dms_media.activity.asset_upload",
|
|
154
|
+
]);
|
|
155
|
+
expect(copy.stable).to.equal(
|
|
156
|
+
`${origin}/media/${photo.id}/${encodeURIComponent("onglets 2.png")}`,
|
|
157
|
+
);
|
|
158
|
+
expect(copy.thumb).to.satisfy((link: string) =>
|
|
159
|
+
link.startsWith(`${origin}/media/${photo.id}/thumb/`),
|
|
160
|
+
);
|
|
161
|
+
expect(copy.preview).to.satisfy((link: string) =>
|
|
162
|
+
link.startsWith(`${origin}/media/${photo.id}/preview/`),
|
|
163
|
+
);
|
|
164
|
+
} finally {
|
|
165
|
+
await client.delete(`/api/media/folders/${folder}`);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("starts every copied link with the configured public URL, never with a request header, and drops trailing slashes", async () => {
|
|
170
|
+
const folder = await scratchFolder("Link origin");
|
|
171
|
+
try {
|
|
172
|
+
const photo = await uploadAsset(
|
|
173
|
+
client,
|
|
174
|
+
folder,
|
|
175
|
+
"lien.png",
|
|
176
|
+
PNG_MIMETYPE,
|
|
177
|
+
await solidPng(20, 20),
|
|
178
|
+
);
|
|
179
|
+
await client.post(`/api/media/assets/${photo.id}/visibility`, {
|
|
180
|
+
visibility: "public",
|
|
181
|
+
});
|
|
182
|
+
const fallback = await linksOf(photo.id);
|
|
183
|
+
expect(fallback.origin).to.equal(DMS_ORIGIN);
|
|
184
|
+
expect(fallback.copy.stable).to.equal(
|
|
185
|
+
`${DMS_ORIGIN}/media/${photo.id}/lien.png`,
|
|
186
|
+
);
|
|
187
|
+
expect(fallback.example).to.satisfy((link: string) =>
|
|
188
|
+
link.startsWith(`${DMS_ORIGIN}/media/`),
|
|
189
|
+
);
|
|
190
|
+
const forwarded = await client.get("/api/media/links/origin", {
|
|
191
|
+
headers: {
|
|
192
|
+
"x-forwarded-host": "evil.example.org",
|
|
193
|
+
"x-forwarded-proto": "https",
|
|
194
|
+
host: "evil.example.org",
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
expect(forwarded.data.origin).to.equal(DMS_ORIGIN);
|
|
198
|
+
for (const configured of [CDN, `${CDN}//`]) {
|
|
199
|
+
await withMediaConfig({ publicBaseUrl: configured }, async () => {
|
|
200
|
+
const seen = await linksOf(photo.id);
|
|
201
|
+
expect(seen.origin, configured).to.equal(CDN);
|
|
202
|
+
expect(seen.copy.stable, configured).to.equal(
|
|
203
|
+
`${CDN}/media/${photo.id}/lien.png`,
|
|
204
|
+
);
|
|
205
|
+
expect(seen.example, configured).to.satisfy((link: string) =>
|
|
206
|
+
link.startsWith(`${CDN}/media/`),
|
|
207
|
+
);
|
|
208
|
+
expect(JSON.stringify(seen), configured).not.to.contain("//media");
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
} finally {
|
|
212
|
+
await client.delete(`/api/media/folders/${folder}`);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
describe("[integration] media file reads — read URLs, tabs and link origin", () => {
|
|
219
|
+
before(async function () {
|
|
220
|
+
this.timeout(30_000);
|
|
221
|
+
client = authorizedClient((await ensureOwnerSession()).accessToken);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
describeReadUrls();
|
|
225
|
+
describeFileTabs();
|
|
226
|
+
});
|
|
@@ -16,6 +16,7 @@ function anonymousAttempts(anonymous: AxiosInstance): Promise<AxiosResponse>[] {
|
|
|
16
16
|
anonymous.get("/api/media/tree"),
|
|
17
17
|
anonymous.get("/api/media/assets"),
|
|
18
18
|
anonymous.get("/api/media/assets/search?q=x"),
|
|
19
|
+
anonymous.get("/api/media/search?q=x"),
|
|
19
20
|
anonymous.get("/api/media/assets/any"),
|
|
20
21
|
anonymous.get("/api/media/assets/any/read-url"),
|
|
21
22
|
anonymous.post("/api/media/assets/any/update", { alt: "x" }),
|