@antelopejs/dms-media 0.3.1 → 0.4.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.
Files changed (48) hide show
  1. package/README.md +5 -1
  2. package/dist/index.d.ts +3 -0
  3. package/dist/index.js +8 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/test/antelope.test.js +1 -1
  6. package/dist/test/helpers/pages.js +3 -2
  7. package/dist/test/helpers/pages.js.map +1 -1
  8. package/dist/test/integration/frontend-module.test.d.ts +1 -0
  9. package/dist/test/integration/frontend-module.test.js +13 -0
  10. package/dist/test/integration/frontend-module.test.js.map +1 -0
  11. package/frontend-vue/app/components/FileProperties.vue +9 -3
  12. package/frontend-vue/app/components/FirstRun.vue +1 -1
  13. package/frontend-vue/app/components/ImageEditor.vue +43 -26
  14. package/frontend-vue/app/components/PresetCards.vue +3 -11
  15. package/frontend-vue/app/components/RecentFiles.vue +6 -14
  16. package/frontend-vue/app/components/UploadQueue.vue +1 -1
  17. package/frontend-vue/app/components/UploadStrip.vue +1 -1
  18. package/frontend-vue/app/components/dialogs/DestinationDialog.vue +1 -2
  19. package/frontend-vue/app/components/explorer/ExplorerInspector.vue +17 -16
  20. package/frontend-vue/app/components/explorer/ExplorerShell.vue +11 -3
  21. package/frontend-vue/app/components/explorer/ExplorerToolbar.vue +2 -1
  22. package/frontend-vue/app/components/field/AssetValue.vue +12 -13
  23. package/frontend-vue/app/components/file/FileViewer.vue +1 -14
  24. package/frontend-vue/app/composables/library/useLibraryListing.ts +180 -79
  25. package/frontend-vue/app/composables/library/useLibraryTree.ts +31 -15
  26. package/frontend-vue/app/composables/library/useMediaLibrary.ts +17 -7
  27. package/frontend-vue/app/composables/uploadLimits.ts +25 -0
  28. package/frontend-vue/app/composables/useAssetContent.ts +20 -0
  29. package/frontend-vue/app/composables/useCurrentFile.ts +10 -8
  30. package/frontend-vue/app/composables/useFieldFolders.ts +19 -18
  31. package/frontend-vue/app/composables/useFileDetails.ts +117 -90
  32. package/frontend-vue/app/composables/useMediaApi.ts +18 -24
  33. package/frontend-vue/package.json +2 -1
  34. package/frontend-vue/pnpm-lock.yaml +17 -2
  35. package/frontend-vue/tests/engines.test.ts +20 -0
  36. package/frontend-vue/tests/fixtures/inertia.ts +8 -0
  37. package/frontend-vue/tests/fixtures/serverRender.ts +200 -0
  38. package/frontend-vue/tests/fixtures/unhead.ts +3 -0
  39. package/frontend-vue/tests/fixtures/vueI18n.ts +4 -0
  40. package/frontend-vue/tests/libraryListing.test.ts +120 -0
  41. package/frontend-vue/tests/serverRender.test.ts +215 -0
  42. package/frontend-vue/vitest.config.ts +21 -0
  43. package/package.json +11 -5
  44. package/src/index.ts +19 -2
  45. package/src/test/antelope.test.ts +1 -1
  46. package/src/test/helpers/pages.ts +3 -2
  47. package/src/test/integration/frontend-module.test.ts +13 -0
  48. package/frontend-vue/app/composables/useSharedTree.ts +0 -73
