@antelopejs/dms-media 0.6.1 → 0.7.0
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 +18 -3
- package/dist/acl/entries.js +1 -2
- package/dist/acl/entries.js.map +1 -1
- package/dist/bindings.js +1 -3
- package/dist/bindings.js.map +1 -1
- package/dist/declared/folders.js +3 -2
- package/dist/declared/folders.js.map +1 -1
- package/dist/declared/records.d.ts +2 -2
- package/dist/declared/records.js +3 -2
- package/dist/declared/records.js.map +1 -1
- package/dist/derivatives.js +9 -6
- package/dist/derivatives.js.map +1 -1
- package/dist/guards.d.ts +4 -0
- package/dist/guards.js +19 -0
- package/dist/guards.js.map +1 -0
- package/dist/library/activity.js +7 -5
- package/dist/library/activity.js.map +1 -1
- package/dist/library/batches.js +6 -3
- package/dist/library/batches.js.map +1 -1
- package/dist/library/events.js +4 -4
- package/dist/library/events.js.map +1 -1
- package/dist/library/module-readout.js +5 -2
- package/dist/library/module-readout.js.map +1 -1
- package/dist/library/realtime.js.map +1 -1
- package/dist/pages/activity.js +1 -1
- package/dist/pages/activity.js.map +1 -1
- package/dist/routes/media/assets.d.ts +1 -1
- package/dist/routes/media/assets.js +5 -5
- package/dist/routes/media/assets.js.map +1 -1
- package/dist/routes/media/bulk.js +17 -13
- package/dist/routes/media/bulk.js.map +1 -1
- package/dist/routes/media/delivery-headers.js +9 -9
- package/dist/routes/media/delivery-headers.js.map +1 -1
- package/dist/routes/media/delivery-stream.js.map +1 -1
- package/dist/routes/media/delivery.js.map +1 -1
- package/dist/routes/media/manage.js.map +1 -1
- package/dist/routes/media/transform.js +13 -8
- package/dist/routes/media/transform.js.map +1 -1
- package/dist/test/antelope.test.js +13 -12
- package/dist/test/antelope.test.js.map +1 -1
- package/dist/test/helpers/folders.d.ts +27 -0
- package/dist/test/helpers/folders.js +15 -0
- package/dist/test/helpers/folders.js.map +1 -1
- package/dist/test/helpers/pages.js +10 -6
- package/dist/test/helpers/pages.js.map +1 -1
- package/dist/test/helpers/permissions-world.d.ts +98 -0
- package/dist/test/helpers/permissions-world.js +205 -0
- package/dist/test/helpers/permissions-world.js.map +1 -0
- package/dist/test/helpers/prototype.d.ts +1 -0
- package/dist/test/helpers/prototype.js +11 -0
- package/dist/test/helpers/prototype.js.map +1 -0
- package/dist/test/integration/derivative-sweep-query.test.js +13 -16
- package/dist/test/integration/derivative-sweep-query.test.js.map +1 -1
- package/dist/test/integration/folder-query.test.js +5 -9
- package/dist/test/integration/folder-query.test.js.map +1 -1
- package/dist/test/integration/media-bindings.test.js +2 -2
- package/dist/test/integration/media-bindings.test.js.map +1 -1
- package/dist/test/integration/media-cleanup.test.js +14 -17
- package/dist/test/integration/media-cleanup.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 +7 -5
- package/dist/test/integration/media-delivery-editing.test.js.map +1 -1
- package/dist/test/integration/media-delivery.test.js +19 -5
- package/dist/test/integration/media-delivery.test.js.map +1 -1
- package/dist/test/integration/media-explorer-writes.test.js +2 -2
- package/dist/test/integration/media-explorer-writes.test.js.map +1 -1
- package/dist/test/integration/media-guards.test.js +18 -7
- package/dist/test/integration/media-guards.test.js.map +1 -1
- package/dist/test/integration/media-library.test.js +1 -1
- package/dist/test/integration/media-library.test.js.map +1 -1
- package/dist/test/integration/media-linked-subfolders.test.js +5 -5
- package/dist/test/integration/media-linked-subfolders.test.js.map +1 -1
- package/dist/test/integration/media-member-access.test.js +2 -5
- package/dist/test/integration/media-member-access.test.js.map +1 -1
- package/dist/test/integration/media-permissions.test.js +142 -473
- package/dist/test/integration/media-permissions.test.js.map +1 -1
- package/dist/test/integration/media-project-field.test.js +3 -5
- package/dist/test/integration/media-project-field.test.js.map +1 -1
- package/dist/test/integration/media-search-query.test.js +11 -16
- package/dist/test/integration/media-search-query.test.js.map +1 -1
- package/dist/test/integration/media-storage-origin-unreachable.test.js +1 -0
- package/dist/test/integration/media-storage-origin-unreachable.test.js.map +1 -1
- package/dist/test/integration/media-upload-policy.test.js +2 -2
- package/dist/test/integration/media-upload-policy.test.js.map +1 -1
- package/dist/test/integration/permissions-management.d.ts +2 -0
- package/dist/test/integration/permissions-management.js +189 -0
- package/dist/test/integration/permissions-management.js.map +1 -0
- package/dist/test/unit/acl/entries.test.js +2 -1
- package/dist/test/unit/acl/entries.test.js.map +1 -1
- package/dist/test/unit/acl/resolver.test.js +10 -3
- package/dist/test/unit/acl/resolver.test.js.map +1 -1
- package/dist/test/unit/library/fixtures.d.ts +1 -1
- package/dist/test/unit/library/fixtures.js +6 -1
- package/dist/test/unit/library/fixtures.js.map +1 -1
- package/dist/test/unit/library/library.test.js +0 -1
- package/dist/test/unit/library/library.test.js.map +1 -1
- package/dist/test/unit/library/realtime.test.js.map +1 -1
- package/dist/test/unit/library/search-facets.test.js +2 -2
- package/dist/test/unit/library/search-facets.test.js.map +1 -1
- package/dist/test/unit/pages/toolbar.test.js +24 -7
- package/dist/test/unit/pages/toolbar.test.js.map +1 -1
- package/dist/test/unit/routes/dto.test.js +7 -6
- package/dist/test/unit/routes/dto.test.js.map +1 -1
- package/dist/test/unit/routes/file-page.test.js +5 -7
- package/dist/test/unit/routes/file-page.test.js.map +1 -1
- package/dist/test/unit/routes/preset-row.test.js +2 -1
- package/dist/test/unit/routes/preset-row.test.js.map +1 -1
- package/dist/transform.js +6 -6
- package/dist/transform.js.map +1 -1
- package/dist/upload-checks.d.ts +8 -2
- package/dist/upload-checks.js.map +1 -1
- package/dist/upload-policy.js +8 -8
- package/dist/upload-policy.js.map +1 -1
- package/dist/validation/declared.schema.js +14 -8
- package/dist/validation/declared.schema.js.map +1 -1
- package/dist/validation/media.schema.d.ts +1 -1
- package/dist/validation/media.schema.js +2 -2
- package/dist/validation/media.schema.js.map +1 -1
- package/frontend-vue/app/build/imageEditor/editorShapes.ts +118 -0
- package/frontend-vue/app/build/imageEditor/useEditorSaving.ts +87 -0
- package/frontend-vue/app/build/library/libraryActions.ts +444 -0
- package/frontend-vue/app/build/library/libraryCore.ts +137 -0
- package/frontend-vue/app/components/FirstRun.vue +2 -1
- package/frontend-vue/app/components/ImageEditor.vue +22 -179
- package/frontend-vue/app/components/dialogs/DestinationDialog.vue +3 -3
- package/frontend-vue/app/components/field/FieldAltPopover.vue +2 -1
- package/frontend-vue/app/composables/library/useMediaLibrary.ts +3 -575
- package/frontend-vue/app/composables/useAssetFieldUploads.ts +9 -1
- package/frontend-vue/app/composables/useAssetLink.ts +33 -13
- package/frontend-vue/app/composables/useFileDetails.ts +6 -5
- package/frontend-vue/app/composables/useMediaApi.ts +21 -5
- package/frontend-vue/app/composables/useUploadFailureText.ts +24 -5
- package/frontend-vue/app/composables/useUploadQueue.ts +178 -44
- package/frontend-vue/app/composables/useUploadToasts.ts +81 -19
- package/frontend-vue/build/backend-boundary.ts +122 -0
- package/frontend-vue/dms.frontend.build.ts +3 -0
- package/frontend-vue/eslint.config.mjs +13 -0
- package/frontend-vue/package.json +4 -2
- package/frontend-vue/pnpm-lock.yaml +217 -61
- package/frontend-vue/tests/api-error-presentation.test.ts +183 -0
- package/frontend-vue/tests/backend-boundary.test.ts +203 -0
- package/frontend-vue/tests/fixtures/serverRender.ts +1 -1
- package/frontend-vue/tests/mediaPreviews.test.ts +39 -0
- package/package.json +5 -11
- package/skills/dms-media/SKILL.md +3 -2
- package/skills/dms-media/cases.json +38 -0
- package/src/acl/entries.ts +6 -4
- package/src/bindings.ts +3 -3
- package/src/declared/folders.ts +3 -3
- package/src/declared/records.ts +9 -8
- package/src/derivatives.ts +10 -6
- package/src/guards.ts +19 -0
- package/src/library/activity.ts +17 -9
- package/src/library/batches.ts +12 -9
- package/src/library/events.ts +7 -4
- package/src/library/module-readout.ts +6 -2
- package/src/library/realtime.ts +5 -1
- package/src/library/zip.ts +1 -1
- package/src/pages/activity.ts +6 -2
- package/src/routes/media/assets.ts +4 -3
- package/src/routes/media/bulk.ts +16 -14
- package/src/routes/media/delivery-headers.ts +9 -12
- package/src/routes/media/delivery-stream.ts +3 -2
- package/src/routes/media/delivery.ts +4 -2
- package/src/routes/media/manage.ts +4 -6
- package/src/routes/media/transform.ts +27 -23
- package/src/test/antelope.test.ts +21 -17
- package/src/test/helpers/folders.ts +22 -0
- package/src/test/helpers/pages.ts +12 -5
- package/src/test/helpers/permissions-world.ts +326 -0
- package/src/test/helpers/prototype.ts +12 -0
- package/src/test/integration/derivative-sweep-query.test.ts +19 -21
- package/src/test/integration/folder-query.test.ts +11 -11
- package/src/test/integration/media-bindings.test.ts +7 -7
- package/src/test/integration/media-cleanup.test.ts +25 -37
- package/src/test/integration/media-declared-content.test.ts +18 -19
- package/src/test/integration/media-delivery-editing.test.ts +11 -7
- package/src/test/integration/media-delivery.test.ts +29 -8
- package/src/test/integration/media-explorer-writes.test.ts +2 -7
- package/src/test/integration/media-guards.test.ts +21 -7
- package/src/test/integration/media-library.test.ts +1 -1
- package/src/test/integration/media-linked-subfolders.test.ts +11 -20
- package/src/test/integration/media-member-access.test.ts +5 -9
- package/src/test/integration/media-permissions.test.ts +56 -570
- package/src/test/integration/media-project-field.test.ts +5 -7
- package/src/test/integration/media-search-query.test.ts +16 -20
- package/src/test/integration/media-storage-origin-unreachable.test.ts +3 -2
- package/src/test/integration/media-upload-policy.test.ts +2 -8
- package/src/test/integration/permissions-management.ts +292 -0
- package/src/test/unit/acl/entries.test.ts +2 -1
- package/src/test/unit/acl/resolver.test.ts +19 -7
- package/src/test/unit/library/fixtures.ts +9 -3
- package/src/test/unit/library/library.test.ts +1 -7
- package/src/test/unit/library/realtime.test.ts +1 -1
- package/src/test/unit/library/search-facets.test.ts +2 -2
- package/src/test/unit/pages/toolbar.test.ts +42 -17
- package/src/test/unit/routes/dto.test.ts +7 -6
- package/src/test/unit/routes/file-page.test.ts +10 -9
- package/src/test/unit/routes/preset-row.test.ts +2 -2
- package/src/transform.ts +6 -6
- package/src/upload-checks.ts +12 -3
- package/src/upload-policy.ts +8 -8
- package/src/validation/declared.schema.ts +17 -12
- package/src/validation/media.schema.ts +6 -6
- package/frontend-vue/tests/engines.test.ts +0 -20
- package/frontend-vue/tests/locales.test.ts +0 -61
package/src/derivatives.ts
CHANGED
|
@@ -32,7 +32,8 @@ export class UnreadableImageError extends Error {}
|
|
|
32
32
|
|
|
33
33
|
interface GenerationFailure {
|
|
34
34
|
failedAt: number;
|
|
35
|
-
|
|
35
|
+
/** Set when the stored bytes could not be decoded: that error is rethrown while the failure is remembered. */
|
|
36
|
+
unreadable?: UnreadableImageError;
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
const generationLocks = new Map<string, Promise<string>>();
|
|
@@ -241,15 +242,15 @@ export function partitionDerivatives(
|
|
|
241
242
|
return { fresh, stale };
|
|
242
243
|
}
|
|
243
244
|
|
|
244
|
-
function failureRetryDelay(
|
|
245
|
-
return
|
|
245
|
+
function failureRetryDelay(failure: GenerationFailure): number {
|
|
246
|
+
return failure.unreadable
|
|
246
247
|
? UNREADABLE_IMAGE_RETRY_MS
|
|
247
248
|
: GENERATION_FAILURE_RETRY_MS;
|
|
248
249
|
}
|
|
249
250
|
|
|
250
251
|
function pruneExpiredGenerationFailures(now: number): void {
|
|
251
252
|
for (const [lockKey, failure] of generationFailures) {
|
|
252
|
-
if (now - failure.failedAt >= failureRetryDelay(failure
|
|
253
|
+
if (now - failure.failedAt >= failureRetryDelay(failure)) {
|
|
253
254
|
generationFailures.delete(lockKey);
|
|
254
255
|
}
|
|
255
256
|
}
|
|
@@ -259,7 +260,7 @@ function assertNoRecentGenerationFailure(lockKey: string): void {
|
|
|
259
260
|
pruneExpiredGenerationFailures(Date.now());
|
|
260
261
|
const failure = generationFailures.get(lockKey);
|
|
261
262
|
if (!failure) return;
|
|
262
|
-
if (failure.
|
|
263
|
+
if (failure.unreadable) throw failure.unreadable;
|
|
263
264
|
throw new Error("Derivative generation recently failed");
|
|
264
265
|
}
|
|
265
266
|
|
|
@@ -284,7 +285,10 @@ export async function ensureDerivative(
|
|
|
284
285
|
return storageKey;
|
|
285
286
|
})
|
|
286
287
|
.catch((error: unknown) => {
|
|
287
|
-
generationFailures.set(lockKey, {
|
|
288
|
+
generationFailures.set(lockKey, {
|
|
289
|
+
failedAt: Date.now(),
|
|
290
|
+
unreadable: error instanceof UnreadableImageError ? error : undefined,
|
|
291
|
+
});
|
|
288
292
|
throw error;
|
|
289
293
|
})
|
|
290
294
|
.finally(() => generationLocks.delete(lockKey));
|
package/src/guards.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Whether `value` is a string. */
|
|
2
|
+
export function isString(value: unknown): value is string {
|
|
3
|
+
return typeof value === "string";
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/** Whether `value` is a non-null object, arrays included. */
|
|
7
|
+
export function isObject(value: unknown): value is object {
|
|
8
|
+
return typeof value === "object" && value !== null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Whether `value` can carry properties of its own: a non-null object or a function. */
|
|
12
|
+
export function isObjectLike(value: unknown): value is object {
|
|
13
|
+
return isObject(value) || isCallable(value);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Whether `typeof` reports `value` as a function: classes included, as TypeScript narrows it. */
|
|
17
|
+
export function isCallable(value: unknown): value is Function {
|
|
18
|
+
return typeof value === "function";
|
|
19
|
+
}
|
package/src/library/activity.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ActivityFeedItem } from "@antelopejs/interface-dms/base/activity-feed";
|
|
2
|
-
import type { ComposedTextParam } from "@antelopejs/interface-dms/base/types";
|
|
3
2
|
import type { Tone } from "@antelopejs/interface-dms/base/types/tone";
|
|
4
3
|
import type { MediaEvent, MediaFolder } from "../db";
|
|
5
4
|
import { countParam } from "./composed-text";
|
|
@@ -67,6 +66,11 @@ const EVENT_PRESENTATIONS: Record<MediaEventKind, EventPresentation> = {
|
|
|
67
66
|
"folder.visibility": { icon: "i-ph-globe", tone: "success" },
|
|
68
67
|
};
|
|
69
68
|
|
|
69
|
+
/** Whether a stored event kind is one this release records and presents. */
|
|
70
|
+
function isMediaEventKind(kind: string): kind is MediaEventKind {
|
|
71
|
+
return Object.hasOwn(EVENT_PRESENTATIONS, kind);
|
|
72
|
+
}
|
|
73
|
+
|
|
70
74
|
const NEUTRAL_PRESENTATION: EventPresentation = {
|
|
71
75
|
icon: "i-ph-clock-counter-clockwise",
|
|
72
76
|
tone: "neutral",
|
|
@@ -163,9 +167,12 @@ function visibleDetails(details: MediaEventDetails): MediaEventDetails {
|
|
|
163
167
|
);
|
|
164
168
|
}
|
|
165
169
|
|
|
166
|
-
|
|
170
|
+
/** The parameters of a feed item's title and meta texts. */
|
|
171
|
+
type FeedParams = NonNullable<ActivityFeedItem["params"]>;
|
|
172
|
+
|
|
173
|
+
function toParams(entry: ActivityEntry): FeedParams {
|
|
167
174
|
const details = visibleDetails(readEventDetails(entry.event));
|
|
168
|
-
const params:
|
|
175
|
+
const params: FeedParams = {
|
|
169
176
|
actor: entry.event.actorName,
|
|
170
177
|
name: entry.event.targetName,
|
|
171
178
|
count: countParam(entry.count),
|
|
@@ -186,7 +193,7 @@ function titleSuffix(event: MediaEvent): string {
|
|
|
186
193
|
return `_${visibility.replace(VISIBILITY_KEY_PREFIX, "")}`;
|
|
187
194
|
}
|
|
188
195
|
|
|
189
|
-
function batchParams(event: MediaEvent):
|
|
196
|
+
function batchParams(event: MediaEvent): FeedParams {
|
|
190
197
|
const details = readEventDetails(event);
|
|
191
198
|
return {
|
|
192
199
|
uploaded: countParam(event.count ?? 0),
|
|
@@ -200,11 +207,12 @@ function presentEntry(
|
|
|
200
207
|
context: ActivityContext,
|
|
201
208
|
): ActivityFeedItem {
|
|
202
209
|
const { event } = entry;
|
|
203
|
-
const kind = event
|
|
210
|
+
const { kind } = event;
|
|
211
|
+
const known = isMediaEventKind(kind) ? kind : undefined;
|
|
204
212
|
const isReport = kind === BATCH_REPORT_KIND;
|
|
205
213
|
const presentation = isReport
|
|
206
214
|
? BATCH_PRESENTATIONS[batchOutcome(event)]
|
|
207
|
-
: (EVENT_PRESENTATIONS[
|
|
215
|
+
: ((known && EVENT_PRESENTATIONS[known]) ?? NEUTRAL_PRESENTATION);
|
|
208
216
|
const path = folderPath(subjectFolderId(event), context.foldersById);
|
|
209
217
|
const isGone = Boolean(
|
|
210
218
|
event.assetId && context.deletedAssetIds.has(event.assetId),
|
|
@@ -300,9 +308,9 @@ function foldBulkActions(entries: ActivityEntry[]): ActivityEntry[] {
|
|
|
300
308
|
|
|
301
309
|
function deletedAssets(events: MediaEvent[]): Set<string> {
|
|
302
310
|
return new Set(
|
|
303
|
-
events
|
|
304
|
-
|
|
305
|
-
|
|
311
|
+
events.flatMap((event) =>
|
|
312
|
+
event.kind === "asset.delete" && event.assetId ? [event.assetId] : [],
|
|
313
|
+
),
|
|
306
314
|
);
|
|
307
315
|
}
|
|
308
316
|
|
package/src/library/batches.ts
CHANGED
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
readEventDetails,
|
|
9
9
|
UPLOAD_KIND,
|
|
10
10
|
} from "./events";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { isString } from "../guards";
|
|
11
13
|
|
|
12
14
|
export interface UploadBatchRow {
|
|
13
15
|
_id: string;
|
|
@@ -33,10 +35,11 @@ type BatchAttention = "yes" | "no";
|
|
|
33
35
|
/** How long a failed upload keeps asking for attention. */
|
|
34
36
|
export const FAILURE_WINDOW_MS = 24 * 60 * 60 * 1000;
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
name: string
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const uploadFailuresSchema = z.array(
|
|
39
|
+
z.object({ name: z.string(), reason: z.string().optional() }),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
type UploadFailures = z.infer<typeof uploadFailuresSchema>;
|
|
40
43
|
|
|
41
44
|
const HISTORY_TEXTS = "dms_media.uploads.history";
|
|
42
45
|
const FAILURES_SHOWN = 3;
|
|
@@ -51,7 +54,7 @@ interface BatchAccumulator {
|
|
|
51
54
|
by: string;
|
|
52
55
|
files: number;
|
|
53
56
|
failed: number;
|
|
54
|
-
failures:
|
|
57
|
+
failures: UploadFailures;
|
|
55
58
|
size: number;
|
|
56
59
|
finishedAt: Date;
|
|
57
60
|
reportedAt?: Date;
|
|
@@ -71,12 +74,12 @@ function newBatch(key: string, event: MediaEvent): BatchAccumulator {
|
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
/** The files a batch report names as failed, with their reasons. */
|
|
74
|
-
function readBatchFailures(event: MediaEvent):
|
|
77
|
+
function readBatchFailures(event: MediaEvent): UploadFailures {
|
|
75
78
|
const raw = readEventDetails(event).failures;
|
|
76
|
-
if (
|
|
79
|
+
if (!isString(raw)) return [];
|
|
77
80
|
try {
|
|
78
|
-
const parsed
|
|
79
|
-
return
|
|
81
|
+
const parsed = uploadFailuresSchema.safeParse(JSON.parse(raw));
|
|
82
|
+
return parsed.success ? parsed.data : [];
|
|
80
83
|
} catch {
|
|
81
84
|
return [];
|
|
82
85
|
}
|
package/src/library/events.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { GetModel } from "@antelopejs/interface-database-decorators";
|
|
|
2
2
|
import { Logging } from "@antelopejs/interface-core/logging";
|
|
3
3
|
import type { User } from "@antelopejs/interface-dms/auth/db";
|
|
4
4
|
import { type MediaEvent, MediaEventModel } from "../db";
|
|
5
|
+
import { z } from "zod";
|
|
5
6
|
import { announceLibraryChange, UPLOAD_ANNOUNCE_WINDOW_MS } from "./realtime";
|
|
6
7
|
|
|
7
8
|
const MEDIA_EVENT_KINDS = [
|
|
@@ -25,6 +26,10 @@ export type MediaEventKind = (typeof MEDIA_EVENT_KINDS)[number];
|
|
|
25
26
|
|
|
26
27
|
export type MediaEventDetails = Record<string, string | number>;
|
|
27
28
|
|
|
29
|
+
const eventDetailsSchema: z.ZodType<MediaEventDetails> = z.record(
|
|
30
|
+
z.union([z.string(), z.number()]),
|
|
31
|
+
);
|
|
32
|
+
|
|
28
33
|
export interface MediaEventInput {
|
|
29
34
|
kind: MediaEventKind;
|
|
30
35
|
targetName: string;
|
|
@@ -77,10 +82,8 @@ export async function recordMediaEvent(
|
|
|
77
82
|
export function readEventDetails(event: MediaEvent): MediaEventDetails {
|
|
78
83
|
if (!event.json_details) return {};
|
|
79
84
|
try {
|
|
80
|
-
const parsed
|
|
81
|
-
return parsed
|
|
82
|
-
? (parsed as MediaEventDetails)
|
|
83
|
-
: {};
|
|
85
|
+
const parsed = eventDetailsSchema.safeParse(JSON.parse(event.json_details));
|
|
86
|
+
return parsed.success ? parsed.data : {};
|
|
84
87
|
} catch {
|
|
85
88
|
return {};
|
|
86
89
|
}
|
|
@@ -13,6 +13,7 @@ import { loadAssetsInFolders } from "./listing";
|
|
|
13
13
|
import { storedSize } from "./overview";
|
|
14
14
|
import { isDescribableImage } from "./type-groups";
|
|
15
15
|
import { loadUploadHistoryEvents } from "./upload-history";
|
|
16
|
+
import { isObject, isString } from "../guards";
|
|
16
17
|
|
|
17
18
|
const TEXTS = "$dms_media.readout";
|
|
18
19
|
const DEFAULT_LANGUAGE = "en";
|
|
@@ -38,8 +39,11 @@ export function readModuleVersion(): string | undefined {
|
|
|
38
39
|
const manifest: unknown = JSON.parse(
|
|
39
40
|
readFileSync(PACKAGE_MANIFEST, "utf8"),
|
|
40
41
|
);
|
|
41
|
-
const version =
|
|
42
|
-
|
|
42
|
+
const version =
|
|
43
|
+
isObject(manifest) && "version" in manifest
|
|
44
|
+
? manifest.version
|
|
45
|
+
: undefined;
|
|
46
|
+
return isString(version) ? version : undefined;
|
|
43
47
|
} catch {
|
|
44
48
|
return undefined;
|
|
45
49
|
}
|
package/src/library/realtime.ts
CHANGED
|
@@ -13,9 +13,13 @@ let pendingDueAt = 0;
|
|
|
13
13
|
let pendingChanges = 0;
|
|
14
14
|
let version = 0;
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Publishes the changes waiting to be announced as one message whose
|
|
18
|
+
* `payload.count` says how many it stands for: a paused page counts that many
|
|
19
|
+
* missed changes, not one per announcement.
|
|
20
|
+
*/
|
|
16
21
|
async function publishNow(): Promise<void> {
|
|
17
22
|
pending = undefined;
|
|
18
|
-
// A paused page counts `payload.count` as that many missed changes, not one per announcement.
|
|
19
23
|
const count = pendingChanges;
|
|
20
24
|
pendingChanges = 0;
|
|
21
25
|
try {
|
package/src/library/zip.ts
CHANGED
|
@@ -23,7 +23,7 @@ interface CentralEntry {
|
|
|
23
23
|
|
|
24
24
|
export type ZipChunkWriter = (chunk: Buffer) => void;
|
|
25
25
|
|
|
26
|
-
function dosDateTime(date: Date):
|
|
26
|
+
function dosDateTime(date: Date): Pick<CentralEntry, "time" | "date"> {
|
|
27
27
|
const year = Math.max(date.getFullYear(), DOS_EPOCH_YEAR);
|
|
28
28
|
return {
|
|
29
29
|
time:
|
package/src/pages/activity.ts
CHANGED
|
@@ -4,7 +4,11 @@ import { DefaultLayout } from "@antelopejs/interface-dms/base/layouts";
|
|
|
4
4
|
import { Tab } from "@antelopejs/interface-dms/base/tab";
|
|
5
5
|
import { PageController, RegisterPage } from "@antelopejs/interface-dms/page";
|
|
6
6
|
import { MEDIA_LIBRARY_TOPIC } from "../constants";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
ACTIVITY_FILTERS,
|
|
9
|
+
type ActivityFilter,
|
|
10
|
+
isActivityFilter,
|
|
11
|
+
} from "../library/activity";
|
|
8
12
|
import { libraryCategory, MEDIA_MODULE_ID } from "./module";
|
|
9
13
|
import { blockMeta } from "./texts";
|
|
10
14
|
import { MEDIA_LIVE, mediaPageToolbar } from "./toolbar";
|
|
@@ -14,7 +18,7 @@ const FEED_LENGTH = 50;
|
|
|
14
18
|
const SKELETON_ROWS = 8;
|
|
15
19
|
const ALL_SLOT = "all";
|
|
16
20
|
|
|
17
|
-
const FILTERS = Object.keys(ACTIVITY_FILTERS)
|
|
21
|
+
const FILTERS = Object.keys(ACTIVITY_FILTERS).filter(isActivityFilter);
|
|
18
22
|
|
|
19
23
|
function feed(filter?: ActivityFilter) {
|
|
20
24
|
const query = filter ? `&type=${filter}` : "";
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
Delete,
|
|
10
10
|
Get,
|
|
11
11
|
JSONBody,
|
|
12
|
+
MultiParameter,
|
|
12
13
|
Parameter,
|
|
13
14
|
Post,
|
|
14
15
|
} from "@antelopejs/interface-api";
|
|
@@ -131,9 +132,9 @@ export class MediaAssetsController extends MediaApiController {
|
|
|
131
132
|
return { assets, truncated };
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
@
|
|
135
|
-
async previews(@
|
|
136
|
-
const { ids } = parseBody(
|
|
135
|
+
@Get("/previews")
|
|
136
|
+
async previews(@MultiParameter("ids", "query") queryIds: string[]) {
|
|
137
|
+
const { ids } = parseBody({ ids: queryIds }, previewIdsSchema);
|
|
137
138
|
const context = await this.resolveContext();
|
|
138
139
|
const { presets } = getMediaConfig();
|
|
139
140
|
const thumb = presets.get(THUMB_PRESET_ID);
|
package/src/routes/media/bulk.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
type MediaRequestContext,
|
|
24
24
|
requireFolderRight,
|
|
25
25
|
} from "./context";
|
|
26
|
+
import { isString } from "../../guards";
|
|
26
27
|
|
|
27
28
|
const HTTP_OK = 200;
|
|
28
29
|
const HTTP_INTERNAL_ERROR = 500;
|
|
@@ -55,19 +56,6 @@ export interface BulkOutcome {
|
|
|
55
56
|
refused: BulkRefusal[];
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
function describeFailure(id: string, error: unknown): BulkRefusal {
|
|
59
|
-
if (error instanceof HTTPResult) {
|
|
60
|
-
const body: unknown = error.getBody();
|
|
61
|
-
const message = typeof body === "string" ? body : JSON.stringify(body);
|
|
62
|
-
return { id, status: error.getStatus(), message: message ?? "" };
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
id,
|
|
66
|
-
status: HTTP_INTERNAL_ERROR,
|
|
67
|
-
message: error instanceof Error ? error.message : String(error),
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
59
|
/** Runs one operation per asset in order, keeping going past the ones refused. */
|
|
72
60
|
async function applyToEach(
|
|
73
61
|
context: MediaRequestContext,
|
|
@@ -81,7 +69,21 @@ async function applyToEach(
|
|
|
81
69
|
await operation(context, asset);
|
|
82
70
|
outcome.done.push(id);
|
|
83
71
|
} catch (error) {
|
|
84
|
-
|
|
72
|
+
if (error instanceof HTTPResult) {
|
|
73
|
+
const body: unknown = error.getBody();
|
|
74
|
+
const message = isString(body) ? body : JSON.stringify(body);
|
|
75
|
+
outcome.refused.push({
|
|
76
|
+
id,
|
|
77
|
+
status: error.getStatus(),
|
|
78
|
+
message: message ?? "",
|
|
79
|
+
});
|
|
80
|
+
} else {
|
|
81
|
+
outcome.refused.push({
|
|
82
|
+
id,
|
|
83
|
+
status: HTTP_INTERNAL_ERROR,
|
|
84
|
+
message: error instanceof Error ? error.message : String(error),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
85
87
|
}
|
|
86
88
|
}
|
|
87
89
|
return outcome;
|
|
@@ -12,13 +12,13 @@ type Disposition = "inline" | "attachment";
|
|
|
12
12
|
* Types a browser would run as a page from the API origin. SVG stays inline
|
|
13
13
|
* (it is an image) but sandboxed; documents are only ever downloaded.
|
|
14
14
|
*/
|
|
15
|
-
const ACTIVE_CONTENT_DISPOSITIONS
|
|
16
|
-
"image/svg+xml"
|
|
17
|
-
"text/html"
|
|
18
|
-
"application/xhtml+xml"
|
|
19
|
-
"text/xml"
|
|
20
|
-
"application/xml"
|
|
21
|
-
|
|
15
|
+
const ACTIVE_CONTENT_DISPOSITIONS = new Map<string, Disposition>([
|
|
16
|
+
["image/svg+xml", "inline"],
|
|
17
|
+
["text/html", "attachment"],
|
|
18
|
+
["application/xhtml+xml", "attachment"],
|
|
19
|
+
["text/xml", "attachment"],
|
|
20
|
+
["application/xml", "attachment"],
|
|
21
|
+
]);
|
|
22
22
|
|
|
23
23
|
export function normalizedMimetype(mimetype: string): string {
|
|
24
24
|
const essence = mimetype
|
|
@@ -29,10 +29,7 @@ export function normalizedMimetype(mimetype: string): string {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export function isActiveContent(mimetype: string): boolean {
|
|
32
|
-
return
|
|
33
|
-
ACTIVE_CONTENT_DISPOSITIONS,
|
|
34
|
-
normalizedMimetype(mimetype),
|
|
35
|
-
);
|
|
32
|
+
return ACTIVE_CONTENT_DISPOSITIONS.has(normalizedMimetype(mimetype));
|
|
36
33
|
}
|
|
37
34
|
|
|
38
35
|
function asciiFilename(filename: string): string {
|
|
@@ -47,7 +44,7 @@ function asciiFilename(filename: string): string {
|
|
|
47
44
|
|
|
48
45
|
export function contentDisposition(mimetype: string, filename: string): string {
|
|
49
46
|
const disposition =
|
|
50
|
-
ACTIVE_CONTENT_DISPOSITIONS
|
|
47
|
+
ACTIVE_CONTENT_DISPOSITIONS.get(normalizedMimetype(mimetype)) ?? "inline";
|
|
51
48
|
const extended = encodeURIComponent(filename).replace(
|
|
52
49
|
/['()*]/g,
|
|
53
50
|
(character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`,
|
|
@@ -79,6 +79,9 @@ function addRepresentationHeaders(
|
|
|
79
79
|
* or the attachment disposition these files need, every other file is
|
|
80
80
|
* redirected to the storage so its bandwidth never goes through Node.
|
|
81
81
|
* Byte ranges are not served: these files are small and rendered whole.
|
|
82
|
+
* The bytes are read from the storage itself, not through its read URL: that
|
|
83
|
+
* URL is the public origin, which the server may not reach (private network,
|
|
84
|
+
* egress policy).
|
|
82
85
|
*/
|
|
83
86
|
export async function streamStoredFile(
|
|
84
87
|
ctx: RequestContext,
|
|
@@ -92,8 +95,6 @@ export async function streamStoredFile(
|
|
|
92
95
|
response.setBody("");
|
|
93
96
|
return response;
|
|
94
97
|
}
|
|
95
|
-
// Read from the storage itself: its read URL is the public origin, which
|
|
96
|
-
// the server may not reach (private network, egress policy).
|
|
97
98
|
const stored = await ReadFile(file.storageKey, file.storage).catch(
|
|
98
99
|
() => undefined,
|
|
99
100
|
);
|
|
@@ -312,6 +312,10 @@ export class MediaDeliveryController extends Controller("/media") {
|
|
|
312
312
|
return deliverAsset(ctx, resolved);
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
+
/**
|
|
316
|
+
* Resolves (and authorizes) the asset before it touches the preset, so an
|
|
317
|
+
* unauthenticated caller cannot probe which preset IDs are configured.
|
|
318
|
+
*/
|
|
315
319
|
@Get("/:assetId/:presetId/:filename")
|
|
316
320
|
async deliverDerivative(
|
|
317
321
|
@Context() ctx: RequestContext,
|
|
@@ -320,8 +324,6 @@ export class MediaDeliveryController extends Controller("/media") {
|
|
|
320
324
|
@IfAuthUser() user?: User,
|
|
321
325
|
) {
|
|
322
326
|
assertNamedSegment(ctx);
|
|
323
|
-
// Resolve (and authorize) the asset before touching the preset so an
|
|
324
|
-
// unauthenticated caller cannot probe which preset IDs are configured.
|
|
325
327
|
const resolved = await guardSignIn(
|
|
326
328
|
ctx,
|
|
327
329
|
resolveDeliverableAsset(ctx, assetId, user),
|
|
@@ -4,6 +4,7 @@ import { getMediaConfig } from "../../config";
|
|
|
4
4
|
import { getLastSweep, SWEEP_DERIVATIVES_SCHEDULE } from "../../crons";
|
|
5
5
|
import type { MediaAsset } from "../../db";
|
|
6
6
|
import { buildUploadBatches, type UploadBatchRow } from "../../library/batches";
|
|
7
|
+
import type { MediaEventDetails } from "../../library/events";
|
|
7
8
|
import { loadUploadHistoryEvents } from "../../library/upload-history";
|
|
8
9
|
import { presetsConfigSnippet } from "../../library/snippets";
|
|
9
10
|
import { loadAssetsInFolders } from "../../library/listing";
|
|
@@ -60,8 +61,8 @@ function matchesFilters(
|
|
|
60
61
|
);
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
function batchDetails(summary: BatchSummary):
|
|
64
|
-
const details:
|
|
64
|
+
function batchDetails(summary: BatchSummary): MediaEventDetails {
|
|
65
|
+
const details: MediaEventDetails = {
|
|
65
66
|
batchId: summary.batchId,
|
|
66
67
|
total: summary.total,
|
|
67
68
|
failed: summary.failed,
|
|
@@ -110,10 +111,7 @@ function readSourcePage(query: Record<string, string>): SourcePage {
|
|
|
110
111
|
return { offset, limit };
|
|
111
112
|
}
|
|
112
113
|
|
|
113
|
-
function pageRows<T>(
|
|
114
|
-
rows: T[],
|
|
115
|
-
page: SourcePage,
|
|
116
|
-
): { results: T[]; total: number } {
|
|
114
|
+
function pageRows<T>(rows: T[], page: SourcePage) {
|
|
117
115
|
const results = page.limit
|
|
118
116
|
? rows.slice(page.offset, page.offset + page.limit)
|
|
119
117
|
: rows.slice(page.offset);
|
|
@@ -24,23 +24,27 @@ const HTTP_BAD_REQUEST = 400;
|
|
|
24
24
|
const HTTP_CONFLICT = 409;
|
|
25
25
|
const HTTP_UNPROCESSABLE_ENTITY = 422;
|
|
26
26
|
|
|
27
|
-
function
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
27
|
+
async function translatingTransformErrors<T>(work: Promise<T>): Promise<T> {
|
|
28
|
+
try {
|
|
29
|
+
return await work;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
assert(
|
|
32
|
+
!(error instanceof AnimatedImageTransformError),
|
|
33
|
+
HTTP_UNPROCESSABLE_ENTITY,
|
|
34
|
+
"Animated images cannot be edited",
|
|
35
|
+
);
|
|
36
|
+
assert(
|
|
37
|
+
!(error instanceof OversizedImageTransformError),
|
|
38
|
+
HTTP_UNPROCESSABLE_ENTITY,
|
|
39
|
+
"This image is too large to be edited",
|
|
40
|
+
);
|
|
41
|
+
assert(
|
|
42
|
+
!(error instanceof MediaAssetChangedError),
|
|
43
|
+
HTTP_CONFLICT,
|
|
44
|
+
"This image was changed by someone else in the meantime. Reload the page to see the latest version.",
|
|
45
|
+
);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
async function requireEditableAsset(
|
|
@@ -106,8 +110,8 @@ export class MediaTransformController extends MediaApiController {
|
|
|
106
110
|
const ops = assertValidation(body, (v) => transformSchema.parse(v));
|
|
107
111
|
const context = await this.resolveContext();
|
|
108
112
|
const asset = await requireEditableAsset(context, assetId);
|
|
109
|
-
await
|
|
110
|
-
|
|
113
|
+
await translatingTransformErrors(
|
|
114
|
+
applyImageTransform(context.assetModel, asset, ops),
|
|
111
115
|
);
|
|
112
116
|
const updated = await context.assetModel.get(assetId);
|
|
113
117
|
assert(updated, HTTP_CONFLICT, "Asset disappeared during transform");
|
|
@@ -132,8 +136,8 @@ export class MediaTransformController extends MediaApiController {
|
|
|
132
136
|
const ops = assertValidation(body, (v) => transformSchema.parse(v));
|
|
133
137
|
const context = await this.resolveContext();
|
|
134
138
|
const asset = await requireEditableAsset(context, assetId);
|
|
135
|
-
const copy = await
|
|
136
|
-
|
|
139
|
+
const copy = await translatingTransformErrors(
|
|
140
|
+
createEditedCopy(context, asset, ops),
|
|
137
141
|
);
|
|
138
142
|
await this.record(context, {
|
|
139
143
|
kind: "asset.upload",
|
|
@@ -156,8 +160,8 @@ export class MediaTransformController extends MediaApiController {
|
|
|
156
160
|
HTTP_CONFLICT,
|
|
157
161
|
"Asset has no original to revert to",
|
|
158
162
|
);
|
|
159
|
-
await
|
|
160
|
-
|
|
163
|
+
await translatingTransformErrors(
|
|
164
|
+
revertImageTransform(context.assetModel, asset),
|
|
161
165
|
);
|
|
162
166
|
const updated = await context.assetModel.get(assetId);
|
|
163
167
|
assert(updated, HTTP_CONFLICT, "Asset disappeared during revert");
|
|
@@ -4,6 +4,7 @@ import { tmpdir } from "node:os";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { defineConfig } from "@antelopejs/interface-core/config";
|
|
6
6
|
import { MongoMemoryReplSet } from "mongodb-memory-server-core";
|
|
7
|
+
import { isString } from "../guards";
|
|
7
8
|
|
|
8
9
|
const API_PORT = 5019;
|
|
9
10
|
const LOCAL_BUILD_COMMAND = process.env.DMS_PREBUILT ? [] : ["pnpm build"];
|
|
@@ -13,16 +14,16 @@ const MONGO_BINARY_VERSION = "8.0.8";
|
|
|
13
14
|
const SMTP_HOST = "127.0.0.1";
|
|
14
15
|
const EPHEMERAL_PORT = 0;
|
|
15
16
|
const TEST_SENDER = "dms-media@test.local";
|
|
16
|
-
const SMTP_RESPONSES
|
|
17
|
-
EHLO
|
|
18
|
-
HELO
|
|
19
|
-
MAIL
|
|
20
|
-
RCPT
|
|
21
|
-
DATA
|
|
22
|
-
RSET
|
|
23
|
-
NOOP
|
|
24
|
-
QUIT
|
|
25
|
-
|
|
17
|
+
const SMTP_RESPONSES = new Map([
|
|
18
|
+
["EHLO", "250-dms-media.test\r\n250 PIPELINING\r\n"],
|
|
19
|
+
["HELO", "250 dms-media.test\r\n"],
|
|
20
|
+
["MAIL", "250 OK\r\n"],
|
|
21
|
+
["RCPT", "250 OK\r\n"],
|
|
22
|
+
["DATA", "354 End data with <CR><LF>.<CR><LF>\r\n"],
|
|
23
|
+
["RSET", "250 OK\r\n"],
|
|
24
|
+
["NOOP", "250 OK\r\n"],
|
|
25
|
+
["QUIT", "221 Bye\r\n"],
|
|
26
|
+
]);
|
|
26
27
|
|
|
27
28
|
interface SmtpConnectionState {
|
|
28
29
|
pending: string;
|
|
@@ -47,7 +48,7 @@ function processSmtpLine(
|
|
|
47
48
|
}
|
|
48
49
|
const command = line.split(" ", 1)[0]?.toUpperCase() ?? "";
|
|
49
50
|
state.isReadingData = command === "DATA";
|
|
50
|
-
const response = SMTP_RESPONSES
|
|
51
|
+
const response = SMTP_RESPONSES.get(command) ?? "250 OK\r\n";
|
|
51
52
|
if (command === "QUIT") socket.end(response);
|
|
52
53
|
else socket.write(response);
|
|
53
54
|
}
|
|
@@ -77,8 +78,7 @@ async function startSmtpFixture(): Promise<number> {
|
|
|
77
78
|
});
|
|
78
79
|
});
|
|
79
80
|
const address = smtpServer.address();
|
|
80
|
-
if (!address ||
|
|
81
|
-
throw new Error("Invalid SMTP address");
|
|
81
|
+
if (!address || isString(address)) throw new Error("Invalid SMTP address");
|
|
82
82
|
return address.port;
|
|
83
83
|
}
|
|
84
84
|
|
|
@@ -113,14 +113,18 @@ export default defineConfig({
|
|
|
113
113
|
version: ">=0.11.0 <1.0.0",
|
|
114
114
|
},
|
|
115
115
|
config: {
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
/**
|
|
117
|
+
* No frontend server runs here: the dashboard URL is the API, whose
|
|
118
|
+
* paths the front proxy serves unchanged.
|
|
119
|
+
*/
|
|
118
120
|
clientBaseUrl: `http://127.0.0.1:${API_PORT}`,
|
|
119
121
|
auth: {
|
|
120
122
|
jwtSecret: JWT_SECRET,
|
|
121
123
|
},
|
|
122
|
-
|
|
123
|
-
|
|
124
|
+
/**
|
|
125
|
+
* Outside development, which the test run is not, dms 0.10 refuses
|
|
126
|
+
* to start without a render secret of its own.
|
|
127
|
+
*/
|
|
124
128
|
htmlRender: {
|
|
125
129
|
serviceSecret: HTML_RENDER_SECRET,
|
|
126
130
|
},
|