@antelopejs/dms-media 0.7.1 → 0.7.2
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 +2 -2
- package/dist/config.js.map +1 -1
- package/dist/declared/assets.js +1 -2
- package/dist/declared/assets.js.map +1 -1
- package/dist/library/activity.d.ts +1 -1
- package/dist/library/activity.js.map +1 -1
- package/dist/pages/uploads.js +1 -1
- package/dist/pages/uploads.js.map +1 -1
- package/dist/routes/media/asset-actions.js +12 -4
- package/dist/routes/media/asset-actions.js.map +1 -1
- package/dist/routes/media/overview.js +5 -1
- package/dist/routes/media/overview.js.map +1 -1
- package/dist/routes/media/upload.js +1 -3
- package/dist/routes/media/upload.js.map +1 -1
- package/dist/test/antelope.test.js +11 -6
- package/dist/test/antelope.test.js.map +1 -1
- package/dist/test/integration/media-explorer-writes.test.js +21 -0
- package/dist/test/integration/media-explorer-writes.test.js.map +1 -1
- package/dist/test/integration/media-file-history.test.d.ts +1 -0
- package/dist/test/integration/media-file-history.test.js +33 -0
- package/dist/test/integration/media-file-history.test.js.map +1 -0
- package/dist/test/integration/media-linked-subfolders.test.js +35 -0
- package/dist/test/integration/media-linked-subfolders.test.js.map +1 -1
- package/dist/test/integration/media-upload-policy.test.js +39 -6
- package/dist/test/integration/media-upload-policy.test.js.map +1 -1
- package/dist/test/stack-modules.json +7 -0
- package/dist/test/unit/library/activity-overview.test.js +9 -0
- package/dist/test/unit/library/activity-overview.test.js.map +1 -1
- package/dist/test/unit/pages/toolbar.test.js +4 -4
- package/dist/test/unit/pages/toolbar.test.js.map +1 -1
- package/dist/upload-checks.d.ts +1 -3
- package/dist/upload-checks.js +12 -14
- package/dist/upload-checks.js.map +1 -1
- package/dist/validation/media.schema.d.ts +1 -0
- package/dist/validation/media.schema.js +1 -0
- package/dist/validation/media.schema.js.map +1 -1
- package/frontend-vue/app/components/explorer/ExplorerShell.vue +11 -7
- package/frontend-vue/i18n/locales/media-en-GB.json +1 -0
- package/frontend-vue/i18n/locales/media-fr-FR.json +1 -0
- package/frontend-vue/package.json +39 -39
- package/package.json +7 -6
- package/skills/dms-media/SKILL.md +1 -1
- package/src/config.ts +4 -3
- package/src/declared/assets.ts +2 -4
- package/src/library/activity.ts +6 -2
- package/src/pages/uploads.ts +1 -1
- package/src/routes/media/asset-actions.ts +24 -3
- package/src/routes/media/overview.ts +5 -4
- package/src/routes/media/upload.ts +2 -5
- package/src/test/antelope.test.ts +8 -6
- package/src/test/integration/media-explorer-writes.test.ts +22 -0
- package/src/test/integration/media-file-history.test.ts +38 -0
- package/src/test/integration/media-linked-subfolders.test.ts +45 -1
- package/src/test/integration/media-upload-policy.test.ts +45 -10
- package/src/test/stack-modules.json +7 -0
- package/src/test/unit/library/activity-overview.test.ts +15 -0
- package/src/test/unit/pages/toolbar.test.ts +4 -4
- package/src/upload-checks.ts +22 -18
- package/src/validation/media.schema.ts +1 -0
|
@@ -13,7 +13,7 @@ Owner pages under `/modules/media` (overview, files, uploads, file, editor, acti
|
|
|
13
13
|
they reach media through `AssetType` fields on project pages. User docs: `docs/` of this package, published at
|
|
14
14
|
https://dms.antelopejs.com/docs/modules/media.
|
|
15
15
|
Overview, uploads and activity are `live` pages (shared `rememberKey: "media"`) opening on the DMS `pageToolbar({ period: false })`
|
|
16
|
-
(last read + Direct / Pause, block id `toolbar`); the upload history table is `liveHold
|
|
16
|
+
(last read + Direct / Pause, block id `toolbar`); the upload history table is `liveHold` with `whileOnScreen: false`: it holds only while the page is paused. Needs interface-dms with `base/page-toolbar`.
|
|
17
17
|
Every data block carries `realtimeTopic: MEDIA_LIBRARY_TOPIC`; custom components refresh through `onLibraryChange` (DMS
|
|
18
18
|
`usePageLiveRefresh`, so Pause holds them). Announcements are coalesced and carry `payload.count` (changes they stand for).
|
|
19
19
|
|
package/src/config.ts
CHANGED
|
@@ -30,13 +30,14 @@ export interface DmsMediaConfig {
|
|
|
30
30
|
storageQuotaBytes?: number;
|
|
31
31
|
/**
|
|
32
32
|
* File types members may upload, as mimetypes (`image/*` matches a prefix).
|
|
33
|
-
* HTML and
|
|
33
|
+
* HTML, XHTML and PHP stay refused, by type or by extension, whatever this
|
|
34
|
+
* list says.
|
|
34
35
|
*/
|
|
35
36
|
allowedMimetypes?: string[];
|
|
36
37
|
/**
|
|
37
38
|
* Public URL of the API, the origin serving `/media`: copied links and the
|
|
38
|
-
* file page's delivery tab start with it. Defaults to the
|
|
39
|
-
*
|
|
39
|
+
* file page's delivery tab start with it. Defaults to the DMS `apiBaseUrl`.
|
|
40
|
+
* With neither set, links stay relative.
|
|
40
41
|
*/
|
|
41
42
|
publicBaseUrl?: string;
|
|
42
43
|
}
|
package/src/declared/assets.ts
CHANGED
|
@@ -11,11 +11,10 @@ import type { MediaAsset, MediaFolder } from "../db";
|
|
|
11
11
|
import { uploadStorageBytes } from "../derivatives";
|
|
12
12
|
import { recordMediaEvent } from "../library/events";
|
|
13
13
|
import {
|
|
14
|
-
assertReadableImage,
|
|
15
14
|
assertUploadTypeAllowed,
|
|
16
15
|
assertWithinQuota,
|
|
17
16
|
type ImageProbe,
|
|
18
|
-
|
|
17
|
+
probeImage,
|
|
19
18
|
UploadRefusedError,
|
|
20
19
|
} from "../upload-checks";
|
|
21
20
|
import { mimetypeOfFormat } from "../upload-policy";
|
|
@@ -122,12 +121,11 @@ async function prepareFile(
|
|
|
122
121
|
): Promise<PreparedFile> {
|
|
123
122
|
assertUploadTypeAllowed(fieldBinding, declaration.name, declaration.mimetype);
|
|
124
123
|
await assertWithinQuota(models.assetModel, bytes.byteLength);
|
|
125
|
-
const image = await
|
|
124
|
+
const image = await probeImage(
|
|
126
125
|
async () => bytes,
|
|
127
126
|
declaration.mimetype,
|
|
128
127
|
bytes.byteLength,
|
|
129
128
|
);
|
|
130
|
-
assertReadableImage(image, declaration.mimetype);
|
|
131
129
|
return {
|
|
132
130
|
bytes,
|
|
133
131
|
mimetype: mimetypeOfFormat(image.format) ?? declaration.mimetype,
|
package/src/library/activity.ts
CHANGED
|
@@ -316,10 +316,14 @@ function deletedAssets(events: MediaEvent[]): Set<string> {
|
|
|
316
316
|
);
|
|
317
317
|
}
|
|
318
318
|
|
|
319
|
-
/**
|
|
319
|
+
/**
|
|
320
|
+
* Newest first, with one entry per upload batch and per bulk action.
|
|
321
|
+
*
|
|
322
|
+
* @param limit The most entries to keep; every entry when left out.
|
|
323
|
+
*/
|
|
320
324
|
export function buildActivityItems(
|
|
321
325
|
source: ActivitySource,
|
|
322
|
-
limit
|
|
326
|
+
limit?: number,
|
|
323
327
|
): ActivityFeedItem[] {
|
|
324
328
|
const context: ActivityContext = {
|
|
325
329
|
...source,
|
package/src/pages/uploads.ts
CHANGED
|
@@ -20,7 +20,7 @@ const history = TableView.fromSource({
|
|
|
20
20
|
caption: `${TEXTS}.history.title`,
|
|
21
21
|
fetchUrl: "/api/media/upload/batches",
|
|
22
22
|
realtimeTopic: MEDIA_LIBRARY_TOPIC,
|
|
23
|
-
liveHold:
|
|
23
|
+
liveHold: { whileOnScreen: false },
|
|
24
24
|
layout: "full",
|
|
25
25
|
density: "compact",
|
|
26
26
|
pageSize: HISTORY_PAGE_SIZE,
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { assert } from "@antelopejs/interface-api-util";
|
|
2
2
|
import { deleteMediaAsset } from "../../asset-lifecycle";
|
|
3
|
+
import { feedingBinding } from "../../bindings";
|
|
3
4
|
import type { MediaAsset, MediaFolder } from "../../db";
|
|
5
|
+
import { bindingAccepts } from "../../library/binding-labels";
|
|
4
6
|
import { recordMediaEvent } from "../../library/events";
|
|
5
7
|
import { forgetFavorites } from "../../library/favorites";
|
|
6
8
|
import type { AssetVisibility } from "../../types";
|
|
9
|
+
import { mimetypeMatches } from "../../upload-policy";
|
|
7
10
|
import { comparableName, MEDIA_ERRORS } from "../../validation/media.schema";
|
|
8
11
|
import {
|
|
9
12
|
assertMediaOwner,
|
|
@@ -13,6 +16,7 @@ import {
|
|
|
13
16
|
import { resolveEffectiveVisibility } from "./dto";
|
|
14
17
|
|
|
15
18
|
const HTTP_CONFLICT = 409;
|
|
19
|
+
const HTTP_UNSUPPORTED_MEDIA_TYPE = 415;
|
|
16
20
|
|
|
17
21
|
export interface AssetChanges {
|
|
18
22
|
name?: string;
|
|
@@ -30,14 +34,15 @@ function changesEffectiveVisibility(
|
|
|
30
34
|
);
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
/** Refuses a name another file of
|
|
37
|
+
/** Refuses a name another file of `folderId` already has, regardless of case. */
|
|
34
38
|
async function assertFreeAssetName(
|
|
35
39
|
context: MediaRequestContext,
|
|
36
40
|
asset: MediaAsset,
|
|
41
|
+
folderId: string,
|
|
37
42
|
name: string,
|
|
38
43
|
): Promise<void> {
|
|
39
44
|
const wanted = comparableName(name);
|
|
40
|
-
const siblings = await context.assetModel.getBy("folderId",
|
|
45
|
+
const siblings = await context.assetModel.getBy("folderId", folderId);
|
|
41
46
|
const clash = siblings.some(
|
|
42
47
|
(sibling) =>
|
|
43
48
|
sibling._id !== asset._id &&
|
|
@@ -54,7 +59,14 @@ export async function updateAssetDetails(
|
|
|
54
59
|
): Promise<void> {
|
|
55
60
|
requireFolderRight(context, asset.folderId, "write");
|
|
56
61
|
const isRename = changes.name !== undefined && changes.name !== asset.name;
|
|
57
|
-
if (isRename)
|
|
62
|
+
if (isRename) {
|
|
63
|
+
await assertFreeAssetName(
|
|
64
|
+
context,
|
|
65
|
+
asset,
|
|
66
|
+
asset.folderId,
|
|
67
|
+
changes.name ?? "",
|
|
68
|
+
);
|
|
69
|
+
}
|
|
58
70
|
await context.assetModel.update(asset._id, changes);
|
|
59
71
|
const isAltChange = changes.alt !== undefined && changes.alt !== asset.alt;
|
|
60
72
|
if (isRename) {
|
|
@@ -84,9 +96,18 @@ export async function moveAsset(
|
|
|
84
96
|
const sourceFolder = requireFolderRight(context, asset.folderId, "write");
|
|
85
97
|
const targetFolder = requireFolderRight(context, folderId, "write");
|
|
86
98
|
if (sourceFolder._id === targetFolder._id) return;
|
|
99
|
+
const accepted = bindingAccepts(
|
|
100
|
+
feedingBinding(targetFolder, context.foldersById),
|
|
101
|
+
);
|
|
102
|
+
assert(
|
|
103
|
+
!accepted || mimetypeMatches(asset.mimetype, accepted),
|
|
104
|
+
HTTP_UNSUPPORTED_MEDIA_TYPE,
|
|
105
|
+
MEDIA_ERRORS.fieldType,
|
|
106
|
+
);
|
|
87
107
|
if (changesEffectiveVisibility(asset, sourceFolder, targetFolder)) {
|
|
88
108
|
assertMediaOwner(context);
|
|
89
109
|
}
|
|
110
|
+
await assertFreeAssetName(context, asset, folderId, asset.name);
|
|
90
111
|
await context.assetModel.update(asset._id, { folderId });
|
|
91
112
|
await recordMediaEvent(context, {
|
|
92
113
|
kind: "asset.move",
|
|
@@ -208,10 +208,11 @@ export class MediaOverviewController extends MediaApiController {
|
|
|
208
208
|
MediaEventModel,
|
|
209
209
|
context.tenantId,
|
|
210
210
|
).listByAsset(assetId);
|
|
211
|
-
const items = buildActivityItems(
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
211
|
+
const items = buildActivityItems({
|
|
212
|
+
events,
|
|
213
|
+
foldersById: context.foldersById,
|
|
214
|
+
foldsBulkActions: false,
|
|
215
|
+
});
|
|
215
216
|
return { items: unlinkCurrentFile(items, assetId) };
|
|
216
217
|
}
|
|
217
218
|
}
|
|
@@ -19,11 +19,10 @@ import { ORIGINAL_FILENAME_METADATA_KEY } from "../../constants";
|
|
|
19
19
|
import { MediaUploadModel } from "../../db";
|
|
20
20
|
import { loadAssetsInFolders } from "../../library/listing";
|
|
21
21
|
import {
|
|
22
|
-
assertReadableImage,
|
|
23
22
|
assertUploadTypeAllowed,
|
|
24
23
|
assertWithinQuota,
|
|
25
24
|
type ImageProbe,
|
|
26
|
-
|
|
25
|
+
probeImage,
|
|
27
26
|
UploadRefusedError,
|
|
28
27
|
} from "../../upload-checks";
|
|
29
28
|
import { suggestFreeNames } from "../../upload-names";
|
|
@@ -73,13 +72,11 @@ async function readImage(
|
|
|
73
72
|
metadata: FileMetadata,
|
|
74
73
|
): Promise<ImageProbe> {
|
|
75
74
|
const storage = getMediaConfig().storage;
|
|
76
|
-
|
|
75
|
+
return probeImage(
|
|
77
76
|
() => readStoredFile(resourceKey, storage),
|
|
78
77
|
metadata.mimetype,
|
|
79
78
|
metadata.size,
|
|
80
79
|
);
|
|
81
|
-
assertReadableImage(probe, metadata.mimetype);
|
|
82
|
-
return probe;
|
|
83
80
|
}
|
|
84
81
|
|
|
85
82
|
async function assertUploadAccepted(
|
|
@@ -2,10 +2,12 @@ import { mkdtemp, rm } from "node:fs/promises";
|
|
|
2
2
|
import { createServer, type Server, type Socket } from "node:net";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
+
import { version as DMS_VERSION } from "@antelopejs/dms/package.json";
|
|
5
6
|
import { defineConfig } from "@antelopejs/interface-core/config";
|
|
6
7
|
import { MongoMemoryReplSet } from "mongodb-memory-server-core";
|
|
7
8
|
import { isString } from "../guards";
|
|
8
9
|
import { SETUP_TOKEN } from "./helpers/setup-token";
|
|
10
|
+
import STACK_MODULES from "./stack-modules.json";
|
|
9
11
|
|
|
10
12
|
const API_PORT = 5019;
|
|
11
13
|
const LOCAL_BUILD_COMMAND = process.env.DMS_PREBUILT ? [] : ["pnpm build"];
|
|
@@ -111,7 +113,7 @@ export default defineConfig({
|
|
|
111
113
|
source: {
|
|
112
114
|
type: "package",
|
|
113
115
|
package: "@antelopejs/dms",
|
|
114
|
-
version:
|
|
116
|
+
version: DMS_VERSION,
|
|
115
117
|
},
|
|
116
118
|
config: {
|
|
117
119
|
/**
|
|
@@ -135,14 +137,14 @@ export default defineConfig({
|
|
|
135
137
|
source: {
|
|
136
138
|
type: "package",
|
|
137
139
|
package: "@antelopejs/mongodb",
|
|
138
|
-
version: "
|
|
140
|
+
version: STACK_MODULES["@antelopejs/mongodb"],
|
|
139
141
|
},
|
|
140
142
|
},
|
|
141
143
|
"auth-jwt": {
|
|
142
144
|
source: {
|
|
143
145
|
type: "package",
|
|
144
146
|
package: "@antelopejs/auth-jwt",
|
|
145
|
-
version: "
|
|
147
|
+
version: STACK_MODULES["@antelopejs/auth-jwt"],
|
|
146
148
|
},
|
|
147
149
|
config: {
|
|
148
150
|
secret: JWT_SECRET,
|
|
@@ -152,7 +154,7 @@ export default defineConfig({
|
|
|
152
154
|
source: {
|
|
153
155
|
type: "package",
|
|
154
156
|
package: "@antelopejs/api",
|
|
155
|
-
version: "
|
|
157
|
+
version: STACK_MODULES["@antelopejs/api"],
|
|
156
158
|
},
|
|
157
159
|
config: {
|
|
158
160
|
servers: [{ protocol: "http", host: "127.0.0.1", port: API_PORT }],
|
|
@@ -163,14 +165,14 @@ export default defineConfig({
|
|
|
163
165
|
source: {
|
|
164
166
|
type: "package",
|
|
165
167
|
package: "@antelopejs/file-storage-local",
|
|
166
|
-
version: "
|
|
168
|
+
version: STACK_MODULES["@antelopejs/file-storage-local"],
|
|
167
169
|
},
|
|
168
170
|
},
|
|
169
171
|
nodemailer: {
|
|
170
172
|
source: {
|
|
171
173
|
type: "package",
|
|
172
174
|
package: "@antelopejs/nodemailer",
|
|
173
|
-
version: "
|
|
175
|
+
version: STACK_MODULES["@antelopejs/nodemailer"],
|
|
174
176
|
},
|
|
175
177
|
config: {
|
|
176
178
|
host: SMTP_HOST,
|
|
@@ -159,6 +159,28 @@ describe("[integration] media explorer writes — names, linked folders, zips",
|
|
|
159
159
|
expect(sameNameElsewhere.status).to.equal(HTTP_OK);
|
|
160
160
|
});
|
|
161
161
|
|
|
162
|
+
it("refuses to move a file onto a name the target folder already holds, regardless of case", async () => {
|
|
163
|
+
const held = await uploadTextAsset(client, otherId, "Report.txt");
|
|
164
|
+
const mover = await uploadTextAsset(client, rootId, "report.txt");
|
|
165
|
+
const moved = await client.post(`/api/media/assets/${mover.id}/move`, {
|
|
166
|
+
folderId: otherId,
|
|
167
|
+
});
|
|
168
|
+
expect(moved.status).to.equal(HTTP_CONFLICT);
|
|
169
|
+
expect(moved.data).to.equal(`${ERRORS}.name_taken`);
|
|
170
|
+
const bulk = await client.post("/api/media/assets/bulk/move", {
|
|
171
|
+
ids: [mover.id],
|
|
172
|
+
folderId: otherId,
|
|
173
|
+
});
|
|
174
|
+
expect(bulk.data.done).to.deep.equal([]);
|
|
175
|
+
expect(bulk.data.refused).to.deep.equal([
|
|
176
|
+
{ id: mover.id, status: HTTP_CONFLICT, message: `${ERRORS}.name_taken` },
|
|
177
|
+
]);
|
|
178
|
+
const detail = await client.get(`/api/media/assets/${mover.id}`);
|
|
179
|
+
expect(detail.data.asset.folderId).to.equal(rootId);
|
|
180
|
+
await client.delete(`/api/media/assets/${held.id}`);
|
|
181
|
+
await client.delete(`/api/media/assets/${mover.id}`);
|
|
182
|
+
});
|
|
183
|
+
|
|
162
184
|
it("answers validation errors with i18n keys instead of zod dumps", async () => {
|
|
163
185
|
const asset = await uploadPixelPng(client, rootId);
|
|
164
186
|
const tooLong = await client.post(`/api/media/assets/${asset.id}/update`, {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { uploadPixelPng } from "../helpers/assets";
|
|
4
|
+
import { createdBody, readBody } from "../helpers/bodies";
|
|
5
|
+
import { authorizedClient } from "../helpers/http";
|
|
6
|
+
import { ensureOwnerSession } from "../helpers/owner";
|
|
7
|
+
|
|
8
|
+
const HTTP_OK = 200;
|
|
9
|
+
const RENAMES = 55;
|
|
10
|
+
|
|
11
|
+
const historyBody = z.object({
|
|
12
|
+
items: z.array(z.object({ title: z.string() })),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe("[integration] file history — every event of the file", () => {
|
|
16
|
+
it("lists more than 50 events, the upload last", async function () {
|
|
17
|
+
this.timeout(60_000);
|
|
18
|
+
const session = await ensureOwnerSession();
|
|
19
|
+
const client = authorizedClient(session.accessToken);
|
|
20
|
+
const folderId = readBody(
|
|
21
|
+
await client.post("/api/media/folders", { name: "File history spec" }),
|
|
22
|
+
createdBody,
|
|
23
|
+
).id;
|
|
24
|
+
const asset = await uploadPixelPng(client, folderId);
|
|
25
|
+
for (let index = 1; index <= RENAMES; index += 1) {
|
|
26
|
+
const rename = await client.post(`/api/media/assets/${asset.id}/update`, {
|
|
27
|
+
name: `history-${index}.png`,
|
|
28
|
+
});
|
|
29
|
+
expect(rename.status, `rename ${index}`).to.equal(HTTP_OK);
|
|
30
|
+
}
|
|
31
|
+
const history = await client.get(`/api/media/assets/${asset.id}/history`);
|
|
32
|
+
const titles = readBody(history, historyBody).items.map(
|
|
33
|
+
(item) => item.title,
|
|
34
|
+
);
|
|
35
|
+
expect(titles).to.have.length(RENAMES + 1);
|
|
36
|
+
expect(titles.at(-1)).to.equal("$dms_media.activity.asset_upload");
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -14,7 +14,12 @@ import {
|
|
|
14
14
|
MediaDeclarationModel,
|
|
15
15
|
MediaFolderModel,
|
|
16
16
|
} from "../../db";
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
ONE_PIXEL_PNG,
|
|
19
|
+
PNG_MIMETYPE,
|
|
20
|
+
uploadPixelPng,
|
|
21
|
+
uploadTextAsset,
|
|
22
|
+
} from "../helpers/assets";
|
|
18
23
|
import { createdBody, readBody } from "../helpers/bodies";
|
|
19
24
|
import { type FolderNode, fetchFolderNodes } from "../helpers/folders";
|
|
20
25
|
import { authorizedClient } from "../helpers/http";
|
|
@@ -167,6 +172,45 @@ describe("[integration] media linked subfolders — bindings that allow them", (
|
|
|
167
172
|
expect((await presign("photo.png", "image/png")).status).to.equal(HTTP_OK);
|
|
168
173
|
});
|
|
169
174
|
|
|
175
|
+
it("refuses to move a file into a linked folder whose field does not take its type", async () => {
|
|
176
|
+
const linked = await treeFolder(OPEN_BINDING_ID);
|
|
177
|
+
const library = await client.post("/api/media/folders", {
|
|
178
|
+
name: "Loose files",
|
|
179
|
+
});
|
|
180
|
+
const libraryId = readBody(library, createdBody).id;
|
|
181
|
+
const notes = await uploadTextAsset(client, libraryId, "notes.txt");
|
|
182
|
+
const photo = await uploadPixelPng(client, libraryId);
|
|
183
|
+
const single = await client.post(`/api/media/assets/${notes.id}/move`, {
|
|
184
|
+
folderId: linked.id,
|
|
185
|
+
});
|
|
186
|
+
expect(single.status).to.equal(HTTP_UNSUPPORTED_MEDIA_TYPE);
|
|
187
|
+
expect(single.data).to.equal(`${ERRORS}.field_type`);
|
|
188
|
+
const subfolder = await client.post("/api/media/folders", {
|
|
189
|
+
name: "Project D",
|
|
190
|
+
parentId: linked.id,
|
|
191
|
+
});
|
|
192
|
+
const intoSubfolder = await client.post(
|
|
193
|
+
`/api/media/assets/${notes.id}/move`,
|
|
194
|
+
{ folderId: readBody(subfolder, createdBody).id },
|
|
195
|
+
);
|
|
196
|
+
expect(intoSubfolder.status).to.equal(HTTP_UNSUPPORTED_MEDIA_TYPE);
|
|
197
|
+
const bulk = await client.post("/api/media/assets/bulk/move", {
|
|
198
|
+
ids: [notes.id, photo.id],
|
|
199
|
+
folderId: linked.id,
|
|
200
|
+
});
|
|
201
|
+
expect(bulk.data.done).to.deep.equal([photo.id]);
|
|
202
|
+
expect(bulk.data.refused).to.deep.equal([
|
|
203
|
+
{
|
|
204
|
+
id: notes.id,
|
|
205
|
+
status: HTTP_UNSUPPORTED_MEDIA_TYPE,
|
|
206
|
+
message: `${ERRORS}.field_type`,
|
|
207
|
+
},
|
|
208
|
+
]);
|
|
209
|
+
const assetModel = GetModel(MediaAssetModel, DEFAULT_TENANT_ID);
|
|
210
|
+
expect((await assetModel.get(notes.id))?.folderId).to.equal(libraryId);
|
|
211
|
+
await client.delete(`/api/media/folders/${libraryId}`);
|
|
212
|
+
});
|
|
213
|
+
|
|
170
214
|
it("declares per-record folders under a linked folder that allows them", async () => {
|
|
171
215
|
const linked = await treeFolder(OPEN_BINDING_ID);
|
|
172
216
|
const project = await EnsureMediaFolder({
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
UnregisterAssetBinding,
|
|
9
9
|
} from "@antelopejs/interface-dms-media";
|
|
10
10
|
import sharp from "sharp";
|
|
11
|
+
import { z } from "zod";
|
|
11
12
|
import { CONTENT_ROOT_BINDING } from "../../bindings";
|
|
12
13
|
import {
|
|
13
14
|
configureMediaModule,
|
|
@@ -31,6 +32,16 @@ const PDF_BINDING_ID = "upload-policy.pdf-only";
|
|
|
31
32
|
const PDF_FOLDER_NAME = "PDF only uploads";
|
|
32
33
|
const PURGE_HORIZON_MS = 25 * 60 * 60 * 1000;
|
|
33
34
|
const EXIF_ROTATED_RIGHT = 6;
|
|
35
|
+
const LARGER_THAN_PROBE_BYTES = 33 * 1024 * 1024;
|
|
36
|
+
|
|
37
|
+
const confirmedBody = z.object({
|
|
38
|
+
asset: z.object({
|
|
39
|
+
mimetype: z.string(),
|
|
40
|
+
size: z.number(),
|
|
41
|
+
width: z.number().nullish(),
|
|
42
|
+
height: z.number().nullish(),
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
34
45
|
|
|
35
46
|
interface StagedUpload {
|
|
36
47
|
resourceKey: string;
|
|
@@ -210,20 +221,44 @@ describe("[integration] media upload policy — types, quota, real content and s
|
|
|
210
221
|
}
|
|
211
222
|
});
|
|
212
223
|
|
|
213
|
-
it("refuses a fake image at confirm and deletes its staged file", async () => {
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
224
|
+
it("refuses a fake image at confirm, whatever the case of its type, and deletes its staged file", async () => {
|
|
225
|
+
for (const mimetype of ["image/png", "Image/PNG"]) {
|
|
226
|
+
const staged = await stage(
|
|
227
|
+
"fake.png",
|
|
228
|
+
mimetype,
|
|
229
|
+
Buffer.from("this is not a png"),
|
|
230
|
+
);
|
|
231
|
+
const confirm = await client.post("/api/media/upload/confirm", {
|
|
232
|
+
folderId,
|
|
233
|
+
resourceKey: staged.resourceKey,
|
|
234
|
+
filename: "fake.png",
|
|
235
|
+
});
|
|
236
|
+
expect(confirm.status, mimetype).to.equal(HTTP_UNPROCESSABLE_ENTITY);
|
|
237
|
+
expect(confirm.data.reason, mimetype).to.equal("invalid_image");
|
|
238
|
+
expect(await FileExists(staged.resourceKey), mimetype).to.equal(false);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("stores an image too large to probe, without its size", async function () {
|
|
243
|
+
this.timeout(60_000);
|
|
244
|
+
const jpeg = await sharp({
|
|
245
|
+
create: { width: 8, height: 6, channels: 3, background: "#808080" },
|
|
246
|
+
})
|
|
247
|
+
.jpeg()
|
|
248
|
+
.toBuffer();
|
|
249
|
+
const large = Buffer.concat([jpeg, Buffer.alloc(LARGER_THAN_PROBE_BYTES)]);
|
|
250
|
+
const staged = await stage("large.jpg", "image/jpeg", large);
|
|
219
251
|
const confirm = await client.post("/api/media/upload/confirm", {
|
|
220
252
|
folderId,
|
|
221
253
|
resourceKey: staged.resourceKey,
|
|
222
|
-
filename: "
|
|
254
|
+
filename: "large.jpg",
|
|
223
255
|
});
|
|
224
|
-
expect(confirm.status).to.equal(
|
|
225
|
-
|
|
226
|
-
expect(
|
|
256
|
+
expect(confirm.status, JSON.stringify(confirm.data)).to.equal(HTTP_OK);
|
|
257
|
+
const { asset } = readBody(confirm, confirmedBody);
|
|
258
|
+
expect(asset.mimetype).to.equal("image/jpeg");
|
|
259
|
+
expect(asset.size).to.equal(large.byteLength);
|
|
260
|
+
expect(asset.width ?? undefined).to.equal(undefined);
|
|
261
|
+
expect(asset.height ?? undefined).to.equal(undefined);
|
|
227
262
|
});
|
|
228
263
|
|
|
229
264
|
it("confirms a text file declared with the name of an Object.prototype member", async () => {
|
|
@@ -274,4 +274,19 @@ describe("[unit] library/presets-page — image sizes", () => {
|
|
|
274
274
|
expect(pickExampleImage([svg, photo], () => true)?._id).to.equal("photo");
|
|
275
275
|
expect(pickExampleImage([svg], () => true)).to.equal(undefined);
|
|
276
276
|
});
|
|
277
|
+
|
|
278
|
+
it("shows sizes on the newest public photo, else on the newest private one", () => {
|
|
279
|
+
const oldPublic = asset("old-public", { createdAt: at(1) });
|
|
280
|
+
const newPrivate = asset("new-private", { createdAt: at(5) });
|
|
281
|
+
const olderPrivate = asset("older-private", { createdAt: at(3) });
|
|
282
|
+
const isPublic = (candidate: { _id: string }) =>
|
|
283
|
+
candidate._id === "old-public";
|
|
284
|
+
expect(pickExampleImage([newPrivate, oldPublic], isPublic)?._id).to.equal(
|
|
285
|
+
"old-public",
|
|
286
|
+
);
|
|
287
|
+
expect(
|
|
288
|
+
pickExampleImage([olderPrivate, newPrivate], isPublic)?._id,
|
|
289
|
+
).to.equal("new-private");
|
|
290
|
+
expect(pickExampleImage([], isPublic)).to.equal(undefined);
|
|
291
|
+
});
|
|
277
292
|
});
|
|
@@ -109,9 +109,9 @@ describe("[unit] pages — toolbar", () => {
|
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
it("holds the upload history while the page is paused", () => {
|
|
113
|
-
expect(MediaUploadsPage.history.serializeSync().options)
|
|
114
|
-
liveHold
|
|
115
|
-
|
|
112
|
+
it("holds the upload history only while the page is paused, not while Live shows it", () => {
|
|
113
|
+
expect(MediaUploadsPage.history.serializeSync().options)
|
|
114
|
+
.to.have.property("liveHold")
|
|
115
|
+
.that.deep.equals({ whileOnScreen: false });
|
|
116
116
|
});
|
|
117
117
|
});
|
package/src/upload-checks.ts
CHANGED
|
@@ -48,11 +48,11 @@ export class UploadRefusedError extends Error {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
/** An image's displayed size and decoded format, each absent when unknown. */
|
|
51
52
|
export interface ImageProbe {
|
|
52
53
|
width?: number;
|
|
53
54
|
height?: number;
|
|
54
55
|
format?: string;
|
|
55
|
-
isReadable: boolean;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/** Displayed size: sharp reports stored pixels, EXIF orientations 5-8 swap them. */
|
|
@@ -62,36 +62,40 @@ function orientedSize(metadata: sharp.Metadata): ImageProbe {
|
|
|
62
62
|
width: isSwapped ? metadata.height : metadata.width,
|
|
63
63
|
height: isSwapped ? metadata.width : metadata.height,
|
|
64
64
|
format: metadata.format,
|
|
65
|
-
isReadable: true,
|
|
66
65
|
};
|
|
67
66
|
}
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
mimetype: string,
|
|
73
|
-
size: number,
|
|
74
|
-
): Promise<ImageProbe> {
|
|
75
|
-
if (!mimetype.startsWith("image/") || size > MAX_PROBE_SIZE_BYTES)
|
|
76
|
-
return { isReadable: true };
|
|
68
|
+
async function readMetadata(
|
|
69
|
+
read: () => Promise<Buffer>,
|
|
70
|
+
): Promise<sharp.Metadata | undefined> {
|
|
77
71
|
try {
|
|
78
|
-
|
|
79
|
-
if (!buffer) return { isReadable: true };
|
|
80
|
-
return orientedSize(await sharp(buffer).metadata());
|
|
72
|
+
return await sharp(await read()).metadata();
|
|
81
73
|
} catch {
|
|
82
|
-
return
|
|
74
|
+
return undefined;
|
|
83
75
|
}
|
|
84
76
|
}
|
|
85
77
|
|
|
86
|
-
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Reads an image's displayed size. A file declared as a raster type sharp
|
|
80
|
+
* decodes must decode; any other file, and an image too large to probe, has
|
|
81
|
+
* no size.
|
|
82
|
+
*/
|
|
83
|
+
export async function probeImage(
|
|
84
|
+
read: () => Promise<Buffer>,
|
|
85
|
+
mimetype: string,
|
|
86
|
+
size: number,
|
|
87
|
+
): Promise<ImageProbe> {
|
|
88
|
+
if (!mimetypeMatches(mimetype, ["image/*"]) || size > MAX_PROBE_SIZE_BYTES)
|
|
89
|
+
return {};
|
|
90
|
+
const metadata = await readMetadata(read);
|
|
91
|
+
if (metadata?.format) return orientedSize(metadata);
|
|
92
|
+
if (expectedImageFormat(mimetype))
|
|
90
93
|
throw new UploadRefusedError(
|
|
91
94
|
HTTP_UNPROCESSABLE_ENTITY,
|
|
92
95
|
"invalid_image",
|
|
93
96
|
"This file is not a readable image",
|
|
94
97
|
);
|
|
98
|
+
return {};
|
|
95
99
|
}
|
|
96
100
|
|
|
97
101
|
/** The library's types, then those of the asset field the folder feeds. */
|