@@ -0,0 +1,120 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { inBrowserApp, type BackendRead } from './fixtures/serverRender'
3
+ import { useLibraryListing } from '../app/composables/library/useLibraryListing'
4
+ import type { MediaAsset } from '../app/types/media'
5
+
6
+ // The explorer's listing is one paged read keyed by the location and the
7
+ // filters: "load more" appends a page, a revalidation reads every loaded page
8
+ // again with the sizes they had, and the local patches keep the next page's
9
+ // offset in step with the server.
10
+
11
+ const FOLDER_FILES = 650
12
+ const FOLDER_URL = '/api/media/folders/catalog/assets'
13
+
14
+ const file = (index: number): MediaAsset => ({
15
+ id: `f${index}`,
16
+ folderId: 'catalog',
17
+ name: `file-${String(index).padStart(4, '0')}.pdf`,
18
+ mimetype: 'application/pdf',
19
+ size: 1000,
20
+ alt: '',
21
+ visibility: 'inherit',
22
+ effectiveVisibility: 'private',
23
+ url: `/media/f${index}/file.pdf`,
24
+ hasOriginal: false,
25
+ typeGroup: 'document',
26
+ starred: false,
27
+ createdAt: '2026-10-01T10:00:00.000Z',
28
+ updatedAt: '2026-10-01T10:00:00.000Z',
29
+ })
30
+
31
+ function folderBackend(files: MediaAsset[]) {
32
+ return ({ url, query }: BackendRead): unknown => {
33
+ if (url !== FOLDER_URL) return {}
34
+ const offset = Number(query.offset)
35
+ const limit = Number(query.limit)
36
+ const sorted = query.direction === 'desc' ? [...files].reverse() : files
37
+ return { assets: sorted.slice(offset, offset + limit), total: files.length, facets: {} }
38
+ }
39
+ }
40
+
41
+ function openListing(files = Array.from({ length: FOLDER_FILES }, (_, index) => file(index))) {
42
+ const app = inBrowserApp(() => useLibraryListing(), folderBackend(files))
43
+ const folderReads = () => app.reads().filter((read) => read.includes(FOLDER_URL))
44
+ return { listing: app.result, folderReads, files }
45
+ }
46
+
47
+ describe('the explorer listing', () => {
48
+ it('reads nothing at the root', () => {
49
+ const { listing, folderReads } = openListing()
50
+ expect(listing.assets.value).toEqual([])
51
+ expect(folderReads()).toEqual([])
52
+ })
53
+
54
+ it('reads a folder page by page', async () => {
55
+ const { listing, folderReads } = openListing()
56
+ await listing.setLocation({ kind: 'folder', folderId: 'catalog' })
57
+ expect(listing.assets.value).toHaveLength(120)
58
+ expect(listing.total.value).toBe(FOLDER_FILES)
59
+ expect(listing.hasMore.value).toBe(true)
60
+
61
+ await listing.load(true)
62
+ expect(listing.assets.value).toHaveLength(240)
63
+ expect(listing.assets.value[120]?.id).toBe('f120')
64
+ expect(folderReads()).toEqual([
65
+ `GET ${FOLDER_URL}?offset=0&limit=120&sort=name&direction=asc&visibility=any&modified=any&orientation=any`,
66
+ `GET ${FOLDER_URL}?offset=120&limit=120&sort=name&direction=asc&visibility=any&modified=any&orientation=any`,
67
+ ])
68
+ })
69
+
70
+ it('reads the next page after the files left once some are removed', async () => {
71
+ const { listing, folderReads, files } = openListing()
72
+ await listing.setLocation({ kind: 'folder', folderId: 'catalog' })
73
+ listing.removeAssets(['f0', 'f1'])
74
+ files.splice(0, 2)
75
+ expect(listing.total.value).toBe(FOLDER_FILES - 2)
76
+
77
+ await listing.load(true)
78
+ expect(folderReads().at(-1)).toContain('offset=118&limit=120')
79
+ expect(listing.assets.value.map((asset) => asset.id)).toEqual(files.slice(0, 238).map((asset) => asset.id))
80
+ })
81
+
82
+ it('loads every file in the largest pages, and reads them again with the same sizes', async () => {
83
+ const { listing, folderReads } = openListing()
84
+ await listing.setLocation({ kind: 'folder', folderId: 'catalog' })
85
+ await listing.loadAll()
86
+ expect(listing.assets.value).toHaveLength(FOLDER_FILES)
87
+ expect(listing.hasMore.value).toBe(false)
88
+ const loaded = folderReads().map((read) => read.match(/offset=\d+&limit=\d+/)?.[0])
89
+ expect(loaded).toEqual(['offset=0&limit=120', 'offset=120&limit=500', 'offset=620&limit=500'])
90
+
91
+ await listing.refresh()
92
+ expect(folderReads().slice(loaded.length).map((read) => read.match(/offset=\d+&limit=\d+/)?.[0])).toEqual(loaded)
93
+ expect(listing.assets.value).toHaveLength(FOLDER_FILES)
94
+ })
95
+
96
+ it('starts again from the first page when the filters change, and shows the pages of a previous key at once', async () => {
97
+ const { listing, folderReads } = openListing()
98
+ await listing.setLocation({ kind: 'folder', folderId: 'catalog' })
99
+ await listing.load(true)
100
+ await listing.setFilters({ direction: 'desc' })
101
+ expect(listing.assets.value).toHaveLength(120)
102
+ expect(listing.assets.value[0]?.id).toBe(`f${FOLDER_FILES - 1}`)
103
+ expect(folderReads().at(-1)).toContain('offset=0&limit=120&sort=name&direction=desc')
104
+
105
+ const back = listing.setFilters({ direction: 'asc' })
106
+ await nextTick()
107
+ expect(listing.assets.value).toHaveLength(240)
108
+ await back
109
+ })
110
+
111
+ it('places a new file where the sort puts it and counts one beyond the loaded pages', async () => {
112
+ const { listing } = openListing()
113
+ await listing.setLocation({ kind: 'folder', folderId: 'catalog' })
114
+ listing.insertAsset({ ...file(9000), name: 'file-0000a.pdf' })
115
+ expect(listing.assets.value[1]?.id).toBe('f9000')
116
+ listing.insertAsset({ ...file(9001), name: 'zzz.pdf' })
117
+ expect(listing.assets.value).toHaveLength(121)
118
+ expect(listing.total.value).toBe(FOLDER_FILES + 2)
119
+ })
120
+ })
@@ -0,0 +1,215 @@
1
+ import { defineComponent, h } from 'vue'
2
+ import { describe, expect, it } from 'vitest'
3
+ import { serverRender, type BackendRead } from './fixtures/serverRender'
4
+ import AssetValue from '../app/components/field/AssetValue.vue'
5
+ import Explorer from '../app/components/Explorer.vue'
6
+ import FileHeader from '../app/components/FileHeader.vue'
7
+ import FilePreview from '../app/components/FilePreview.vue'
8
+ import FileProperties from '../app/components/FileProperties.vue'
9
+ import ImageEditor from '../app/components/ImageEditor.vue'
10
+ import PresetCards from '../app/components/PresetCards.vue'
11
+ import RecentFiles from '../app/components/RecentFiles.vue'
12
+ import { useFieldFolders } from '../app/composables/useFieldFolders'
13
+ import type { MediaAsset, MediaFolder } from '../app/types/media'
14
+
15
+ // What a server render of each block reads, and that it hands every read to
16
+ // the browser: a read the page does not hand over is made again by the
17
+ // browser, after a server request for nothing.
18
+
19
+ const RIGHTS = { read: true, write: true, manage: true }
20
+
21
+ const folder = (id: string, name: string): MediaFolder => ({
22
+ id,
23
+ name,
24
+ parentId: null,
25
+ shell: false,
26
+ bound: false,
27
+ binding: null,
28
+ link: null,
29
+ accepts: null,
30
+ visibility: 'private',
31
+ hasOwnAcl: false,
32
+ createdAt: '2026-10-01T10:00:00.000Z',
33
+ updatedAt: '2026-10-01T10:00:00.000Z',
34
+ rights: RIGHTS,
35
+ fileCount: 3,
36
+ size: 3000,
37
+ starred: false,
38
+ })
39
+
40
+ const file = (id: string, name: string, mimetype = 'image/png'): MediaAsset => ({
41
+ id,
42
+ folderId: 'catalog',
43
+ name,
44
+ mimetype,
45
+ size: 1000,
46
+ width: 1200,
47
+ height: 800,
48
+ alt: `${name} alt`,
49
+ visibility: 'inherit',
50
+ effectiveVisibility: 'private',
51
+ url: `/media/${id}/${name}`,
52
+ hasOriginal: false,
53
+ typeGroup: mimetype.startsWith('image/') ? 'image' : 'document',
54
+ starred: false,
55
+ createdAt: '2026-10-01T10:00:00.000Z',
56
+ updatedAt: '2026-10-01T10:00:00.000Z',
57
+ })
58
+
59
+ const FILES = [file('a1', 'harbour.png'), file('a2', 'lighthouse.png'), file('a3', 'dunes.png')]
60
+
61
+ function backend({ url }: BackendRead): unknown {
62
+ const details = url.match(/^\/api\/media\/assets\/([^/]+)\/details$/)
63
+ if (details) {
64
+ const found = FILES.find((entry) => entry.id === details[1])
65
+ if (!found) throw Object.assign(new Error('Not Found'), { statusCode: 404 })
66
+ return { asset: found, folder: folder('catalog', 'Catalog'), path: [], uploadedBy: null }
67
+ }
68
+ const one = url.match(/^\/api\/media\/assets\/([^/]+)$/)
69
+ if (one) return { asset: FILES.find((entry) => entry.id === one[1]) }
70
+ if (/\/read-url$/.test(url)) return { url: `https://storage.test${url}`, expiresAt: 0 }
71
+ switch (url) {
72
+ case '/api/media/tree':
73
+ return {
74
+ folders: [folder('catalog', 'Catalog')],
75
+ root: { write: true, manage: true, fileCount: 3, size: 3000 },
76
+ views: { starred: 0, missingAlt: 0 },
77
+ isOwner: true,
78
+ maxUploadBytes: 1000,
79
+ allowedMimetypes: [],
80
+ quotaBytes: null,
81
+ }
82
+ case '/api/media/stats/recent':
83
+ return { assets: FILES }
84
+ case '/api/media/presets':
85
+ return {
86
+ presets: [{ id: 'thumb', width: 300, height: 300, fit: 'cover', cacheKey: 'thumb.1', rendered: 1, urlPattern: '', exampleUrl: null }],
87
+ cache: { schedule: '', lastSweepAt: null, lastSweepRemoved: null, publicTtlSeconds: 0, privateTtlSeconds: 0 },
88
+ isDefault: true,
89
+ example: null,
90
+ }
91
+ case '/api/media/folders/catalog/assets':
92
+ return { assets: FILES, total: FILES.length, facets: {} }
93
+ case '/api/media/bindings/demo.cover/folder':
94
+ return { folder: { ...folder('covers', 'Demo covers'), bound: true }, maxUploadBytes: 1000, allowedMimetypes: [] }
95
+ default:
96
+ return {}
97
+ }
98
+ }
99
+
100
+ const render = (component: Parameters<typeof serverRender>[0], props: Record<string, unknown> = {}, url = '/') =>
101
+ serverRender(component, props, { url, respond: backend })
102
+
103
+ /** The file page's blocks, as the page lays them out. */
104
+ const FilePage = defineComponent({
105
+ setup: () => () => h('div', [h(FileHeader), h(FilePreview), h(FileProperties)]),
106
+ })
107
+
108
+ describe('server render: the blocks read with the page and hand it over', () => {
109
+ it('recent files: the files and the folder tree', async () => {
110
+ const page = await render(RecentFiles)
111
+ expect(page.reads).toEqual(['GET /api/media/stats/recent', 'GET /api/media/tree'])
112
+ expect(page.handed).toEqual(expect.arrayContaining(page.reads))
113
+ expect(page.html).toContain('lighthouse.png')
114
+ expect(page.html).not.toContain('animate-pulse')
115
+ })
116
+
117
+ it('image sizes: the presets', async () => {
118
+ const page = await render(PresetCards)
119
+ expect(page.reads).toEqual(['GET /api/media/presets'])
120
+ expect(page.handed).toEqual(expect.arrayContaining(page.reads))
121
+ expect(page.html).toContain('thumb')
122
+ })
123
+
124
+ it('file page: one read of the file and its neighbours for the three blocks, and the image read URL', async () => {
125
+ const page = await render(FilePage, {}, '/modules/media/file?asset=a2')
126
+ expect(page.reads.sort()).toEqual(
127
+ [
128
+ 'GET /api/media/tree',
129
+ 'GET /api/media/assets/a2/details',
130
+ 'GET /api/media/folders/catalog/assets?sort=name&offset=0&limit=500',
131
+ 'GET /api/media/assets/a2/read-url?preset=preview',
132
+ ].sort(),
133
+ )
134
+ expect(page.handed).toEqual(
135
+ expect.arrayContaining([
136
+ 'GET /api/media/tree',
137
+ 'dms-media:file:a2:[null,null,null]',
138
+ 'dms-media:content:a2:2026-10-01T10:00:00.000Z',
139
+ ]),
140
+ )
141
+ // The header's name and position, the viewer's image, the name field.
142
+ expect(page.html).toContain('lighthouse.png')
143
+ expect(page.html).toContain('dms_media.lightbox.position 2 3')
144
+ expect(page.html).toContain('https://storage.test/api/media/assets/a2/read-url')
145
+ expect(page.html).toContain('value="lighthouse"')
146
+ })
147
+
148
+ it('file page: a text file is read by the browser alone', async () => {
149
+ FILES.push(file('t1', 'notes.txt', 'text/plain'))
150
+ try {
151
+ const page = await render(FilePage, {}, '/modules/media/file?asset=t1')
152
+ expect(page.reads).not.toContain(expect.stringContaining('read-url'))
153
+ expect(page.html).toContain('notes.txt')
154
+ } finally {
155
+ FILES.pop()
156
+ }
157
+ })
158
+
159
+ it('file page: an unknown file is said so, and the failure handed over', async () => {
160
+ const page = await render(FilePage, {}, '/modules/media/file?asset=gone')
161
+ expect(page.reads).toContain('GET /api/media/assets/gone/details')
162
+ expect(page.payload.errors).toHaveProperty(['dms-media:file:gone:[null,null,null]'])
163
+ expect(page.html).toContain('dms_media.file.not_found')
164
+ })
165
+
166
+ it('library: a link to a folder reads its files with the page', async () => {
167
+ const page = await render(Explorer, {}, '/modules/media/files?folder=catalog&sort=name&direction=desc')
168
+ expect(page.reads).toEqual([
169
+ 'GET /api/media/tree',
170
+ 'GET /api/media/folders/catalog/assets?offset=0&limit=120&sort=name&direction=desc&visibility=any&modified=any&orientation=any',
171
+ ])
172
+ expect(page.handed).toEqual(expect.arrayContaining(['GET /api/media/tree']))
173
+ expect(page.handed.some((key) => key.startsWith('dms-media:listing:'))).toBe(true)
174
+ expect(page.html).toContain('aria-current="location">Catalog')
175
+ expect(page.html).toContain('dms_media.status.items 3')
176
+ })
177
+
178
+ it('library and image editor: the key hints are the platform labels the browser hydrates with', async () => {
179
+ const library = await render(Explorer, {}, '/modules/media/files')
180
+ const editor = await render(ImageEditor, {}, '/modules/media/editor?asset=a1')
181
+ for (const page of [library, editor]) {
182
+ expect(page.html).not.toContain('data-stub="UKbd" value="meta"')
183
+ expect(page.html).toContain('data-stub="UKbd" value="Ctrl"')
184
+ }
185
+ })
186
+
187
+ it('image editor: the details, not the image the browser edits', async () => {
188
+ const page = await render(ImageEditor, {}, '/modules/media/editor?asset=a1')
189
+ expect(page.reads).toEqual(['GET /api/media/assets/a1/details'])
190
+ expect(page.handed).toEqual(expect.arrayContaining(page.reads))
191
+ expect(page.html).toContain('dms_media.editor.heading harbour.png')
192
+ })
193
+
194
+ it('asset cell: the files it names', async () => {
195
+ const page = await render(AssetValue, { value: ['a1', 'a3', 'a2'] })
196
+ expect(page.reads).toEqual(['GET /api/media/assets/a1', 'GET /api/media/assets/a3'])
197
+ expect(page.handed).toEqual(['dms-media:asset-names:a1,a3'])
198
+ expect(page.html).toContain('harbour.png')
199
+ expect(page.html).toContain('dunes.png')
200
+ expect(page.html).toContain('dms_media.field_widget.more 1')
201
+ })
202
+
203
+ it('bound asset field: its folder', async () => {
204
+ const Field = defineComponent({
205
+ setup() {
206
+ const { boundFolder } = useFieldFolders('demo.cover')
207
+ return () => h('p', boundFolder.value?.name ?? 'no folder')
208
+ },
209
+ })
210
+ const page = await render(Field)
211
+ expect(page.reads).toEqual(['GET /api/media/bindings/demo.cover/folder'])
212
+ expect(page.handed).toEqual(page.reads)
213
+ expect(page.html).toContain('Demo covers')
214
+ })
215
+ })
@@ -1,5 +1,26 @@
1
+ import { resolve } from 'node:path'
2
+ import vue from '@vitejs/plugin-vue'
1
3
  import { defineConfig } from 'vitest/config'
