@antelopejs/dms-media 0.7.0 → 0.7.1
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/README.md +17 -23
- package/dist/acl/entries.js +2 -1
- package/dist/acl/entries.js.map +1 -1
- package/dist/asset-lifecycle.js.map +1 -1
- package/dist/db/models/mediaAssets.model.d.ts +7 -5
- package/dist/db/models/mediaDeclarations.model.d.ts +7 -5
- package/dist/db/models/mediaEvents.model.d.ts +7 -5
- package/dist/db/models/mediaFavorites.model.d.ts +7 -5
- package/dist/db/models/mediaFolders.model.d.ts +7 -5
- package/dist/db/models/mediaUploads.model.d.ts +7 -5
- package/dist/declared/assets.js +2 -5
- package/dist/declared/assets.js.map +1 -1
- package/dist/declared/records.d.ts +2 -1
- package/dist/declared/records.js.map +1 -1
- package/dist/library/activity.js +2 -1
- package/dist/library/activity.js.map +1 -1
- package/dist/routes/media/manage.js +2 -2
- package/dist/routes/media/manage.js.map +1 -1
- package/dist/routes/media/storage-keys.js.map +1 -1
- package/dist/test/antelope.test.js +7 -5
- package/dist/test/antelope.test.js.map +1 -1
- package/dist/test/helpers/assets.d.ts +24 -5
- package/dist/test/helpers/assets.js +22 -7
- package/dist/test/helpers/assets.js.map +1 -1
- package/dist/test/helpers/bodies.d.ts +31 -0
- package/dist/test/helpers/bodies.js +16 -0
- package/dist/test/helpers/bodies.js.map +1 -0
- package/dist/test/helpers/folders.d.ts +50 -0
- package/dist/test/helpers/folders.js +4 -2
- package/dist/test/helpers/folders.js.map +1 -1
- package/dist/test/helpers/members.js +10 -3
- package/dist/test/helpers/members.js.map +1 -1
- package/dist/test/helpers/owner.js +6 -1
- package/dist/test/helpers/owner.js.map +1 -1
- package/dist/test/helpers/permissions-world.d.ts +132 -11
- package/dist/test/helpers/permissions-world.js +21 -2
- package/dist/test/helpers/permissions-world.js.map +1 -1
- package/dist/test/helpers/setup-token.d.ts +1 -0
- package/dist/test/helpers/setup-token.js +5 -0
- package/dist/test/helpers/setup-token.js.map +1 -0
- package/dist/test/integration/derivative-sweep-query.test.js +1 -2
- package/dist/test/integration/derivative-sweep-query.test.js.map +1 -1
- package/dist/test/integration/folder-cascade.test.js +3 -1
- package/dist/test/integration/folder-cascade.test.js.map +1 -1
- package/dist/test/integration/media-activity-overview.test.js +39 -12
- package/dist/test/integration/media-activity-overview.test.js.map +1 -1
- package/dist/test/integration/media-api.test.js +22 -21
- package/dist/test/integration/media-api.test.js.map +1 -1
- package/dist/test/integration/media-bindings.test.js +6 -5
- package/dist/test/integration/media-bindings.test.js.map +1 -1
- package/dist/test/integration/media-declared-content.test.js +2 -1
- package/dist/test/integration/media-declared-content.test.js.map +1 -1
- package/dist/test/integration/media-delivery-editing.test.js +12 -2
- package/dist/test/integration/media-delivery-editing.test.js.map +1 -1
- package/dist/test/integration/media-delivery.test.js +5 -3
- package/dist/test/integration/media-delivery.test.js.map +1 -1
- package/dist/test/integration/media-explorer-writes.test.js +6 -4
- package/dist/test/integration/media-explorer-writes.test.js.map +1 -1
- package/dist/test/integration/media-guards.test.js +11 -16
- package/dist/test/integration/media-guards.test.js.map +1 -1
- package/dist/test/integration/media-library.test.js +73 -23
- package/dist/test/integration/media-library.test.js.map +1 -1
- package/dist/test/integration/media-linked-subfolders.test.js +3 -2
- package/dist/test/integration/media-linked-subfolders.test.js.map +1 -1
- package/dist/test/integration/media-member-access.test.js +18 -2
- package/dist/test/integration/media-member-access.test.js.map +1 -1
- package/dist/test/integration/media-permissions.test.js +7 -2
- package/dist/test/integration/media-permissions.test.js.map +1 -1
- package/dist/test/integration/media-project-field.test.js +17 -2
- package/dist/test/integration/media-project-field.test.js.map +1 -1
- package/dist/test/integration/media-search-views.test.js +24 -10
- package/dist/test/integration/media-search-views.test.js.map +1 -1
- package/dist/test/integration/media-storage-origin-unreachable.test.js +2 -1
- package/dist/test/integration/media-storage-origin-unreachable.test.js.map +1 -1
- package/dist/test/integration/media-transform.test.js +8 -9
- package/dist/test/integration/media-transform.test.js.map +1 -1
- package/dist/test/integration/media-upload-history-filters.test.d.ts +1 -0
- package/dist/test/integration/media-upload-history-filters.test.js +67 -0
- package/dist/test/integration/media-upload-history-filters.test.js.map +1 -0
- package/dist/test/integration/media-upload-policy.test.js +31 -14
- package/dist/test/integration/media-upload-policy.test.js.map +1 -1
- package/dist/test/integration/permissions-management.js +15 -4
- package/dist/test/integration/permissions-management.js.map +1 -1
- package/dist/test/unit/declared.test.js +1 -1
- package/dist/test/unit/declared.test.js.map +1 -1
- package/dist/test/unit/library/zip-names.test.js +22 -4
- package/dist/test/unit/library/zip-names.test.js.map +1 -1
- package/dist/test/unit/upload-rules.test.js +10 -0
- package/dist/test/unit/upload-rules.test.js.map +1 -1
- package/dist/transform-ops.js.map +1 -1
- package/dist/upload-policy.js +11 -11
- package/dist/upload-policy.js.map +1 -1
- package/dist/validation/declared.schema.d.ts +4 -4
- package/dist/validation/library.schema.d.ts +10 -10
- package/dist/validation/media.schema.d.ts +8 -9
- package/dist/validation/media.schema.js +4 -6
- package/dist/validation/media.schema.js.map +1 -1
- package/frontend-vue/package.json +2 -2
- package/package.json +12 -11
- package/skills/dms-media/SKILL.md +2 -2
- package/src/acl/entries.ts +5 -2
- package/src/asset-lifecycle.ts +2 -1
- package/src/declared/assets.ts +6 -6
- package/src/declared/records.ts +5 -1
- package/src/library/activity.ts +3 -1
- package/src/routes/media/manage.ts +2 -2
- package/src/routes/media/storage-keys.ts +1 -0
- package/src/test/antelope.test.ts +7 -5
- package/src/test/helpers/assets.ts +28 -15
- package/src/test/helpers/bodies.ts +22 -0
- package/src/test/helpers/folders.ts +6 -3
- package/src/test/helpers/members.ts +11 -3
- package/src/test/helpers/owner.ts +6 -1
- package/src/test/helpers/permissions-world.ts +23 -19
- package/src/test/helpers/setup-token.ts +6 -0
- package/src/test/integration/derivative-sweep-query.test.ts +4 -3
- package/src/test/integration/folder-cascade.test.ts +3 -1
- package/src/test/integration/media-activity-overview.test.ts +52 -37
- package/src/test/integration/media-api.test.ts +25 -27
- package/src/test/integration/media-bindings.test.ts +10 -16
- package/src/test/integration/media-declared-content.test.ts +2 -1
- package/src/test/integration/media-delivery-editing.test.ts +13 -2
- package/src/test/integration/media-delivery.test.ts +8 -3
- package/src/test/integration/media-explorer-writes.test.ts +6 -4
- package/src/test/integration/media-guards.test.ts +18 -13
- package/src/test/integration/media-library.test.ts +101 -47
- package/src/test/integration/media-linked-subfolders.test.ts +3 -2
- package/src/test/integration/media-member-access.test.ts +22 -24
- package/src/test/integration/media-permissions.test.ts +11 -5
- package/src/test/integration/media-project-field.test.ts +21 -9
- package/src/test/integration/media-search-views.test.ts +35 -31
- package/src/test/integration/media-storage-origin-unreachable.test.ts +2 -1
- package/src/test/integration/media-transform.test.ts +8 -9
- package/src/test/integration/media-upload-history-filters.test.ts +77 -0
- package/src/test/integration/media-upload-policy.test.ts +39 -20
- package/src/test/integration/permissions-management.ts +16 -4
- package/src/test/unit/declared.test.ts +4 -1
- package/src/test/unit/library/zip-names.test.ts +26 -7
- package/src/test/unit/upload-rules.test.ts +11 -0
- package/src/transform-ops.ts +1 -0
- package/src/upload-policy.ts +11 -11
- package/src/validation/media.schema.ts +8 -8
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AxiosInstance } from "axios";
|
|
2
2
|
import { assert, expect } from "chai";
|
|
3
|
+
import { z } from "zod";
|
|
3
4
|
import { RegisterAssetBinding } from "@antelopejs/interface-dms-media";
|
|
4
5
|
import {
|
|
5
6
|
configureMediaModule,
|
|
@@ -8,6 +9,7 @@ import {
|
|
|
8
9
|
} from "../../config";
|
|
9
10
|
import { MEDIA_PAGE_PERMISSION } from "../../pages/files";
|
|
10
11
|
import type { AclEntry } from "../../types";
|
|
12
|
+
import { createdBody, readBody } from "../helpers/bodies";
|
|
11
13
|
import {
|
|
12
14
|
type UploadedAsset,
|
|
13
15
|
uploadPixelPng,
|
|
@@ -37,25 +39,27 @@ export const STOCK_FOLDER_NAME = "Warehouse stock";
|
|
|
37
39
|
export const CONTENT_ROOT_NAME = "Content";
|
|
38
40
|
export const ROTATE_QUARTER_TURN = 90;
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
id: string
|
|
42
|
-
name: string
|
|
43
|
-
parentId: string
|
|
44
|
-
shell: boolean
|
|
45
|
-
bound: boolean
|
|
46
|
-
visibility: string
|
|
47
|
-
rights: {
|
|
48
|
-
|
|
42
|
+
const treeFolderNodeBody = z.object({
|
|
43
|
+
id: z.string(),
|
|
44
|
+
name: z.string(),
|
|
45
|
+
parentId: z.string().nullable(),
|
|
46
|
+
shell: z.boolean(),
|
|
47
|
+
bound: z.boolean(),
|
|
48
|
+
visibility: z.string(),
|
|
49
|
+
rights: z.object({
|
|
50
|
+
read: z.boolean(),
|
|
51
|
+
write: z.boolean(),
|
|
52
|
+
manage: z.boolean(),
|
|
53
|
+
}),
|
|
54
|
+
});
|
|
49
55
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
manage: boolean
|
|
53
|
-
}
|
|
56
|
+
const treeBody = z.object({
|
|
57
|
+
folders: z.array(treeFolderNodeBody),
|
|
58
|
+
root: z.object({ write: z.boolean(), manage: z.boolean() }),
|
|
59
|
+
});
|
|
54
60
|
|
|
55
|
-
export
|
|
56
|
-
|
|
57
|
-
root: TreeRootRights;
|
|
58
|
-
}
|
|
61
|
+
export type TreeFolderNode = z.infer<typeof treeFolderNodeBody>;
|
|
62
|
+
export type TreeResponse = z.infer<typeof treeBody>;
|
|
59
63
|
|
|
60
64
|
export interface WorldRoles {
|
|
61
65
|
pageHolder: string;
|
|
@@ -103,7 +107,7 @@ export interface WorldAssets {
|
|
|
103
107
|
export async function fetchTree(client: AxiosInstance): Promise<TreeResponse> {
|
|
104
108
|
const response = await client.get("/api/media/tree");
|
|
105
109
|
expect(response.status, "tree").to.equal(HTTP_OK);
|
|
106
|
-
return response
|
|
110
|
+
return readBody(response, treeBody);
|
|
107
111
|
}
|
|
108
112
|
|
|
109
113
|
export function findByName(
|
|
@@ -134,7 +138,7 @@ export async function createFolder(
|
|
|
134
138
|
): Promise<string> {
|
|
135
139
|
const response = await owner.post("/api/media/folders", { name, parentId });
|
|
136
140
|
expect(response.status, `create folder ${name}`).to.equal(HTTP_OK);
|
|
137
|
-
return response.
|
|
141
|
+
return readBody(response, createdBody).id;
|
|
138
142
|
}
|
|
139
143
|
|
|
140
144
|
export function roleEntry(
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The first-owner setup token of the test instance. The harness hands it to the
|
|
3
|
+
* DMS as `DMS_SETUP_TOKEN`, and the owner registration sends it back: from dms
|
|
4
|
+
* 0.15 onboarding refuses a registration without it.
|
|
5
|
+
*/
|
|
6
|
+
export const SETUP_TOKEN = "dms-media-test-setup-token";
|
|
@@ -28,14 +28,15 @@ describe("[integration] streaming derivative sweep", () => {
|
|
|
28
28
|
for (const [index, model] of models.entries()) {
|
|
29
29
|
await model.insert([{ ...fixture, _id: TENANTS[index] }]);
|
|
30
30
|
}
|
|
31
|
-
const visits:
|
|
31
|
+
const visits: unknown[] = [];
|
|
32
32
|
const restore = patchMethod<Query<unknown>, "cursor">(
|
|
33
33
|
Query.prototype,
|
|
34
34
|
"cursor",
|
|
35
35
|
(readCursor) =>
|
|
36
36
|
async function* (this: Query<unknown>) {
|
|
37
|
-
const table = this.stages.find(
|
|
38
|
-
|
|
37
|
+
const table: unknown = this.stages.find(
|
|
38
|
+
(stage) => stage.stage === "table",
|
|
39
|
+
)?.options?.id;
|
|
39
40
|
if (table === "tenants") {
|
|
40
41
|
for (const _id of TENANTS) yield { _id };
|
|
41
42
|
return;
|
|
@@ -6,6 +6,7 @@ import { uploadStorageBytes } from "../../derivatives";
|
|
|
6
6
|
import { deleteFolderTree } from "../../routes/media/folders";
|
|
7
7
|
|
|
8
8
|
const TENANT = "folder-cascade";
|
|
9
|
+
const TEST_TIMEOUT_MS = 20 * 1000;
|
|
9
10
|
|
|
10
11
|
async function insertFolder(
|
|
11
12
|
model: MediaFolderModel,
|
|
@@ -47,7 +48,8 @@ async function insertAsset(
|
|
|
47
48
|
return _id;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
describe("[integration] folder deletion cascade", ()
|
|
51
|
+
describe("[integration] folder deletion cascade", function () {
|
|
52
|
+
this.timeout(TEST_TIMEOUT_MS);
|
|
51
53
|
let folderModel: MediaFolderModel;
|
|
52
54
|
let assetModel: MediaAssetModel;
|
|
53
55
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { AxiosInstance } from "axios";
|
|
2
2
|
import { expect } from "chai";
|
|
3
|
+
import { z } from "zod";
|
|
3
4
|
import { uploadAsset } from "../helpers/assets";
|
|
5
|
+
import { createdBody, readBody } from "../helpers/bodies";
|
|
4
6
|
import { authorizedClient } from "../helpers/http";
|
|
5
7
|
import { createRole, registerMember } from "../helpers/members";
|
|
6
8
|
import { ensureOwnerSession } from "../helpers/owner";
|
|
@@ -11,25 +13,35 @@ const TEXT_MIMETYPE = "text/plain";
|
|
|
11
13
|
const BODY = Buffer.alloc(10, 1);
|
|
12
14
|
const BATCH_ID = "overview-retried-batch";
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
id: string
|
|
16
|
-
landingSlug: string
|
|
17
|
-
readout
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const moduleEntrySchema = z.object({
|
|
17
|
+
id: z.string(),
|
|
18
|
+
landingSlug: z.string(),
|
|
19
|
+
readout: z
|
|
20
|
+
.array(z.object({ text: z.string(), tone: z.string().optional() }))
|
|
21
|
+
.optional(),
|
|
22
|
+
status: z.string().optional(),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const modulesBody = z.union([
|
|
26
|
+
z.array(moduleEntrySchema),
|
|
27
|
+
z.object({ modules: z.array(moduleEntrySchema) }),
|
|
28
|
+
]);
|
|
20
29
|
|
|
21
|
-
|
|
22
|
-
_id: string
|
|
23
|
-
files: number
|
|
24
|
-
failed: number
|
|
25
|
-
result: string
|
|
26
|
-
attention: string
|
|
27
|
-
}
|
|
30
|
+
const batchRowSchema = z.object({
|
|
31
|
+
_id: z.string(),
|
|
32
|
+
files: z.number(),
|
|
33
|
+
failed: z.number(),
|
|
34
|
+
result: z.string(),
|
|
35
|
+
attention: z.string(),
|
|
36
|
+
});
|
|
28
37
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
38
|
+
const batchesBody = z.object({ results: z.array(batchRowSchema) });
|
|
39
|
+
const attentionBody = z.object({
|
|
40
|
+
items: z.array(z.object({ id: z.string(), value: z.number().optional() })),
|
|
41
|
+
});
|
|
42
|
+
const activityBody = z.object({
|
|
43
|
+
items: z.array(z.object({ title: z.string(), to: z.string().optional() })),
|
|
44
|
+
});
|
|
33
45
|
|
|
34
46
|
describe("[integration] media activity and overview — figures, upload history and module catalog", () => {
|
|
35
47
|
let client: AxiosInstance;
|
|
@@ -39,9 +51,10 @@ describe("[integration] media activity and overview — figures, upload history
|
|
|
39
51
|
this.timeout(30_000);
|
|
40
52
|
const session = await ensureOwnerSession();
|
|
41
53
|
client = authorizedClient(session.accessToken);
|
|
42
|
-
folderId = (
|
|
43
|
-
await client.post("/api/media/folders", { name: "Overview figures" })
|
|
44
|
-
|
|
54
|
+
folderId = readBody(
|
|
55
|
+
await client.post("/api/media/folders", { name: "Overview figures" }),
|
|
56
|
+
createdBody,
|
|
57
|
+
).id;
|
|
45
58
|
});
|
|
46
59
|
|
|
47
60
|
after(async () => {
|
|
@@ -51,9 +64,8 @@ describe("[integration] media activity and overview — figures, upload history
|
|
|
51
64
|
it("lands the catalog tile on the overview, with a readout", async () => {
|
|
52
65
|
const response = await client.get("/dms/modules-listing");
|
|
53
66
|
expect(response.status).to.equal(HTTP_OK);
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
: response.data.modules;
|
|
67
|
+
const listing = readBody(response, modulesBody);
|
|
68
|
+
const entries = Array.isArray(listing) ? listing : listing.modules;
|
|
57
69
|
const media = entries.find((entry) => entry.id === "media");
|
|
58
70
|
expect(media?.landingSlug).to.equal("/modules/media/overview");
|
|
59
71
|
expect(media?.readout).to.have.length(2);
|
|
@@ -77,29 +89,30 @@ describe("[integration] media activity and overview — figures, upload history
|
|
|
77
89
|
const failedOnly = await client.get("/api/media/upload/batches", {
|
|
78
90
|
params: { filter_result: "is:partial,failed" },
|
|
79
91
|
});
|
|
80
|
-
expect(
|
|
81
|
-
|
|
82
|
-
);
|
|
92
|
+
expect(
|
|
93
|
+
readBody(failedOnly, batchesBody).results.map((row) => row._id),
|
|
94
|
+
).to.include(BATCH_ID);
|
|
83
95
|
expect((await report(2, 0)).status).to.equal(HTTP_OK);
|
|
84
96
|
const all = await client.get("/api/media/upload/batches");
|
|
85
|
-
const row = all.
|
|
86
|
-
(entry
|
|
97
|
+
const row = readBody(all, batchesBody).results.find(
|
|
98
|
+
(entry) => entry._id === BATCH_ID,
|
|
87
99
|
);
|
|
88
100
|
expect(row).to.include({ failed: 0, result: "complete" });
|
|
89
101
|
const stillFailed = await client.get("/api/media/upload/batches", {
|
|
90
102
|
params: { filter_result: "is:partial,failed" },
|
|
91
103
|
});
|
|
92
104
|
expect(
|
|
93
|
-
stillFailed.
|
|
105
|
+
readBody(stillFailed, batchesBody).results.map((entry) => entry._id),
|
|
94
106
|
).to.not.include(BATCH_ID);
|
|
95
107
|
});
|
|
96
108
|
|
|
97
109
|
it("counts on the overview exactly the failures the history flags", async () => {
|
|
98
|
-
const failingFolder = (
|
|
110
|
+
const failingFolder = readBody(
|
|
99
111
|
await client.post("/api/media/folders", {
|
|
100
112
|
name: "Overview failing uploads",
|
|
101
|
-
})
|
|
102
|
-
|
|
113
|
+
}),
|
|
114
|
+
createdBody,
|
|
115
|
+
).id;
|
|
103
116
|
await client.post("/api/media/upload/batches", {
|
|
104
117
|
batchId: "overview-failing-batch",
|
|
105
118
|
folderId: failingFolder,
|
|
@@ -112,15 +125,15 @@ describe("[integration] media activity and overview — figures, upload history
|
|
|
112
125
|
const rows = await client.get("/api/media/upload/batches", {
|
|
113
126
|
params: { filter_attention: "is:yes" },
|
|
114
127
|
});
|
|
115
|
-
return rows.
|
|
116
|
-
(total
|
|
128
|
+
return readBody(rows, batchesBody).results.reduce(
|
|
129
|
+
(total, row) => total + row.failed,
|
|
117
130
|
0,
|
|
118
131
|
);
|
|
119
132
|
};
|
|
120
133
|
const counted = async () => {
|
|
121
134
|
const attention = await client.get("/api/media/stats/attention");
|
|
122
|
-
const item = attention.
|
|
123
|
-
(entry
|
|
135
|
+
const item = readBody(attention, attentionBody).items.find(
|
|
136
|
+
(entry) => entry.id === "failed-uploads",
|
|
124
137
|
);
|
|
125
138
|
return item?.value ?? 0;
|
|
126
139
|
};
|
|
@@ -136,7 +149,9 @@ describe("[integration] media activity and overview — figures, upload history
|
|
|
136
149
|
const response = await client.get("/api/media/activity", {
|
|
137
150
|
params: { limit: 50 },
|
|
138
151
|
});
|
|
139
|
-
const titles = response.
|
|
152
|
+
const titles = readBody(response, activityBody).items.map(
|
|
153
|
+
(item) => item.title,
|
|
154
|
+
);
|
|
140
155
|
expect(titles).to.not.include("$dms_media.activity.upload_batch");
|
|
141
156
|
expect(titles).to.not.include("$dms_media.activity.upload_batch_partial");
|
|
142
157
|
});
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { AxiosInstance } from "axios";
|
|
2
|
-
import axios from "axios";
|
|
3
2
|
import { expect } from "chai";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { putPresigned } from "../helpers/assets";
|
|
5
|
+
import { createdBody, presignBody, readBody } from "../helpers/bodies";
|
|
4
6
|
import { authorizedClient } from "../helpers/http";
|
|
5
7
|
import { ensureOwnerSession } from "../helpers/owner";
|
|
6
8
|
|
|
@@ -26,18 +28,17 @@ async function waitForMediaApi(client: AxiosInstance): Promise<void> {
|
|
|
26
28
|
throw new Error("Timed out waiting for the media API to be ready");
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
31
|
+
const treeBody = z.object({
|
|
32
|
+
folders: z.array(
|
|
33
|
+
z.object({
|
|
34
|
+
id: z.string(),
|
|
35
|
+
parentId: z.string().nullable(),
|
|
36
|
+
rights: z
|
|
37
|
+
.object({ read: z.boolean(), write: z.boolean(), manage: z.boolean() })
|
|
38
|
+
.strict(),
|
|
39
|
+
}),
|
|
40
|
+
),
|
|
41
|
+
});
|
|
41
42
|
|
|
42
43
|
describe("[integration] media API — owner lifecycle", () => {
|
|
43
44
|
let client: AxiosInstance;
|
|
@@ -64,7 +65,7 @@ describe("[integration] media API — owner lifecycle", () => {
|
|
|
64
65
|
name: "Brand",
|
|
65
66
|
});
|
|
66
67
|
expect(created.status).to.equal(HTTP_OK);
|
|
67
|
-
brandFolderId = created.
|
|
68
|
+
brandFolderId = readBody(created, createdBody).id;
|
|
68
69
|
expect(brandFolderId).to.be.a("string");
|
|
69
70
|
|
|
70
71
|
const sub = await client.post("/api/media/folders", {
|
|
@@ -72,15 +73,15 @@ describe("[integration] media API — owner lifecycle", () => {
|
|
|
72
73
|
parentId: brandFolderId,
|
|
73
74
|
});
|
|
74
75
|
expect(sub.status).to.equal(HTTP_OK);
|
|
75
|
-
subFolderId = sub.
|
|
76
|
+
subFolderId = readBody(sub, createdBody).id;
|
|
76
77
|
|
|
77
78
|
const tree = await client.get("/api/media/tree");
|
|
78
79
|
expect(tree.data.folders).to.have.length(2);
|
|
79
|
-
const subNode = tree.
|
|
80
|
-
(node
|
|
80
|
+
const subNode = readBody(tree, treeBody).folders.find(
|
|
81
|
+
(node) => node.id === subFolderId,
|
|
81
82
|
);
|
|
82
|
-
expect(subNode
|
|
83
|
-
expect(subNode
|
|
83
|
+
expect(subNode?.parentId).to.equal(brandFolderId);
|
|
84
|
+
expect(subNode?.rights).to.deep.equal({
|
|
84
85
|
read: true,
|
|
85
86
|
write: true,
|
|
86
87
|
manage: true,
|
|
@@ -103,22 +104,19 @@ describe("[integration] media API — owner lifecycle", () => {
|
|
|
103
104
|
mimetype: FILE_MIMETYPE,
|
|
104
105
|
});
|
|
105
106
|
expect(presign.status).to.equal(HTTP_OK);
|
|
106
|
-
|
|
107
|
+
const presigned = readBody(presign, presignBody);
|
|
108
|
+
expect(presigned.resourceKey).to.be.a("string");
|
|
107
109
|
|
|
108
|
-
const putStatus = await
|
|
109
|
-
presign.data.uploadUrl,
|
|
110
|
-
presign.data.headers,
|
|
111
|
-
body,
|
|
112
|
-
);
|
|
110
|
+
const putStatus = (await putPresigned(presigned, body)).status;
|
|
113
111
|
expect(putStatus).to.be.lessThan(300);
|
|
114
112
|
|
|
115
113
|
const confirm = await client.post("/api/media/upload/confirm", {
|
|
116
114
|
folderId: brandFolderId,
|
|
117
|
-
resourceKey:
|
|
115
|
+
resourceKey: presigned.resourceKey,
|
|
118
116
|
filename: FILE_NAME,
|
|
119
117
|
});
|
|
120
118
|
expect(confirm.status).to.equal(HTTP_OK);
|
|
121
|
-
assetId = confirm.
|
|
119
|
+
assetId = readBody(confirm, z.object({ asset: createdBody })).asset.id;
|
|
122
120
|
expect(confirm.data.asset.name).to.equal(FILE_NAME);
|
|
123
121
|
expect(confirm.data.asset.mimetype).to.equal(FILE_MIMETYPE);
|
|
124
122
|
expect(confirm.data.asset.size).to.equal(body.byteLength);
|
|
@@ -8,7 +8,8 @@ import { CustomComponent } from "@antelopejs/interface-dms/base/custom";
|
|
|
8
8
|
import type { AxiosInstance } from "axios";
|
|
9
9
|
import { assert, expect } from "chai";
|
|
10
10
|
import { RegisterAssetBinding } from "@antelopejs/interface-dms-media";
|
|
11
|
-
import {
|
|
11
|
+
import { readBody } from "../helpers/bodies";
|
|
12
|
+
import { folderTreeBody, readFolderAcl } from "../helpers/folders";
|
|
12
13
|
import { authorizedClient } from "../helpers/http";
|
|
13
14
|
import { ensureOwnerSession } from "../helpers/owner";
|
|
14
15
|
|
|
@@ -28,13 +29,6 @@ class PageBoundProbePage extends PageController("page-bound-probe", {
|
|
|
28
29
|
static content = CustomComponent("dms-media-page-bound-probe");
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
interface FolderNode {
|
|
32
|
-
id: string;
|
|
33
|
-
name: string;
|
|
34
|
-
parentId: string | null;
|
|
35
|
-
bound: boolean;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
32
|
describe("[integration] media bindings — linked folder provisioning", () => {
|
|
39
33
|
let client: AxiosInstance;
|
|
40
34
|
let contentRootId: string;
|
|
@@ -62,7 +56,7 @@ describe("[integration] media bindings — linked folder provisioning", () => {
|
|
|
62
56
|
it("provisions the content root and the linked folder lazily", async () => {
|
|
63
57
|
const tree = await client.get("/api/media/tree");
|
|
64
58
|
expect(tree.status).to.equal(HTTP_OK);
|
|
65
|
-
const folders
|
|
59
|
+
const folders = readBody(tree, folderTreeBody).folders;
|
|
66
60
|
const contentRoot = folders.find(
|
|
67
61
|
(folder) => folder.name === "Content" && folder.parentId === null,
|
|
68
62
|
);
|
|
@@ -79,8 +73,8 @@ describe("[integration] media bindings — linked folder provisioning", () => {
|
|
|
79
73
|
const first = await client.get("/api/media/tree");
|
|
80
74
|
const second = await client.get("/api/media/tree");
|
|
81
75
|
expect(second.data.folders.length).to.equal(first.data.folders.length);
|
|
82
|
-
const bound = second.
|
|
83
|
-
(folder
|
|
76
|
+
const bound = readBody(second, folderTreeBody).folders.filter(
|
|
77
|
+
(folder) => folder.name === "Article covers",
|
|
84
78
|
);
|
|
85
79
|
expect(bound).to.have.length(1);
|
|
86
80
|
});
|
|
@@ -101,10 +95,10 @@ describe("[integration] media bindings — linked folder provisioning", () => {
|
|
|
101
95
|
const pagePermission = GetPermissionId(PageBoundProbePage);
|
|
102
96
|
expect(pagePermission, "probe page permission").to.be.a("string");
|
|
103
97
|
const tree = await client.get("/api/media/tree");
|
|
104
|
-
const folder = tree.
|
|
105
|
-
(node
|
|
98
|
+
const folder = readBody(tree, folderTreeBody).folders.find(
|
|
99
|
+
(node) => node.name === PAGE_BOUND_FOLDER_NAME,
|
|
106
100
|
);
|
|
107
|
-
|
|
101
|
+
assert.isDefined(folder, "page-bound folder");
|
|
108
102
|
const entries = await readFolderAcl(folder.id);
|
|
109
103
|
expect(entries).to.deep.include({
|
|
110
104
|
subject: { kind: "permission", id: pagePermission },
|
|
@@ -150,8 +144,8 @@ describe("[integration] media bindings — linked folder provisioning", () => {
|
|
|
150
144
|
expect(response.status).to.equal(HTTP_OK);
|
|
151
145
|
}
|
|
152
146
|
const tree = await client.get("/api/media/tree");
|
|
153
|
-
const probes = tree.
|
|
154
|
-
(folder
|
|
147
|
+
const probes = readBody(tree, folderTreeBody).folders.filter(
|
|
148
|
+
(folder) => folder.name === PROBE_NAME,
|
|
155
149
|
);
|
|
156
150
|
expect(probes).to.have.length(1);
|
|
157
151
|
});
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
MediaFolderModel,
|
|
22
22
|
} from "../../db";
|
|
23
23
|
import { ONE_PIXEL_PNG, PNG_MIMETYPE } from "../helpers/assets";
|
|
24
|
+
import { readBody, urlBody } from "../helpers/bodies";
|
|
24
25
|
import { readFolderAcl } from "../helpers/folders";
|
|
25
26
|
import { authorizedClient } from "../helpers/http";
|
|
26
27
|
import { ensureOwnerSession } from "../helpers/owner";
|
|
@@ -336,7 +337,7 @@ describe("[integration] media declared content — folders and files shipped as
|
|
|
336
337
|
`/api/media/assets/${first.id}/read-url`,
|
|
337
338
|
);
|
|
338
339
|
expect(readUrl.status).to.equal(HTTP_OK);
|
|
339
|
-
const stored = await fetch(readUrl.
|
|
340
|
+
const stored = await fetch(readBody(readUrl, urlBody).url);
|
|
340
341
|
expect(Buffer.from(await stored.arrayBuffer())).to.deep.equal(
|
|
341
342
|
ONE_PIXEL_PNG,
|
|
342
343
|
);
|
|
@@ -4,6 +4,7 @@ import { assert, expect } from "chai";
|
|
|
4
4
|
import { GetModel } from "@antelopejs/interface-database-decorators";
|
|
5
5
|
import { DEFAULT_TENANT_ID } from "@antelopejs/interface-dms/constants";
|
|
6
6
|
import sharp from "sharp";
|
|
7
|
+
import { z } from "zod";
|
|
7
8
|
import { MediaAssetModel } from "../../db";
|
|
8
9
|
import { uploadStorageBytes } from "../../derivatives";
|
|
9
10
|
import {
|
|
@@ -12,9 +13,16 @@ import {
|
|
|
12
13
|
MediaAssetChangedError,
|
|
13
14
|
} from "../../transform";
|
|
14
15
|
import { type UploadedAsset, uploadAsset } from "../helpers/assets";
|
|
16
|
+
import { createdBody, readBody } from "../helpers/bodies";
|
|
15
17
|
import { authorizedClient, getBaseUrl } from "../helpers/http";
|
|
16
18
|
import { ensureOwnerSession } from "../helpers/owner";
|
|
17
19
|
|
|
20
|
+
const previewsBody = z.object({
|
|
21
|
+
previews: z
|
|
22
|
+
.record(z.string())
|
|
23
|
+
.transform((urls) => new Map(Object.entries(urls))),
|
|
24
|
+
});
|
|
25
|
+
|
|
18
26
|
const HTTP_OK = 200;
|
|
19
27
|
const HTTP_FOUND = 302;
|
|
20
28
|
const HTTP_NOT_MODIFIED = 304;
|
|
@@ -153,7 +161,7 @@ describe("[integration] media delivery and editing — cache, orientation, activ
|
|
|
153
161
|
name: "Delivery and editing",
|
|
154
162
|
});
|
|
155
163
|
expect(folder.status).to.equal(HTTP_OK);
|
|
156
|
-
folderId = folder.
|
|
164
|
+
folderId = readBody(folder, createdBody).id;
|
|
157
165
|
jpeg = await uploadAsset(
|
|
158
166
|
client,
|
|
159
167
|
folderId,
|
|
@@ -341,9 +349,12 @@ describe("[integration] media delivery and editing — cache, orientation, activ
|
|
|
341
349
|
`/api/media/previews?ids=${logo.id}&ids=${banner.id}`,
|
|
342
350
|
);
|
|
343
351
|
expect(answer.status).to.equal(HTTP_OK);
|
|
352
|
+
const { previews } = readBody(answer, previewsBody);
|
|
344
353
|
const [vector, raster] = await Promise.all(
|
|
345
354
|
[logo.id, banner.id].map(async (id) => {
|
|
346
|
-
const
|
|
355
|
+
const preview = previews.get(id);
|
|
356
|
+
assert.isDefined(preview, `preview of ${id}`);
|
|
357
|
+
const response = await fetch(preview);
|
|
347
358
|
return sharp(Buffer.from(await response.arrayBuffer())).metadata();
|
|
348
359
|
}),
|
|
349
360
|
);
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { AxiosInstance } from "axios";
|
|
2
2
|
import { assert, expect } from "chai";
|
|
3
|
+
import { z } from "zod";
|
|
3
4
|
import {
|
|
4
5
|
ONE_PIXEL_PNG,
|
|
5
6
|
PNG_NAME,
|
|
6
7
|
rawGet,
|
|
7
8
|
uploadPixelPng,
|
|
8
9
|
} from "../helpers/assets";
|
|
10
|
+
import { createdBody, readBody, urlBody } from "../helpers/bodies";
|
|
9
11
|
import { authorizedClient } from "../helpers/http";
|
|
10
12
|
import { ensureOwnerSession } from "../helpers/owner";
|
|
11
13
|
|
|
@@ -39,7 +41,7 @@ describe("[integration] media delivery — visibility and derivatives", () => {
|
|
|
39
41
|
name: "Delivery",
|
|
40
42
|
});
|
|
41
43
|
expect(folder.status).to.equal(HTTP_OK);
|
|
42
|
-
folderId = folder.
|
|
44
|
+
folderId = readBody(folder, createdBody).id;
|
|
43
45
|
const asset = await uploadPixelPng(client, folderId);
|
|
44
46
|
assetId = asset.id;
|
|
45
47
|
});
|
|
@@ -115,7 +117,7 @@ describe("[integration] media delivery — visibility and derivatives", () => {
|
|
|
115
117
|
`/api/media/assets/${assetId}/read-url?preset=thumb`,
|
|
116
118
|
);
|
|
117
119
|
expect(derived.status).to.equal(HTTP_OK);
|
|
118
|
-
const bytes = await fetchBytes(derived.
|
|
120
|
+
const bytes = await fetchBytes(readBody(derived, urlBody).url);
|
|
119
121
|
expect(bytes.byteLength).to.be.greaterThan(0);
|
|
120
122
|
});
|
|
121
123
|
|
|
@@ -123,7 +125,10 @@ describe("[integration] media delivery — visibility and derivatives", () => {
|
|
|
123
125
|
const listing = await client.get("/api/media/assets");
|
|
124
126
|
expect(listing.status).to.equal(HTTP_OK);
|
|
125
127
|
expect(listing.data.truncated).to.equal(false);
|
|
126
|
-
const ids =
|
|
128
|
+
const ids = readBody(
|
|
129
|
+
listing,
|
|
130
|
+
z.object({ assets: z.array(createdBody) }),
|
|
131
|
+
).assets.map((asset) => asset.id);
|
|
127
132
|
expect(ids).to.include(assetId);
|
|
128
133
|
|
|
129
134
|
const secondAsset = await uploadPixelPng(client, folderId);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AxiosInstance } from "axios";
|
|
2
2
|
import { expect } from "chai";
|
|
3
|
+
import { z } from "zod";
|
|
3
4
|
import { GetModel } from "@antelopejs/interface-database-decorators";
|
|
4
5
|
import { DEFAULT_TENANT_ID } from "@antelopejs/interface-dms/constants";
|
|
5
6
|
import {
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
import { CONTENT_ROOT_BINDING } from "../../bindings";
|
|
10
11
|
import { MediaEventModel, MediaFolderModel } from "../../db";
|
|
11
12
|
import { uploadPixelPng, uploadTextAsset } from "../helpers/assets";
|
|
13
|
+
import { createdBody, readBody } from "../helpers/bodies";
|
|
12
14
|
import { fetchFolderNodes } from "../helpers/folders";
|
|
13
15
|
import { authorizedClient } from "../helpers/http";
|
|
14
16
|
import { ensureOwnerSession } from "../helpers/owner";
|
|
@@ -72,12 +74,12 @@ describe("[integration] media explorer writes — names, linked folders, zips",
|
|
|
72
74
|
name: "Explorer writes",
|
|
73
75
|
});
|
|
74
76
|
expect(root.status).to.equal(HTTP_OK);
|
|
75
|
-
rootId = root.
|
|
77
|
+
rootId = readBody(root, createdBody).id;
|
|
76
78
|
const other = await client.post("/api/media/folders", {
|
|
77
79
|
name: "Other",
|
|
78
80
|
parentId: rootId,
|
|
79
81
|
});
|
|
80
|
-
otherId = other.
|
|
82
|
+
otherId = readBody(other, createdBody).id;
|
|
81
83
|
});
|
|
82
84
|
|
|
83
85
|
after(async () => {
|
|
@@ -116,7 +118,7 @@ describe("[integration] media explorer writes — names, linked folders, zips",
|
|
|
116
118
|
const event = events.find((entry) => entry.targetName === "Traced");
|
|
117
119
|
expect(event?.folderId).to.equal(rootId);
|
|
118
120
|
expect(JSON.parse(event?.json_details ?? "{}")).to.deep.equal({
|
|
119
|
-
targetId: created.
|
|
121
|
+
targetId: readBody(created, createdBody).id,
|
|
120
122
|
});
|
|
121
123
|
});
|
|
122
124
|
|
|
@@ -190,7 +192,7 @@ describe("[integration] media explorer writes — names, linked folders, zips",
|
|
|
190
192
|
expect(zipped.headers["content-disposition"]).to.contain(
|
|
191
193
|
"Explorer writes.zip",
|
|
192
194
|
);
|
|
193
|
-
const names = zipEntryNames(
|
|
195
|
+
const names = zipEntryNames(readBody(zipped, z.instanceof(Buffer)));
|
|
194
196
|
expect(names).to.include.members([
|
|
195
197
|
"Notes.txt",
|
|
196
198
|
"other.txt",
|