@antelopejs/dms-media 0.6.2 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -23
- package/dist/acl/entries.js +2 -1
- package/dist/acl/entries.js.map +1 -1
- package/dist/asset-lifecycle.js.map +1 -1
- package/dist/db/models/mediaAssets.model.d.ts +7 -5
- package/dist/db/models/mediaDeclarations.model.d.ts +7 -5
- package/dist/db/models/mediaEvents.model.d.ts +7 -5
- package/dist/db/models/mediaFavorites.model.d.ts +7 -5
- package/dist/db/models/mediaFolders.model.d.ts +7 -5
- package/dist/db/models/mediaUploads.model.d.ts +7 -5
- package/dist/declared/assets.js +2 -5
- package/dist/declared/assets.js.map +1 -1
- package/dist/declared/records.d.ts +2 -1
- package/dist/declared/records.js.map +1 -1
- package/dist/library/activity.js +2 -1
- package/dist/library/activity.js.map +1 -1
- package/dist/routes/media/manage.js +2 -2
- package/dist/routes/media/manage.js.map +1 -1
- package/dist/routes/media/storage-keys.js.map +1 -1
- package/dist/test/antelope.test.js +7 -5
- package/dist/test/antelope.test.js.map +1 -1
- package/dist/test/helpers/assets.d.ts +24 -5
- package/dist/test/helpers/assets.js +22 -7
- package/dist/test/helpers/assets.js.map +1 -1
- package/dist/test/helpers/bodies.d.ts +31 -0
- package/dist/test/helpers/bodies.js +16 -0
- package/dist/test/helpers/bodies.js.map +1 -0
- package/dist/test/helpers/folders.d.ts +50 -0
- package/dist/test/helpers/folders.js +4 -2
- package/dist/test/helpers/folders.js.map +1 -1
- package/dist/test/helpers/members.js +10 -3
- package/dist/test/helpers/members.js.map +1 -1
- package/dist/test/helpers/owner.js +6 -1
- package/dist/test/helpers/owner.js.map +1 -1
- package/dist/test/helpers/permissions-world.d.ts +132 -11
- package/dist/test/helpers/permissions-world.js +21 -2
- package/dist/test/helpers/permissions-world.js.map +1 -1
- package/dist/test/helpers/setup-token.d.ts +1 -0
- package/dist/test/helpers/setup-token.js +5 -0
- package/dist/test/helpers/setup-token.js.map +1 -0
- package/dist/test/integration/derivative-sweep-query.test.js +1 -2
- package/dist/test/integration/derivative-sweep-query.test.js.map +1 -1
- package/dist/test/integration/folder-cascade.test.js +3 -1
- package/dist/test/integration/folder-cascade.test.js.map +1 -1
- package/dist/test/integration/media-activity-overview.test.js +39 -12
- package/dist/test/integration/media-activity-overview.test.js.map +1 -1
- package/dist/test/integration/media-api.test.js +22 -21
- package/dist/test/integration/media-api.test.js.map +1 -1
- package/dist/test/integration/media-bindings.test.js +6 -5
- package/dist/test/integration/media-bindings.test.js.map +1 -1
- package/dist/test/integration/media-declared-content.test.js +2 -1
- package/dist/test/integration/media-declared-content.test.js.map +1 -1
- package/dist/test/integration/media-delivery-editing.test.js +12 -2
- package/dist/test/integration/media-delivery-editing.test.js.map +1 -1
- package/dist/test/integration/media-delivery.test.js +5 -3
- package/dist/test/integration/media-delivery.test.js.map +1 -1
- package/dist/test/integration/media-explorer-writes.test.js +6 -4
- package/dist/test/integration/media-explorer-writes.test.js.map +1 -1
- package/dist/test/integration/media-guards.test.js +11 -16
- package/dist/test/integration/media-guards.test.js.map +1 -1
- package/dist/test/integration/media-library.test.js +73 -23
- package/dist/test/integration/media-library.test.js.map +1 -1
- package/dist/test/integration/media-linked-subfolders.test.js +3 -2
- package/dist/test/integration/media-linked-subfolders.test.js.map +1 -1
- package/dist/test/integration/media-member-access.test.js +18 -2
- package/dist/test/integration/media-member-access.test.js.map +1 -1
- package/dist/test/integration/media-permissions.test.js +7 -2
- package/dist/test/integration/media-permissions.test.js.map +1 -1
- package/dist/test/integration/media-project-field.test.js +17 -2
- package/dist/test/integration/media-project-field.test.js.map +1 -1
- package/dist/test/integration/media-search-views.test.js +24 -10
- package/dist/test/integration/media-search-views.test.js.map +1 -1
- package/dist/test/integration/media-storage-origin-unreachable.test.js +2 -1
- package/dist/test/integration/media-storage-origin-unreachable.test.js.map +1 -1
- package/dist/test/integration/media-transform.test.js +8 -9
- package/dist/test/integration/media-transform.test.js.map +1 -1
- package/dist/test/integration/media-upload-history-filters.test.d.ts +1 -0
- package/dist/test/integration/media-upload-history-filters.test.js +67 -0
- package/dist/test/integration/media-upload-history-filters.test.js.map +1 -0
- package/dist/test/integration/media-upload-policy.test.js +31 -14
- package/dist/test/integration/media-upload-policy.test.js.map +1 -1
- package/dist/test/integration/permissions-management.js +15 -4
- package/dist/test/integration/permissions-management.js.map +1 -1
- package/dist/test/unit/declared.test.js +1 -1
- package/dist/test/unit/declared.test.js.map +1 -1
- package/dist/test/unit/library/zip-names.test.js +22 -4
- package/dist/test/unit/library/zip-names.test.js.map +1 -1
- package/dist/test/unit/upload-rules.test.js +10 -0
- package/dist/test/unit/upload-rules.test.js.map +1 -1
- package/dist/transform-ops.js.map +1 -1
- package/dist/upload-policy.js +11 -11
- package/dist/upload-policy.js.map +1 -1
- package/dist/validation/declared.schema.d.ts +4 -4
- package/dist/validation/library.schema.d.ts +10 -10
- package/dist/validation/media.schema.d.ts +8 -9
- package/dist/validation/media.schema.js +4 -6
- package/dist/validation/media.schema.js.map +1 -1
- package/frontend-vue/app/build/imageEditor/useEditorSaving.ts +3 -2
- package/frontend-vue/app/build/library/libraryCore.ts +2 -1
- package/frontend-vue/app/components/FirstRun.vue +2 -1
- 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/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/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/package.json +3 -3
- package/frontend-vue/tests/api-error-presentation.test.ts +183 -0
- package/frontend-vue/tests/fixtures/serverRender.ts +1 -1
- package/package.json +12 -11
- package/skills/dms-media/SKILL.md +2 -2
- package/src/acl/entries.ts +5 -2
- package/src/asset-lifecycle.ts +2 -1
- package/src/declared/assets.ts +6 -6
- package/src/declared/records.ts +5 -1
- package/src/library/activity.ts +3 -1
- package/src/routes/media/manage.ts +2 -2
- package/src/routes/media/storage-keys.ts +1 -0
- package/src/test/antelope.test.ts +7 -5
- package/src/test/helpers/assets.ts +28 -15
- package/src/test/helpers/bodies.ts +22 -0
- package/src/test/helpers/folders.ts +6 -3
- package/src/test/helpers/members.ts +11 -3
- package/src/test/helpers/owner.ts +6 -1
- package/src/test/helpers/permissions-world.ts +23 -19
- package/src/test/helpers/setup-token.ts +6 -0
- package/src/test/integration/derivative-sweep-query.test.ts +4 -3
- package/src/test/integration/folder-cascade.test.ts +3 -1
- package/src/test/integration/media-activity-overview.test.ts +52 -37
- package/src/test/integration/media-api.test.ts +25 -27
- package/src/test/integration/media-bindings.test.ts +10 -16
- package/src/test/integration/media-declared-content.test.ts +2 -1
- package/src/test/integration/media-delivery-editing.test.ts +13 -2
- package/src/test/integration/media-delivery.test.ts +8 -3
- package/src/test/integration/media-explorer-writes.test.ts +6 -4
- package/src/test/integration/media-guards.test.ts +18 -13
- package/src/test/integration/media-library.test.ts +101 -47
- package/src/test/integration/media-linked-subfolders.test.ts +3 -2
- package/src/test/integration/media-member-access.test.ts +22 -24
- package/src/test/integration/media-permissions.test.ts +11 -5
- package/src/test/integration/media-project-field.test.ts +21 -9
- package/src/test/integration/media-search-views.test.ts +35 -31
- package/src/test/integration/media-storage-origin-unreachable.test.ts +2 -1
- package/src/test/integration/media-transform.test.ts +8 -9
- package/src/test/integration/media-upload-history-filters.test.ts +77 -0
- package/src/test/integration/media-upload-policy.test.ts +39 -20
- package/src/test/integration/permissions-management.ts +16 -4
- package/src/test/unit/declared.test.ts +4 -1
- package/src/test/unit/library/zip-names.test.ts +26 -7
- package/src/test/unit/upload-rules.test.ts +11 -0
- package/src/transform-ops.ts +1 -0
- package/src/upload-policy.ts +11 -11
- package/src/validation/media.schema.ts +8 -8
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { afterEach, expect, it, vi } from 'vitest'
|
|
2
|
+
import * as vue from 'vue'
|
|
3
|
+
import { useApiErrorPresenter } from '#dms-core/app/composables/useApiErrorPresenter'
|
|
4
|
+
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
vi.unstubAllGlobals()
|
|
7
|
+
vi.unstubAllEnvs()
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it.each([
|
|
11
|
+
'names',
|
|
12
|
+
'presign',
|
|
13
|
+
'confirm',
|
|
14
|
+
'field',
|
|
15
|
+
'partial',
|
|
16
|
+
'success',
|
|
17
|
+
'local-field',
|
|
18
|
+
'local-batch',
|
|
19
|
+
])(
|
|
20
|
+
'presents the upload %s outcome without duplicate notices',
|
|
21
|
+
async (stage) => {
|
|
22
|
+
vi.resetModules()
|
|
23
|
+
vi.stubEnv('SSR', false)
|
|
24
|
+
for (const [name, value] of Object.entries(vue)) vi.stubGlobal(name, value)
|
|
25
|
+
const data = { message: 'error.read_only_demo', severity: 'warning' }
|
|
26
|
+
const error = Object.assign(new Error('Forbidden'), {
|
|
27
|
+
response: new Response(JSON.stringify(data), { status: 403 }),
|
|
28
|
+
data,
|
|
29
|
+
})
|
|
30
|
+
const notices = new Map<string | number, { title: string; color: string }>()
|
|
31
|
+
let sequence = 0
|
|
32
|
+
vi.stubGlobal('useToast', () => ({
|
|
33
|
+
add: (notice: { id?: string; title: string; color: string }) => {
|
|
34
|
+
const id = notice.id ?? ++sequence
|
|
35
|
+
notices.set(id, notice)
|
|
36
|
+
return { id }
|
|
37
|
+
},
|
|
38
|
+
update: (id: string | number, notice: { title: string; color: string }) =>
|
|
39
|
+
notices.set(id, notice),
|
|
40
|
+
remove: (id: string | number) => notices.delete(id),
|
|
41
|
+
}))
|
|
42
|
+
vi.stubGlobal('getPluginI18n', () => ({
|
|
43
|
+
i18n: {
|
|
44
|
+
tm: (key: string) =>
|
|
45
|
+
key === 'error.read_only_demo' ? 'This demo is read-only' : key,
|
|
46
|
+
rt: (message: string) => message,
|
|
47
|
+
},
|
|
48
|
+
}))
|
|
49
|
+
const state = vue.ref(new WeakMap())
|
|
50
|
+
vi.stubGlobal('useDmsState', () => state)
|
|
51
|
+
vi.stubGlobal('useApiErrorPresenter', useApiErrorPresenter)
|
|
52
|
+
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
|
53
|
+
vi.stubGlobal('useConfirm', () => ({ confirm: async () => false }))
|
|
54
|
+
vi.stubGlobal('onBeforeUnmount', () => undefined)
|
|
55
|
+
vi.stubGlobal('useUploadFailureText', () => () => 'Upload failed')
|
|
56
|
+
vi.stubGlobal('apiErrorStatus', () => 403)
|
|
57
|
+
vi.stubGlobal(
|
|
58
|
+
'uploadLimits',
|
|
59
|
+
vue.ref({ maxUploadBytes: 1000, allowedMimetypes: null }),
|
|
60
|
+
)
|
|
61
|
+
vi.stubGlobal('isActiveDocument', () => false)
|
|
62
|
+
vi.stubGlobal('newBatchId', () => 'batch-1')
|
|
63
|
+
vi.stubGlobal(
|
|
64
|
+
'XMLHttpRequest',
|
|
65
|
+
class {
|
|
66
|
+
upload = {}
|
|
67
|
+
status = 200
|
|
68
|
+
onload = () => undefined
|
|
69
|
+
open() {}
|
|
70
|
+
send() {
|
|
71
|
+
this.onload()
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
)
|
|
75
|
+
vi.stubGlobal('useUploadApi', () => ({
|
|
76
|
+
freeNames: async () => {
|
|
77
|
+
if (stage === 'names' || stage === 'field') throw error
|
|
78
|
+
return { names: [null, null] }
|
|
79
|
+
},
|
|
80
|
+
presign: async (_folderId: string, file: File) => {
|
|
81
|
+
if (
|
|
82
|
+
stage === 'presign' ||
|
|
83
|
+
(stage === 'partial' && file.name === 'world.txt')
|
|
84
|
+
)
|
|
85
|
+
throw error
|
|
86
|
+
return { resourceKey: 'key', uploadUrl: '/storage', headers: {} }
|
|
87
|
+
},
|
|
88
|
+
confirm: async () => {
|
|
89
|
+
if (stage === 'partial' || stage === 'success')
|
|
90
|
+
return { asset: { id: 'asset-1' } }
|
|
91
|
+
throw error
|
|
92
|
+
},
|
|
93
|
+
abort: async () => undefined,
|
|
94
|
+
reportBatch: async () => undefined,
|
|
95
|
+
}))
|
|
96
|
+
const { useUploadQueue } = await import('../app/composables/useUploadQueue')
|
|
97
|
+
vi.stubGlobal('useUploadQueue', useUploadQueue)
|
|
98
|
+
const { useUploadToasts } =
|
|
99
|
+
await import('../app/composables/useUploadToasts')
|
|
100
|
+
vi.stubGlobal('useUploadToasts', useUploadToasts)
|
|
101
|
+
const queue = useUploadQueue()
|
|
102
|
+
const toasts = useUploadToasts()
|
|
103
|
+
const settled = new Promise<void>((resolve) =>
|
|
104
|
+
queue.onBatchSettled(() => resolve()),
|
|
105
|
+
)
|
|
106
|
+
const files = stage.startsWith('local-')
|
|
107
|
+
? [new File([], 'empty.txt')]
|
|
108
|
+
: [new File(['hello'], 'hello.txt'), new File(['world'], 'world.txt')]
|
|
109
|
+
const destination = { folderId: 'folder-1', folderName: 'Docs' }
|
|
110
|
+
if (stage === 'field' || stage === 'local-field') {
|
|
111
|
+
const { useAssetFieldUploads } =
|
|
112
|
+
await import('../app/composables/useAssetFieldUploads')
|
|
113
|
+
await useAssetFieldUploads({
|
|
114
|
+
accept: () => undefined,
|
|
115
|
+
destination: () => destination,
|
|
116
|
+
room: () => undefined,
|
|
117
|
+
onUploaded: () => undefined,
|
|
118
|
+
}).upload(files)
|
|
119
|
+
} else {
|
|
120
|
+
const batchId = queue.enqueue(files, destination)
|
|
121
|
+
toasts.announce(batchId, files.length, 'Docs')
|
|
122
|
+
}
|
|
123
|
+
await settled
|
|
124
|
+
await vue.nextTick()
|
|
125
|
+
expect(
|
|
126
|
+
[...notices.values()].map(({ title, color }) => ({ title, color })),
|
|
127
|
+
).toEqual([
|
|
128
|
+
stage === 'success'
|
|
129
|
+
? { title: 'dms_media.toasts.upload_added', color: 'success' }
|
|
130
|
+
: stage === 'local-field'
|
|
131
|
+
? { title: 'dms_media.field_widget.upload.failed', color: 'warning' }
|
|
132
|
+
: stage === 'local-batch'
|
|
133
|
+
? { title: 'dms_media.toasts.upload_failed_one', color: 'warning' }
|
|
134
|
+
: { title: 'This demo is read-only', color: 'warning' },
|
|
135
|
+
])
|
|
136
|
+
},
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
it.each([true, false])(
|
|
140
|
+
'presents the clipboard outcome when copied is %s',
|
|
141
|
+
async (copied) => {
|
|
142
|
+
vi.resetModules()
|
|
143
|
+
const notices: { title: string; color: string; description?: string }[] = []
|
|
144
|
+
vi.stubGlobal('useMediaApi', () => ({}))
|
|
145
|
+
vi.stubGlobal('useAuthFetch', () => ({
|
|
146
|
+
$authFetch: async () => ({ origin: 'https://media.example.test/' }),
|
|
147
|
+
}))
|
|
148
|
+
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
|
149
|
+
vi.stubGlobal('useToast', () => ({
|
|
150
|
+
add: (notice: (typeof notices)[number]) => notices.push(notice),
|
|
151
|
+
}))
|
|
152
|
+
vi.stubGlobal('useConfirm', () => ({ confirm: async () => false }))
|
|
153
|
+
vi.stubGlobal('useApiErrorPresenter', useApiErrorPresenter)
|
|
154
|
+
vi.stubGlobal('getPluginI18n', () => ({ i18n: {} }))
|
|
155
|
+
vi.stubGlobal('useDmsState', () => vue.ref(new WeakMap()))
|
|
156
|
+
vi.stubGlobal('navigator', {
|
|
157
|
+
clipboard: {
|
|
158
|
+
writeText: async () => {
|
|
159
|
+
if (!copied) throw new Error('Clipboard denied')
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
})
|
|
163
|
+
const { useAssetLink } = await import('../app/composables/useAssetLink')
|
|
164
|
+
await useAssetLink().copyLink({
|
|
165
|
+
name: 'hello.txt',
|
|
166
|
+
url: '/media/hello.txt',
|
|
167
|
+
effectiveVisibility: 'public',
|
|
168
|
+
})
|
|
169
|
+
expect(notices).toHaveLength(1)
|
|
170
|
+
expect(notices[0]).toMatchObject(
|
|
171
|
+
copied
|
|
172
|
+
? {
|
|
173
|
+
title: 'dms_media.toasts.link_copied',
|
|
174
|
+
color: 'success',
|
|
175
|
+
}
|
|
176
|
+
: {
|
|
177
|
+
title: 'dms_media.asset_link.copy_failed',
|
|
178
|
+
description: 'https://media.example.test/media/hello.txt',
|
|
179
|
+
color: 'warning',
|
|
180
|
+
},
|
|
181
|
+
)
|
|
182
|
+
},
|
|
183
|
+
)
|
|
@@ -62,7 +62,7 @@ provideGlobal('useToast', () => ({ add: noop }))
|
|
|
62
62
|
provideGlobal('useConfirm', () => ({ confirm: async () => false }))
|
|
63
63
|
provideGlobal('useOverlay', () => ({ create: () => ({ open: async () => undefined }) }))
|
|
64
64
|
provideGlobal('useDrawer', () => ({ open: noop }))
|
|
65
|
-
provideGlobal('
|
|
65
|
+
provideGlobal('useApiErrorPresenter', () => ({ presentError: noop, resolveError: () => null }))
|
|
66
66
|
provideGlobal('useUnsavedChanges', noop)
|
|
67
67
|
provideGlobal('usePageLiveRefresh', noop)
|
|
68
68
|
provideGlobal('defineShortcuts', noop)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/dms-media",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Media library for the AntelopeJS DMS: uploads, folders with per-folder permissions, image sizes and light editing, with a Finder-style explorer.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antelopejs",
|
|
@@ -60,12 +60,12 @@
|
|
|
60
60
|
"test:exports": "node --test tests/package-exports.test.mjs"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@antelopejs/interface-api": ">=0.0
|
|
64
|
-
"@antelopejs/interface-api-util": ">=0.
|
|
65
|
-
"@antelopejs/interface-core": ">=0.
|
|
66
|
-
"@antelopejs/interface-database": ">=0.
|
|
67
|
-
"@antelopejs/interface-database-decorators": ">=0.
|
|
68
|
-
"@antelopejs/interface-dms": ">=0.
|
|
63
|
+
"@antelopejs/interface-api": ">=0.3.0 <1.0.0",
|
|
64
|
+
"@antelopejs/interface-api-util": ">=0.3.0 <1.0.0",
|
|
65
|
+
"@antelopejs/interface-core": ">=0.4.0 <1.0.0",
|
|
66
|
+
"@antelopejs/interface-database": ">=0.3.0 <1.0.0",
|
|
67
|
+
"@antelopejs/interface-database-decorators": ">=0.2.0 <1.0.0",
|
|
68
|
+
"@antelopejs/interface-dms": ">=0.12.0 <1.0.0",
|
|
69
69
|
"@antelopejs/interface-dms-media": ">=0.3.0 <0.4.0",
|
|
70
70
|
"@antelopejs/interface-file-storage": ">=0.1.6 <1.0.0",
|
|
71
71
|
"node-cron": "^4.2.1",
|
|
@@ -73,10 +73,11 @@
|
|
|
73
73
|
"zod": "~3.24.2"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
|
-
"@antelopejs/core": "
|
|
77
|
-
"@antelopejs/dms": ">=0.
|
|
78
|
-
"@antelopejs/dms-frontend": "0.
|
|
79
|
-
"@antelopejs/
|
|
76
|
+
"@antelopejs/core": "^1.20.0",
|
|
77
|
+
"@antelopejs/dms": ">=0.16.1 <1.0.0",
|
|
78
|
+
"@antelopejs/dms-frontend": "0.10.0",
|
|
79
|
+
"@antelopejs/interface-data-api": ">=0.6.1 <1.0.0",
|
|
80
|
+
"@antelopejs/tooling-configs": "^0.2.18",
|
|
80
81
|
"@types/chai": "^4.3.20",
|
|
81
82
|
"@types/mocha": "^10",
|
|
82
83
|
"@types/node": "^24.0.0",
|
|
@@ -19,8 +19,8 @@ Every data block carries `realtimeTopic: MEDIA_LIBRARY_TOPIC`; custom components
|
|
|
19
19
|
|
|
20
20
|
## Setup
|
|
21
21
|
|
|
22
|
-
-
|
|
23
|
-
and
|
|
22
|
+
- The DMS backend, renderer and `@antelopejs/interface-dms-media` releases the module runs on are in the README compatibility block
|
|
23
|
+
and, for the renderer, in `engines["@antelopejs/dms-frontend"]` of `frontend-vue/package.json`. Media 0.4 uses media interface 0.2; Media 0.3 is the DMS 0.8 line.
|
|
24
24
|
- `ajs project modules add @antelopejs/dms-media`, plus an `interface-file-storage` module (`file-storage-local`).
|
|
25
25
|
- Set the storage's `baseUrl` and the module's `publicBaseUrl` to `${@api.API_PUBLIC_BASE_URL}`, and list every
|
|
26
26
|
dashboard origin in the api module's `cors.allowedOrigins`: the browser `PUT`s files straight to the storage.
|
package/src/acl/entries.ts
CHANGED
|
@@ -10,8 +10,11 @@ import type { AclEntry } from "../types";
|
|
|
10
10
|
export function parseFolderAcl(folder: MediaFolder): AclEntry[] | undefined {
|
|
11
11
|
if (!folder.json_acl) return undefined;
|
|
12
12
|
try {
|
|
13
|
-
const parsed = JSON.parse(folder.json_acl);
|
|
14
|
-
if (Array.isArray(parsed))
|
|
13
|
+
const parsed: unknown = JSON.parse(folder.json_acl);
|
|
14
|
+
if (Array.isArray(parsed)) {
|
|
15
|
+
// SAFETY: json_acl is written only as serializeAcl of an AclEntry[] (bindings.ts, declared/folders.ts) or as the literal "[]" (bindings.ts EMPTY_ACL), so an array read back holds AclEntry values; a schema parse of a stored row on read is excluded by ruling.
|
|
16
|
+
return parsed as AclEntry[];
|
|
17
|
+
}
|
|
15
18
|
} catch {}
|
|
16
19
|
Logging.Warn(
|
|
17
20
|
`Media folder '${folder._id}' has an unreadable ACL; treating it as empty.`,
|
package/src/asset-lifecycle.ts
CHANGED
|
@@ -11,7 +11,8 @@ export const TECHNICAL_MUTATION: MediaMutationOptions = { touchesAsset: false };
|
|
|
11
11
|
|
|
12
12
|
/** Reads the durable, retryable file deletion queue for an asset. */
|
|
13
13
|
export function retiredFiles(asset: MediaAsset): string[] {
|
|
14
|
-
|
|
14
|
+
// SAFETY: json_retiredFiles is written only as "[]" at creation (upload.ts, declared/assets.ts, routes/media/transform.ts) or the JSON.stringify of storage-key strings (this file), so it parses to a string[]; a schema parse of a stored row on read is excluded by ruling.
|
|
15
|
+
return JSON.parse(asset.json_retiredFiles) as string[];
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
/** Detaches references and records their cleanup in the same media transition. */
|
package/src/declared/assets.ts
CHANGED
|
@@ -53,10 +53,6 @@ interface PreparedFile {
|
|
|
53
53
|
|
|
54
54
|
type Fail = (reason: string) => never;
|
|
55
55
|
|
|
56
|
-
function describeError(error: unknown): string {
|
|
57
|
-
return error instanceof Error ? error.message : String(error);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
56
|
async function loadBytes(
|
|
61
57
|
load: () => Uint8Array | Promise<Uint8Array>,
|
|
62
58
|
fail: Fail,
|
|
@@ -64,7 +60,9 @@ async function loadBytes(
|
|
|
64
60
|
const loaded: unknown = await Promise.resolve()
|
|
65
61
|
.then(load)
|
|
66
62
|
.catch((error: unknown) =>
|
|
67
|
-
fail(
|
|
63
|
+
fail(
|
|
64
|
+
`the source failed to load: ${error instanceof Error ? error.message : String(error)}`,
|
|
65
|
+
),
|
|
68
66
|
);
|
|
69
67
|
if (!(loaded instanceof Uint8Array))
|
|
70
68
|
fail("source.load must return a Uint8Array");
|
|
@@ -80,7 +78,9 @@ async function readSource(
|
|
|
80
78
|
if ("bytes" in source) bytes = Buffer.from(source.bytes);
|
|
81
79
|
else if ("filePath" in source)
|
|
82
80
|
bytes = await readFile(source.filePath).catch((error: unknown) =>
|
|
83
|
-
fail(
|
|
81
|
+
fail(
|
|
82
|
+
`cannot read '${source.filePath}': ${error instanceof Error ? error.message : String(error)}`,
|
|
83
|
+
),
|
|
84
84
|
);
|
|
85
85
|
else bytes = await loadBytes(source.load, fail);
|
|
86
86
|
const size = declaredFileSizeSchema.safeParse(bytes.byteLength);
|
package/src/declared/records.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { GetModel } from "@antelopejs/interface-database-decorators";
|
|
2
|
+
import type {
|
|
3
|
+
MediaAssetDeclaration,
|
|
4
|
+
MediaFolderDeclaration,
|
|
5
|
+
} from "@antelopejs/interface-dms-media";
|
|
2
6
|
import type { ZodType, ZodTypeDef } from "zod";
|
|
3
7
|
import { isObjectLike, isString } from "../guards";
|
|
4
8
|
import {
|
|
@@ -48,7 +52,7 @@ export function declaredModels(tenantId: string): DeclaredModels {
|
|
|
48
52
|
/** Validates a declaration, naming every refused field. */
|
|
49
53
|
export function parseDeclaration<Output>(
|
|
50
54
|
kind: MediaDeclarationKind,
|
|
51
|
-
input:
|
|
55
|
+
input: MediaFolderDeclaration | MediaAssetDeclaration,
|
|
52
56
|
schema: ZodType<Output, ZodTypeDef, unknown>,
|
|
53
57
|
): Output {
|
|
54
58
|
const parsed = schema.safeParse(input);
|
package/src/library/activity.ts
CHANGED
|
@@ -101,6 +101,8 @@ export const ACTIVITY_FILTERS = {
|
|
|
101
101
|
|
|
102
102
|
export type ActivityFilter = keyof typeof ACTIVITY_FILTERS;
|
|
103
103
|
|
|
104
|
+
const ACTIVITY_FILTER_KINDS = new Map(Object.entries(ACTIVITY_FILTERS));
|
|
105
|
+
|
|
104
106
|
export function isActivityFilter(value: unknown): value is ActivityFilter {
|
|
105
107
|
return typeof value === "string" && Object.hasOwn(ACTIVITY_FILTERS, value);
|
|
106
108
|
}
|
|
@@ -324,7 +326,7 @@ export function buildActivityItems(
|
|
|
324
326
|
deletedAssetIds: deletedAssets(source.events),
|
|
325
327
|
};
|
|
326
328
|
const kinds: ReadonlySet<string> | undefined = source.filter
|
|
327
|
-
? new Set(
|
|
329
|
+
? new Set(ACTIVITY_FILTER_KINDS.get(source.filter))
|
|
328
330
|
: undefined;
|
|
329
331
|
const events = kinds
|
|
330
332
|
? source.events.filter((event) => kinds.has(event.kind))
|
|
@@ -55,9 +55,9 @@ function matchesFilters(
|
|
|
55
55
|
row: UploadBatchRow,
|
|
56
56
|
filters: Map<string, Set<string>>,
|
|
57
57
|
): boolean {
|
|
58
|
-
const fields
|
|
58
|
+
const fields = new Map<string, unknown>(Object.entries(row));
|
|
59
59
|
return [...filters].every(([column, values]) =>
|
|
60
|
-
values.has(String(fields
|
|
60
|
+
values.has(String(fields.get(column))),
|
|
61
61
|
);
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -2,6 +2,7 @@ import type { MediaAsset } from "../../db";
|
|
|
2
2
|
|
|
3
3
|
export function parseDerivatives(asset: MediaAsset): Record<string, string> {
|
|
4
4
|
if (!asset.json_derivatives) return {};
|
|
5
|
+
// SAFETY: json_derivatives is written only as "" or the JSON.stringify of a map from cache key to storage key (transform.ts, derivatives.ts, crons/sweep-derivatives.ts), so a non-empty value is that string map; a schema parse of a stored row on read is excluded by ruling.
|
|
5
6
|
return JSON.parse(asset.json_derivatives) as Record<string, string>;
|
|
6
7
|
}
|
|
7
8
|
|
|
@@ -5,6 +5,7 @@ import { join } from "node:path";
|
|
|
5
5
|
import { defineConfig } from "@antelopejs/interface-core/config";
|
|
6
6
|
import { MongoMemoryReplSet } from "mongodb-memory-server-core";
|
|
7
7
|
import { isString } from "../guards";
|
|
8
|
+
import { SETUP_TOKEN } from "./helpers/setup-token";
|
|
8
9
|
|
|
9
10
|
const API_PORT = 5019;
|
|
10
11
|
const LOCAL_BUILD_COMMAND = process.env.DMS_PREBUILT ? [] : ["pnpm build"];
|
|
@@ -110,7 +111,7 @@ export default defineConfig({
|
|
|
110
111
|
source: {
|
|
111
112
|
type: "package",
|
|
112
113
|
package: "@antelopejs/dms",
|
|
113
|
-
version: ">=0.
|
|
114
|
+
version: ">=0.16.1 <1.0.0",
|
|
114
115
|
},
|
|
115
116
|
config: {
|
|
116
117
|
/**
|
|
@@ -134,14 +135,14 @@ export default defineConfig({
|
|
|
134
135
|
source: {
|
|
135
136
|
type: "package",
|
|
136
137
|
package: "@antelopejs/mongodb",
|
|
137
|
-
version: "1.
|
|
138
|
+
version: "1.6.2",
|
|
138
139
|
},
|
|
139
140
|
},
|
|
140
141
|
"auth-jwt": {
|
|
141
142
|
source: {
|
|
142
143
|
type: "package",
|
|
143
144
|
package: "@antelopejs/auth-jwt",
|
|
144
|
-
version: "1.0
|
|
145
|
+
version: "1.1.0",
|
|
145
146
|
},
|
|
146
147
|
config: {
|
|
147
148
|
secret: JWT_SECRET,
|
|
@@ -151,7 +152,7 @@ export default defineConfig({
|
|
|
151
152
|
source: {
|
|
152
153
|
type: "package",
|
|
153
154
|
package: "@antelopejs/api",
|
|
154
|
-
version: "1.
|
|
155
|
+
version: "1.7.0",
|
|
155
156
|
},
|
|
156
157
|
config: {
|
|
157
158
|
servers: [{ protocol: "http", host: "127.0.0.1", port: API_PORT }],
|
|
@@ -162,7 +163,7 @@ export default defineConfig({
|
|
|
162
163
|
source: {
|
|
163
164
|
type: "package",
|
|
164
165
|
package: "@antelopejs/file-storage-local",
|
|
165
|
-
version: "0.
|
|
166
|
+
version: "0.2.0",
|
|
166
167
|
},
|
|
167
168
|
},
|
|
168
169
|
nodemailer: {
|
|
@@ -193,6 +194,7 @@ export default defineConfig({
|
|
|
193
194
|
process.env.TEST_MONGO_URL = mongoUrl;
|
|
194
195
|
process.env.TEST_API_BASE_URL = `http://127.0.0.1:${API_PORT}`;
|
|
195
196
|
process.env.TEST_JWT_SECRET = JWT_SECRET;
|
|
197
|
+
process.env.DMS_SETUP_TOKEN = SETUP_TOKEN;
|
|
196
198
|
|
|
197
199
|
return {
|
|
198
200
|
modules: {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import axios, { type AxiosInstance } from "axios";
|
|
2
2
|
import { expect } from "chai";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { presignBody, readBody } from "./bodies";
|
|
3
5
|
import { getBaseUrl } from "./http";
|
|
4
6
|
|
|
5
7
|
const HTTP_OK = 200;
|
|
@@ -12,14 +14,16 @@ export const ONE_PIXEL_PNG = Buffer.from(
|
|
|
12
14
|
"base64",
|
|
13
15
|
);
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
id: string
|
|
17
|
-
folderId: string
|
|
18
|
-
name: string
|
|
19
|
-
width
|
|
20
|
-
height
|
|
21
|
-
url: string
|
|
22
|
-
}
|
|
17
|
+
const uploadedAssetBody = z.object({
|
|
18
|
+
id: z.string(),
|
|
19
|
+
folderId: z.string(),
|
|
20
|
+
name: z.string(),
|
|
21
|
+
width: z.number().nullish(),
|
|
22
|
+
height: z.number().nullish(),
|
|
23
|
+
url: z.string(),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export type UploadedAsset = z.infer<typeof uploadedAssetBody>;
|
|
23
27
|
|
|
24
28
|
export interface RawRedirectResponse {
|
|
25
29
|
status: number;
|
|
@@ -34,6 +38,18 @@ export interface BatchFile {
|
|
|
34
38
|
batchId?: string;
|
|
35
39
|
}
|
|
36
40
|
|
|
41
|
+
/** Sends the bytes to the storage URL a presign answered, the way a browser does. */
|
|
42
|
+
export function putPresigned(
|
|
43
|
+
presign: z.infer<typeof presignBody>,
|
|
44
|
+
body: Buffer,
|
|
45
|
+
) {
|
|
46
|
+
return axios.put(presign.uploadUrl, body, {
|
|
47
|
+
headers: presign.headers,
|
|
48
|
+
validateStatus: () => true,
|
|
49
|
+
transformRequest: [(data: Buffer) => data],
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
37
53
|
export function uploadAsset(
|
|
38
54
|
client: AxiosInstance,
|
|
39
55
|
folderId: string,
|
|
@@ -57,20 +73,17 @@ export async function uploadAssetInBatch(
|
|
|
57
73
|
mimetype,
|
|
58
74
|
});
|
|
59
75
|
expect(presign.status, "presign").to.equal(HTTP_OK);
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
validateStatus: () => true,
|
|
63
|
-
transformRequest: [(data) => data],
|
|
64
|
-
});
|
|
76
|
+
const presigned = readBody(presign, presignBody);
|
|
77
|
+
const put = await putPresigned(presigned, body);
|
|
65
78
|
expect(put.status, "storage PUT").to.be.lessThan(HTTP_REDIRECT_BOUNDARY);
|
|
66
79
|
const confirm = await client.post("/api/media/upload/confirm", {
|
|
67
80
|
folderId,
|
|
68
|
-
resourceKey:
|
|
81
|
+
resourceKey: presigned.resourceKey,
|
|
69
82
|
filename,
|
|
70
83
|
batchId,
|
|
71
84
|
});
|
|
72
85
|
expect(confirm.status, "confirm").to.equal(HTTP_OK);
|
|
73
|
-
return confirm.
|
|
86
|
+
return readBody(confirm, z.object({ asset: uploadedAssetBody })).asset;
|
|
74
87
|
}
|
|
75
88
|
|
|
76
89
|
export function uploadPixelPng(
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z, type ZodType, type ZodTypeDef } from "zod";
|
|
2
|
+
|
|
3
|
+
/** A response body checked against the shape its route answers. */
|
|
4
|
+
export function readBody<Output>(
|
|
5
|
+
response: { data: unknown },
|
|
6
|
+
schema: ZodType<Output, ZodTypeDef, unknown>,
|
|
7
|
+
): Output {
|
|
8
|
+
return schema.parse(response.data);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** What creating a folder answers. */
|
|
12
|
+
export const createdBody = z.object({ id: z.string() });
|
|
13
|
+
|
|
14
|
+
/** What presigning an upload answers. */
|
|
15
|
+
export const presignBody = z.object({
|
|
16
|
+
uploadUrl: z.string(),
|
|
17
|
+
headers: z.record(z.string()),
|
|
18
|
+
resourceKey: z.string(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
/** What a read-url answers. */
|
|
22
|
+
export const urlBody = z.object({ url: z.string() });
|
|
@@ -31,17 +31,20 @@ const folderNodeSchema = z.object({
|
|
|
31
31
|
name: z.string(),
|
|
32
32
|
parentId: z.string().nullable(),
|
|
33
33
|
binding: z.string().nullable(),
|
|
34
|
+
bound: z.boolean(),
|
|
34
35
|
acceptsSubfolders: z.boolean(),
|
|
35
36
|
accepts: z.array(z.string()).nullable(),
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
export type FolderNode = z.infer<typeof folderNodeSchema>;
|
|
39
40
|
|
|
40
|
-
/**
|
|
41
|
+
/** What `/api/media/tree` answers, checked against the fields the suites read. */
|
|
42
|
+
export const folderTreeBody = z.object({ folders: z.array(folderNodeSchema) });
|
|
43
|
+
|
|
44
|
+
/** The folders `/api/media/tree` answers. */
|
|
41
45
|
export async function fetchFolderNodes(
|
|
42
46
|
client: AxiosInstance,
|
|
43
47
|
): Promise<FolderNode[]> {
|
|
44
48
|
const response = await client.get("/api/media/tree");
|
|
45
|
-
return
|
|
46
|
-
.folders;
|
|
49
|
+
return folderTreeBody.parse(response.data).folders;
|
|
47
50
|
}
|
|
@@ -3,6 +3,8 @@ import { GetModel } from "@antelopejs/interface-database-decorators";
|
|
|
3
3
|
import { DEFAULT_TENANT_ID } from "@antelopejs/interface-dms/constants";
|
|
4
4
|
import { RoleModel, UserInviteModel } from "@antelopejs/interface-dms/db";
|
|
5
5
|
import type { AxiosInstance } from "axios";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { readBody } from "./bodies";
|
|
6
8
|
import { authorizedClient, createClient } from "./http";
|
|
7
9
|
import { withPermissionAncestors } from "./permission-ancestors";
|
|
8
10
|
|
|
@@ -11,6 +13,11 @@ const MEMBER_LANGUAGE = "en";
|
|
|
11
13
|
const INVITE_LIFETIME_MS = 3_600_000;
|
|
12
14
|
const HTTP_BAD_REQUEST = 400;
|
|
13
15
|
|
|
16
|
+
const signupBody = z.object({
|
|
17
|
+
access_token: z.string(),
|
|
18
|
+
user: z.object({ _id: z.string() }),
|
|
19
|
+
});
|
|
20
|
+
|
|
14
21
|
export interface MemberSession {
|
|
15
22
|
client: AxiosInstance;
|
|
16
23
|
accessToken: string;
|
|
@@ -74,10 +81,11 @@ export async function registerMember(
|
|
|
74
81
|
`Member signup failed [${signup.status}]: ${JSON.stringify(signup.data)}`,
|
|
75
82
|
);
|
|
76
83
|
}
|
|
84
|
+
const session = readBody(signup, signupBody);
|
|
77
85
|
return {
|
|
78
|
-
client: authorizedClient(
|
|
79
|
-
accessToken:
|
|
80
|
-
userId:
|
|
86
|
+
client: authorizedClient(session.access_token),
|
|
87
|
+
accessToken: session.access_token,
|
|
88
|
+
userId: session.user._id,
|
|
81
89
|
email,
|
|
82
90
|
};
|
|
83
91
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { readBody } from "./bodies";
|
|
1
3
|
import { createClient } from "./http";
|
|
4
|
+
import { SETUP_TOKEN } from "./setup-token";
|
|
2
5
|
|
|
3
6
|
const OWNER_EMAIL = "owner@test.local";
|
|
4
7
|
const OWNER_PASSWORD = "TestPassw0rd!";
|
|
@@ -19,6 +22,7 @@ export async function ensureOwnerSession(): Promise<OwnerSession> {
|
|
|
19
22
|
lastName: OWNER_LAST_NAME,
|
|
20
23
|
email: OWNER_EMAIL,
|
|
21
24
|
password: OWNER_PASSWORD,
|
|
25
|
+
setupToken: SETUP_TOKEN,
|
|
22
26
|
});
|
|
23
27
|
const isRegistered = registration.status < HTTP_BAD_REQUEST;
|
|
24
28
|
const isAlreadyRegistered =
|
|
@@ -38,5 +42,6 @@ export async function ensureOwnerSession(): Promise<OwnerSession> {
|
|
|
38
42
|
`Login failed [${login.status}]: ${JSON.stringify(login.data)}`,
|
|
39
43
|
);
|
|
40
44
|
}
|
|
41
|
-
|
|
45
|
+
const session = readBody(login, z.object({ access_token: z.string() }));
|
|
46
|
+
return { accessToken: session.access_token, email: OWNER_EMAIL };
|
|
42
47
|
}
|