2
4
 
5
+ // The renderer and the DMS core layer the server-render tests run on: the
6
+ // ones the module installs (`@antelopejs/dms-frontend`, `@antelopejs/dms`),
7
+ // as `pnpm test:frontend` checks the module against them.
8
+ const root = resolve(__dirname, '..', 'node_modules', '@antelopejs')
9
+
3
10
  export default defineConfig({
11
+ plugins: [vue()],
12
+ resolve: {
13
+ alias: {
14
+ '#dms/frontend-module': resolve(root, 'dms-frontend/templates/vue/frontend-module.ts'),
15
+ '#dms-core': resolve(root, 'dms/frontend-vue/layers/dms-core'),
16
+ '#dms-ui': resolve(root, 'dms/frontend-vue/layers/dms-ui'),
17
+ // One Vue for the renderer and the components.
18
+ vue: resolve(__dirname, 'node_modules/vue'),
19
+ // What the renderer reads of Inertia, vue-i18n and unhead in the browser only.
20
+ '@inertiajs/vue3': resolve(__dirname, 'tests/fixtures/inertia.ts'),
21
+ 'vue-i18n': resolve(__dirname, 'tests/fixtures/vueI18n.ts'),
22
+ '@unhead/vue': resolve(__dirname, 'tests/fixtures/unhead.ts'),
23
+ },
24
+ },
4
25
  test: { environment: 'node', include: ['tests/**/*.test.ts'] },
5
26
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antelopejs/dms-media",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +14,12 @@
14
14
  "src"
15
15
  ],
16
16
  "main": "dist/index.js",
17
+ "types": "dist/index.d.ts",
17
18
  "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "default": "./dist/index.js"
22
+ },
18
23
  "./package.json": "./package.json"
