@antelopejs/dms-media 0.7.1 → 0.7.3
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/declared/folders.js.map +1 -1
- package/dist/library/activity.d.ts +1 -1
- package/dist/library/activity.js.map +1 -1
- package/dist/library/folder-stats.d.ts +1 -1
- package/dist/library/folder-stats.js.map +1 -1
- package/dist/library/listing.d.ts +2 -0
- package/dist/library/listing.js +14 -4
- package/dist/library/listing.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/assets.js +4 -4
- package/dist/routes/media/assets.js.map +1 -1
- package/dist/routes/media/bulk.js +4 -4
- package/dist/routes/media/bulk.js.map +1 -1
- package/dist/routes/media/folders.js +4 -4
- package/dist/routes/media/folders.js.map +1 -1
- package/dist/routes/media/library.js +6 -12
- package/dist/routes/media/library.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/library/zip-names.test.js +6 -3
- package/dist/test/unit/library/zip-names.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 +2 -1
- package/dist/validation/media.schema.js +11 -6
- 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/frontend-vue/tsconfig.json +1 -2
- package/package.json +9 -8
- package/skills/dms-media/SKILL.md +1 -1
- package/src/config.ts +4 -3
- package/src/declared/assets.ts +2 -4
- package/src/declared/folders.ts +1 -0
- package/src/library/activity.ts +6 -2
- package/src/library/folder-stats.ts +1 -1
- package/src/library/listing.ts +24 -4
- package/src/pages/uploads.ts +1 -1
- package/src/routes/media/asset-actions.ts +24 -3
- package/src/routes/media/assets.ts +9 -5
- package/src/routes/media/bulk.ts +7 -5
- package/src/routes/media/folders.ts +9 -5
- package/src/routes/media/library.ts +10 -18
- 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/library/zip-names.test.ts +9 -7
- package/src/test/unit/pages/toolbar.test.ts +4 -4
- package/src/upload-checks.ts +22 -18
- package/src/validation/media.schema.ts +15 -15
|
@@ -16,7 +16,7 @@ function emptyStats(): FolderStats {
|
|
|
16
16
|
/** Recursive file counts and sizes of every folder, from one pass over the assets. */
|
|
17
17
|
export function computeFolderStats(
|
|
18
18
|
folders: MediaFolder[],
|
|
19
|
-
assets: MediaAsset[],
|
|
19
|
+
assets: Pick<MediaAsset, "folderId" | "size">[],
|
|
20
20
|
): Map<string, FolderStats> {
|
|
21
21
|
const stats = new Map(folders.map((folder) => [folder._id, emptyStats()]));
|
|
22
22
|
const foldersById = new Map(folders.map((folder) => [folder._id, folder]));
|
package/src/library/listing.ts
CHANGED
|
@@ -33,21 +33,41 @@ interface AssetsTableModel {
|
|
|
33
33
|
table: MediaAssetModel["table"];
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/** What the library tree counts of each asset. */
|
|
37
|
+
export type AssetCountFields = Pick<
|
|
38
|
+
MediaAsset,
|
|
39
|
+
"_id" | "folderId" | "size" | "mimetype" | "alt"
|
|
40
|
+
>;
|
|
41
|
+
|
|
42
|
+
function liveAssetsIn(model: AssetsTableModel, folderIds: string[]) {
|
|
43
|
+
return model.table
|
|
44
|
+
.getAll(folderIds.length === 1 ? folderIds[0] : folderIds, "folderId")
|
|
45
|
+
.filter((row) => row.key("isDeleting").default(false).eq(false));
|
|
46
|
+
}
|
|
47
|
+
|
|
36
48
|
/** Every live asset stored in the given folders. */
|
|
37
49
|
export async function loadAssetsInFolders(
|
|
38
50
|
model: AssetsTableModel,
|
|
39
51
|
folderIds: string[],
|
|
40
52
|
): Promise<MediaAsset[]> {
|
|
41
53
|
if (folderIds.length === 0) return [];
|
|
42
|
-
const rows = await model.
|
|
43
|
-
.getAll(folderIds.length === 1 ? folderIds[0] : folderIds, "folderId")
|
|
44
|
-
.filter((row) => row.key("isDeleting").default(false).eq(false))
|
|
45
|
-
.run();
|
|
54
|
+
const rows = await liveAssetsIn(model, folderIds).run();
|
|
46
55
|
return rows
|
|
47
56
|
.map((row) => MediaAssetModel.fromDatabase(row))
|
|
48
57
|
.filter((row): row is MediaAsset => row !== undefined);
|
|
49
58
|
}
|
|
50
59
|
|
|
60
|
+
/** The fields the tree counts, of every live asset stored in the given folders. */
|
|
61
|
+
export async function loadAssetCountFields(
|
|
62
|
+
model: AssetsTableModel,
|
|
63
|
+
folderIds: string[],
|
|
64
|
+
): Promise<AssetCountFields[]> {
|
|
65
|
+
if (folderIds.length === 0) return [];
|
|
66
|
+
return liveAssetsIn(model, folderIds)
|
|
67
|
+
.pluck("_id", "folderId", "size", "mimetype", "alt")
|
|
68
|
+
.run();
|
|
69
|
+
}
|
|
70
|
+
|
|
51
71
|
/** Bytes the tenant's live assets keep in storage, edited originals included. */
|
|
52
72
|
export async function sumStoredBytes(model: AssetsTableModel): Promise<number> {
|
|
53
73
|
const total = await model.table
|
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",
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
assetVisibilitySchema,
|
|
24
24
|
MEDIA_ERRORS,
|
|
25
25
|
moveAssetSchema,
|
|
26
|
-
|
|
26
|
+
rejectInvalid,
|
|
27
27
|
previewIdsSchema,
|
|
28
28
|
updateAssetSchema,
|
|
29
29
|
} from "../../validation/media.schema";
|
|
@@ -134,7 +134,9 @@ export class MediaAssetsController extends MediaApiController {
|
|
|
134
134
|
|
|
135
135
|
@Get("/previews")
|
|
136
136
|
async previews(@MultiParameter("ids", "query") queryIds: string[]) {
|
|
137
|
-
const { ids } =
|
|
137
|
+
const { ids } = rejectInvalid(() =>
|
|
138
|
+
previewIdsSchema.parse({ ids: queryIds }),
|
|
139
|
+
);
|
|
138
140
|
const context = await this.resolveContext();
|
|
139
141
|
const { presets } = getMediaConfig();
|
|
140
142
|
const thumb = presets.get(THUMB_PRESET_ID);
|
|
@@ -212,7 +214,7 @@ export class MediaAssetsController extends MediaApiController {
|
|
|
212
214
|
@Parameter("assetId", "param") assetId: string,
|
|
213
215
|
@JSONBody() body: unknown,
|
|
214
216
|
) {
|
|
215
|
-
const changes =
|
|
217
|
+
const changes = rejectInvalid(() => updateAssetSchema.parse(body));
|
|
216
218
|
const context = await this.resolveContext();
|
|
217
219
|
const asset = await requireReadableAsset(context, assetId);
|
|
218
220
|
await updateAssetDetails(context, asset, changes);
|
|
@@ -224,7 +226,7 @@ export class MediaAssetsController extends MediaApiController {
|
|
|
224
226
|
@Parameter("assetId", "param") assetId: string,
|
|
225
227
|
@JSONBody() body: unknown,
|
|
226
228
|
) {
|
|
227
|
-
const { folderId } =
|
|
229
|
+
const { folderId } = rejectInvalid(() => moveAssetSchema.parse(body));
|
|
228
230
|
const context = await this.resolveContext();
|
|
229
231
|
const asset = await requireReadableAsset(context, assetId);
|
|
230
232
|
await moveAsset(context, asset, folderId);
|
|
@@ -236,7 +238,9 @@ export class MediaAssetsController extends MediaApiController {
|
|
|
236
238
|
@Parameter("assetId", "param") assetId: string,
|
|
237
239
|
@JSONBody() body: unknown,
|
|
238
240
|
) {
|
|
239
|
-
const { visibility } =
|
|
241
|
+
const { visibility } = rejectInvalid(() =>
|
|
242
|
+
assetVisibilitySchema.parse(body),
|
|
243
|
+
);
|
|
240
244
|
const context = await this.resolveContext();
|
|
241
245
|
const asset = await requireReadableAsset(context, assetId);
|
|
242
246
|
await setAssetVisibility(context, asset, visibility);
|
package/src/routes/media/bulk.ts
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
bulkMoveSchema,
|
|
15
15
|
bulkVisibilitySchema,
|
|
16
16
|
} from "../../validation/library.schema";
|
|
17
|
-
import {
|
|
17
|
+
import { rejectInvalid } from "../../validation/media.schema";
|
|
18
18
|
import { moveAsset, removeAsset, setAssetVisibility } from "./asset-actions";
|
|
19
19
|
import { requireReadableAsset } from "./assets";
|
|
20
20
|
import { MediaApiController } from "./controller";
|
|
@@ -195,7 +195,7 @@ function zipResponse(entries: ZipEntry[], filename: string): HTTPResult {
|
|
|
195
195
|
export class MediaBulkController extends MediaApiController {
|
|
196
196
|
@Post("/assets/bulk/move")
|
|
197
197
|
async bulkMove(@JSONBody() body: unknown) {
|
|
198
|
-
const { ids, folderId } =
|
|
198
|
+
const { ids, folderId } = rejectInvalid(() => bulkMoveSchema.parse(body));
|
|
199
199
|
const context = await this.resolveContext();
|
|
200
200
|
return applyToEach(context, ids, (ctx, asset) =>
|
|
201
201
|
moveAsset(ctx, asset, folderId),
|
|
@@ -204,7 +204,9 @@ export class MediaBulkController extends MediaApiController {
|
|
|
204
204
|
|
|
205
205
|
@Post("/assets/bulk/visibility")
|
|
206
206
|
async bulkVisibility(@JSONBody() body: unknown) {
|
|
207
|
-
const { ids, visibility } =
|
|
207
|
+
const { ids, visibility } = rejectInvalid(() =>
|
|
208
|
+
bulkVisibilitySchema.parse(body),
|
|
209
|
+
);
|
|
208
210
|
const context = await this.resolveContext();
|
|
209
211
|
return applyToEach(context, ids, (ctx, asset) =>
|
|
210
212
|
setAssetVisibility(ctx, asset, visibility),
|
|
@@ -213,14 +215,14 @@ export class MediaBulkController extends MediaApiController {
|
|
|
213
215
|
|
|
214
216
|
@Post("/assets/bulk/delete")
|
|
215
217
|
async bulkDelete(@JSONBody() body: unknown) {
|
|
216
|
-
const { ids } =
|
|
218
|
+
const { ids } = rejectInvalid(() => bulkIdsSchema.parse(body));
|
|
217
219
|
const context = await this.resolveContext();
|
|
218
220
|
return applyToEach(context, ids, removeAsset);
|
|
219
221
|
}
|
|
220
222
|
|
|
221
223
|
@Post("/assets/zip")
|
|
222
224
|
async zip(@JSONBody() body: unknown) {
|
|
223
|
-
const { ids } =
|
|
225
|
+
const { ids } = rejectInvalid(() => bulkIdsSchema.parse(body));
|
|
224
226
|
const context = await this.resolveContext();
|
|
225
227
|
return zipResponse(await loadZipAssets(context, ids), ZIP_FILENAME);
|
|
226
228
|
}
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
folderVisibilitySchema,
|
|
12
12
|
MEDIA_ERRORS,
|
|
13
13
|
moveFolderSchema,
|
|
14
|
-
|
|
14
|
+
rejectInvalid,
|
|
15
15
|
renameFolderSchema,
|
|
16
16
|
} from "../../validation/media.schema";
|
|
17
17
|
import {
|
|
@@ -156,7 +156,9 @@ export function isMoveInsideSubtree(
|
|
|
156
156
|
export class MediaFoldersController extends MediaApiController {
|
|
157
157
|
@Post("/folders")
|
|
158
158
|
async createFolder(@JSONBody() body: unknown) {
|
|
159
|
-
const { name, parentId } =
|
|
159
|
+
const { name, parentId } = rejectInvalid(() =>
|
|
160
|
+
createFolderSchema.parse(body),
|
|
161
|
+
);
|
|
160
162
|
const context = await this.resolveContext();
|
|
161
163
|
const parent = assertCanPlaceUnder(context, parentId);
|
|
162
164
|
assertUniqueSiblingName(context, name, parentId);
|
|
@@ -180,7 +182,7 @@ export class MediaFoldersController extends MediaApiController {
|
|
|
180
182
|
@Parameter("folderId", "param") folderId: string,
|
|
181
183
|
@JSONBody() body: unknown,
|
|
182
184
|
) {
|
|
183
|
-
const { name } =
|
|
185
|
+
const { name } = rejectInvalid(() => renameFolderSchema.parse(body));
|
|
184
186
|
const context = await this.resolveContext();
|
|
185
187
|
const folder = requireFolderRight(context, folderId, "manage");
|
|
186
188
|
assertNotBound(folder);
|
|
@@ -205,7 +207,7 @@ export class MediaFoldersController extends MediaApiController {
|
|
|
205
207
|
@Parameter("folderId", "param") folderId: string,
|
|
206
208
|
@JSONBody() body: unknown,
|
|
207
209
|
) {
|
|
208
|
-
const { parentId } =
|
|
210
|
+
const { parentId } = rejectInvalid(() => moveFolderSchema.parse(body));
|
|
209
211
|
const context = await this.resolveContext();
|
|
210
212
|
const folder = requireFolderRight(context, folderId, "manage");
|
|
211
213
|
assertNotBound(folder);
|
|
@@ -232,7 +234,9 @@ export class MediaFoldersController extends MediaApiController {
|
|
|
232
234
|
@Parameter("folderId", "param") folderId: string,
|
|
233
235
|
@JSONBody() body: unknown,
|
|
234
236
|
) {
|
|
235
|
-
const { visibility } =
|
|
237
|
+
const { visibility } = rejectInvalid(() =>
|
|
238
|
+
folderVisibilitySchema.parse(body),
|
|
239
|
+
);
|
|
236
240
|
const context = await this.resolveContext();
|
|
237
241
|
const folder = requireFolderRight(context, folderId, "manage");
|
|
238
242
|
assertMediaOwner(context);
|
|
@@ -13,7 +13,9 @@ import {
|
|
|
13
13
|
} from "../../library/favorites";
|
|
14
14
|
import { computeFolderStats } from "../../library/folder-stats";
|
|
15
15
|
import {
|
|
16
|
+
type AssetCountFields,
|
|
16
17
|
countByTypeGroup,
|
|
18
|
+
loadAssetCountFields,
|
|
17
19
|
loadAssetsInFolders,
|
|
18
20
|
pageAssets,
|
|
19
21
|
} from "../../library/listing";
|
|
@@ -73,6 +75,10 @@ const SMART_VIEW_DEFAULT_SORTS: Partial<Record<SmartView, ViewSort>> = {
|
|
|
73
75
|
largest: { sort: "size", direction: "desc" },
|
|
74
76
|
};
|
|
75
77
|
|
|
78
|
+
function isMissingAlt(asset: Pick<MediaAsset, "mimetype" | "alt">): boolean {
|
|
79
|
+
return isDescribableImage(asset.mimetype) && !asset.alt?.trim();
|
|
80
|
+
}
|
|
81
|
+
|
|
76
82
|
const SMART_VIEW_FILTERS: Record<SmartView, SmartViewFilter> = {
|
|
77
83
|
recent: (assets) =>
|
|
78
84
|
[...assets]
|
|
@@ -82,26 +88,12 @@ const SMART_VIEW_FILTERS: Record<SmartView, SmartViewFilter> = {
|
|
|
82
88
|
.slice(0, RECENT_VIEW_LIMIT),
|
|
83
89
|
starred: (assets, { starredAssetIds }) =>
|
|
84
90
|
assets.filter((asset) => starredAssetIds.has(asset._id)),
|
|
85
|
-
"missing-alt": (assets) =>
|
|
86
|
-
assets.filter(
|
|
87
|
-
(asset) => isDescribableImage(asset.mimetype) && !asset.alt?.trim(),
|
|
88
|
-
),
|
|
91
|
+
"missing-alt": (assets) => assets.filter(isMissingAlt),
|
|
89
92
|
largest: (assets) => assets,
|
|
90
93
|
public: (assets, { visibilityOf }) =>
|
|
91
94
|
assets.filter((asset) => visibilityOf(asset) === "public"),
|
|
92
95
|
};
|
|
93
96
|
|
|
94
|
-
function readableAssets(context: MediaRequestContext): Promise<MediaAsset[]> {
|
|
95
|
-
return loadAssetsInFolders(context.assetModel, [...context.access.readable]);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function countMissingAlt(assets: MediaAsset[]): number {
|
|
99
|
-
return SMART_VIEW_FILTERS["missing-alt"](assets, {
|
|
100
|
-
starredAssetIds: new Set(),
|
|
101
|
-
visibilityOf: () => "private",
|
|
102
|
-
}).length;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
97
|
function folderPathName(
|
|
106
98
|
context: MediaRequestContext,
|
|
107
99
|
folder: MediaFolder | undefined,
|
|
@@ -154,7 +146,7 @@ function treeViewScope(
|
|
|
154
146
|
}
|
|
155
147
|
|
|
156
148
|
function countViews(
|
|
157
|
-
assets:
|
|
149
|
+
assets: AssetCountFields[],
|
|
158
150
|
starred: StarredTargets,
|
|
159
151
|
scope: Set<string> | undefined,
|
|
160
152
|
) {
|
|
@@ -165,7 +157,7 @@ function countViews(
|
|
|
165
157
|
starred:
|
|
166
158
|
scoped.filter((asset) => starred.assetIds.has(asset._id)).length +
|
|
167
159
|
starredFolders,
|
|
168
|
-
missingAlt:
|
|
160
|
+
missingAlt: scoped.filter(isMissingAlt).length,
|
|
169
161
|
};
|
|
170
162
|
}
|
|
171
163
|
|
|
@@ -198,7 +190,7 @@ export class MediaLibraryController extends MediaApiController {
|
|
|
198
190
|
async tree() {
|
|
199
191
|
const context = await this.resolveContext();
|
|
200
192
|
const [assets, starred] = await Promise.all([
|
|
201
|
-
|
|
193
|
+
loadAssetCountFields(context.assetModel, [...context.access.readable]),
|
|
202
194
|
loadStarredTargets(this.owner(context)),
|
|
203
195
|
]);
|
|
204
196
|
const stats = computeFolderStats(context.folders, assets);
|
|
@@ -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({
|