19
24
  },
20
25
  "publishConfig": {
@@ -39,7 +44,8 @@
39
44
  "release": "pnpm --filter @antelopejs/interface-dms-media build && pnpm --dir frontend-vue install --frozen-lockfile && release-it",
40
45
  "prepack": "pnpm run build",
41
46
  "knip": "knip --dependencies",
42
- "knip:all": "knip"
47
+ "knip:all": "knip",
48
+ "test:exports": "node --test tests/package-exports.test.mjs"
43
49
  },
44
50
  "dependencies": {
45
51
  "@antelopejs/interface-api": ">=0.0.14 <1.0.0",
@@ -47,7 +53,7 @@
47
53
  "@antelopejs/interface-core": ">=0.1.1 <1.0.0",
48
54
  "@antelopejs/interface-database": ">=0.1.8 <1.0.0",
49
55
  "@antelopejs/interface-database-decorators": ">=0.1.7 <1.0.0",
50
- "@antelopejs/interface-dms": ">=0.6.0 <1.0.0",
56
+ "@antelopejs/interface-dms": ">=0.7.0 <1.0.0",
51
57
  "@antelopejs/interface-dms-media": ">=0.2.1 <0.3.0",
52
58
  "@antelopejs/interface-file-storage": ">=0.1.3 <1.0.0",
53
59
  "node-cron": "^4.2.1",
@@ -56,8 +62,8 @@
56
62
  },
57
63
  "devDependencies": {
58
64
  "@antelopejs/core": ">=1.13.5 <2",
59
- "@antelopejs/dms": ">=0.8.0 <0.9.0",
60
- "@antelopejs/dms-frontend": "0.5.6",
65
+ "@antelopejs/dms": ">=0.9.0 <1.0.0",
66
+ "@antelopejs/dms-frontend": "0.6.0",
61
67
  "@antelopejs/tooling-configs": ">=0.0.7 <1.0.0",
62
68
  "@types/chai": "^4.3.20",
63
69
  "@types/mocha": "^10",
package/src/index.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import path from "node:path";
2
2
  import { ImplementInterface } from "@antelopejs/interface-core";
3
- import { AddFrontendModule } from "@antelopejs/interface-dms/page";
3
+ import {
4
+ AddFrontendModule,
5
+ type FrontendBackendProxy,
6
+ } from "@antelopejs/interface-dms/page";
4
7
  import { Logging } from "@antelopejs/interface-core/logging";
5
8
  import "./db";
6
9
  import type { ScheduledTask } from "node-cron";
@@ -23,6 +26,19 @@ export * from "./types";
23
26
 
24
27
  let cronTasks: ScheduledTask[] = [];
25
28
 
29
+ /** The frontend module the dashboard loads: its blocks, viewers and fields. */
30
+ export const MEDIA_FRONTEND_MODULE = "@antelopejs/dms-media-frontend-vue";
31
+
32
+ /**
33
+ * The file links a dashboard page shows (`/media/<id>/<name>`), which the
34
+ * backend serves: proxied by the frontend server with the member's session,
35
+ * so that a private file opens for a member signed in, as on the API origin.
36
+ */
37
+ export const MEDIA_DELIVERY_PROXY: FrontendBackendProxy = {
38
+ path: "/media/**",
39
+ auth: "session",
40
+ };
41
+
26
42
  export async function construct(config: DmsMediaConfig = {}): Promise<void> {
27
43
  configureMediaModule(config);
28
44
  ImplementInterface(
@@ -32,11 +48,12 @@ export async function construct(config: DmsMediaConfig = {}): Promise<void> {
32
48
  const sourcePath = path.join(__dirname, "../frontend-vue");
33
49
 
34
50
  await AddFrontendModule({
35
- name: "@antelopejs/dms-media-frontend-vue",
51
+ name: MEDIA_FRONTEND_MODULE,
36
52
  sourcePath,
37
53
  renderer: { name: "vue", version: "3" },
38
54
  configKey: "dmsMedia",
39
55
  priority: 0,
56
+ backendProxies: [MEDIA_DELIVERY_PROXY],
40
57
  });
41
58
  }
42
59
 
@@ -109,7 +109,7 @@ export default defineConfig({
109
109
  source: {
110
110
  type: "package",
111
111
  package: "@antelopejs/dms",
112
- version: ">=0.8.0 <0.9.0",
112
+ version: ">=0.9.0 <1.0.0",
113
113
  },
114
114
  config: {
115
115
  auth: {
@@ -1,7 +1,8 @@
1
+ import { pageRoutePath } from "@antelopejs/interface-dms/page";
1
2
  import type { AxiosInstance } from "axios";
2
3
 
3
4
  const HTTP_OK = 200;
4
- const PAGE_LAYOUT_SUFFIX = "/pagelayout";
5
+ const PAGE_LAYOUT_ROUTE = "/pagelayout";
5
6
  const OMIT_SHARED_PAGE = "false";
6
7
 
7
8
  /** What a caller gets from each surface that serves a DMS page. */
@@ -25,7 +26,7 @@ export async function readPageAccess(
25
26
  slug: string,
26
27
  ): Promise<PageAccess> {
27
28
  const [ownRoute, page, layout] = await Promise.all([
28
- client.get(`${slug}${PAGE_LAYOUT_SUFFIX}`),
29
+ client.get(pageRoutePath(slug, PAGE_LAYOUT_ROUTE)),
29
30
  client.get("/dms/page", {
30
31
  params: { path: slug, shared: OMIT_SHARED_PAGE },
31
32
  }),
@@ -0,0 +1,13 @@
1
+ import { GetFrontendModules } from "@antelopejs/interface-dms/page";
2
+ import { expect } from "chai";
3
+ import { MEDIA_DELIVERY_PROXY, MEDIA_FRONTEND_MODULE } from "../../index";
4
+
5
+ describe("frontend module", () => {
6
+ it("declares the file links as a backend prefix the frontend server proxies with the session", async () => {
7
+ const modules = await GetFrontendModules();
8
+ const media = modules.find(
9
+ (module) => module.name === MEDIA_FRONTEND_MODULE,
10
+ );
11
+ expect(media?.backendProxies).to.deep.equal([MEDIA_DELIVERY_PROXY]);
12
+ });
13
+ });
@@ -1,73 +0,0 @@
1
- import type { MediaTree } from '../types/media'
2
- import type { MediaApi } from './useMediaApi'
3
-
4
- const DEFAULT_MAX_UPLOAD_BYTES = 500 * 1024 * 1024
5
-
6
- /** What the library takes at all, from the module config: every upload is checked against it before it is sent. */
7
- export interface UploadLimits {
8
- maxUploadBytes: number
9
- /** Mimetype patterns the library accepts; any type until the server says otherwise. */
10
- allowedMimetypes: readonly string[] | null
11
- }
12
-
13
- const sharedTree = ref<MediaTree | null>(null)
14
- const limits = ref<UploadLimits>({
15
- maxUploadBytes: DEFAULT_MAX_UPLOAD_BYTES,
16
- allowedMimetypes: null,
17
- })
18
- let pendingLoad: Promise<void> | null = null
19
- let consumers = 0
20
-
21
- /** The upload limits the server last sent, shared by every screen that uploads. */
22
- export const uploadLimits = readonly(limits)
23
-
24
- /** Keeps the upload limits a server answer carries. */
25
- export function rememberUploadLimits(answer: UploadLimits): void {
26
- limits.value = {
27
- maxUploadBytes: answer.maxUploadBytes,
28
- allowedMimetypes: answer.allowedMimetypes,
29
- }
30
- }
31
-
32
- /** Reads the folder tree (counted over `scopeFolderId` when given) and keeps the upload limits it carries. */
33
- export async function fetchTree(
34
- api: MediaApi,
35
- scopeFolderId?: string,
36
- ): Promise<MediaTree> {
37
- const tree = await api.tree(scopeFolderId)
38
- rememberUploadLimits(tree)
39
- return tree
40
- }
41
-
42
- /**
43
- * The folder tree every block of a page shares: read once when the first block
44
- * mounts, read again on each library change, and dropped when the last block
45
- * leaves so the next page starts from fresh data.
46
- */
47
- export function useSharedTree() {
48
- const api = useMediaApi()
49
-
50
- function reload(): Promise<void> {
51
- pendingLoad ??= fetchTree(api)
52
- .then((tree) => {
53
- sharedTree.value = tree
54
- })
55
- .catch(() => undefined)
56
- .finally(() => {
57
- pendingLoad = null
58
- })
59
- return pendingLoad
60
- }
61
-
62
- consumers += 1
63
- onScopeDispose(() => {
64
- consumers -= 1
65
- if (consumers === 0) sharedTree.value = null
66
- })
67
- onMounted(() => {
68
- if (!sharedTree.value) void reload()
69
- })
70
- onLibraryChange(reload)
71
-
72
- return { tree: computed(() => sharedTree.value), reload }
73
- }