@antelopejs/dms-media 0.5.0 → 0.6.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/dist/frontend-module.d.ts +4 -0
- package/dist/frontend-module.js +24 -0
- package/dist/frontend-module.js.map +1 -0
- package/dist/index.d.ts +1 -3
- package/dist/index.js +3 -19
- package/dist/index.js.map +1 -1
- package/dist/library/realtime.js +8 -1
- package/dist/library/realtime.js.map +1 -1
- package/dist/pages/activity.d.ts +1 -0
- package/dist/pages/activity.js +3 -0
- package/dist/pages/activity.js.map +1 -1
- package/dist/pages/overview.d.ts +1 -0
- package/dist/pages/overview.js +3 -2
- package/dist/pages/overview.js.map +1 -1
- package/dist/pages/toolbar.d.ts +3 -0
- package/dist/pages/toolbar.js +19 -0
- package/dist/pages/toolbar.js.map +1 -0
- package/dist/pages/uploads.d.ts +1 -0
- package/dist/pages/uploads.js +4 -0
- package/dist/pages/uploads.js.map +1 -1
- package/dist/routes/media/manage.d.ts +23 -0
- package/dist/routes/media/manage.js +7 -4
- package/dist/routes/media/manage.js.map +1 -1
- package/dist/test/antelope.test.js +9 -4
- package/dist/test/antelope.test.js.map +1 -1
- package/dist/test/integration/media-activity-overview.test.js +6 -0
- package/dist/test/integration/media-activity-overview.test.js.map +1 -1
- package/dist/test/unit/library/realtime.test.d.ts +1 -0
- package/dist/test/unit/library/realtime.test.js +43 -0
- package/dist/test/unit/library/realtime.test.js.map +1 -0
- package/dist/test/unit/pages/toolbar.test.d.ts +1 -0
- package/dist/test/unit/pages/toolbar.test.js +64 -0
- package/dist/test/unit/pages/toolbar.test.js.map +1 -0
- package/dist/test/unit/routes/preset-row.test.d.ts +1 -0
- package/dist/test/unit/routes/preset-row.test.js +36 -0
- package/dist/test/unit/routes/preset-row.test.js.map +1 -0
- package/frontend-vue/app/components/Explorer.vue +2 -0
- package/frontend-vue/app/components/FirstRun.vue +3 -1
- package/frontend-vue/app/components/PresetCards.vue +28 -5
- package/frontend-vue/app/components/RecentFiles.vue +11 -5
- package/frontend-vue/app/components/UploadQueue.vue +3 -1
- package/frontend-vue/app/components/UploadStrip.vue +3 -1
- package/frontend-vue/app/components/explorer/ExplorerDetailsDrawer.vue +10 -0
- package/frontend-vue/app/components/explorer/ExplorerInspector.vue +19 -14
- package/frontend-vue/app/components/explorer/ExplorerShell.vue +1 -11
- package/frontend-vue/app/composables/library/useExplorerCommands.ts +7 -1
- package/frontend-vue/app/composables/library/useExplorerDetailsDrawer.ts +75 -0
- package/frontend-vue/i18n/locales/media-en-GB.json +9 -2
- package/frontend-vue/i18n/locales/media-fr-FR.json +9 -2
- package/frontend-vue/package.json +1 -1
- package/frontend-vue/tests/detailsDrawer.test.ts +150 -0
- package/frontend-vue/tests/fixtures/serverRender.ts +70 -0
- package/frontend-vue/tests/locales.test.ts +17 -0
- package/frontend-vue/tests/serverRender.test.ts +47 -2
- package/package.json +7 -6
- package/skills/dms-media/SKILL.md +6 -0
- package/src/frontend-module.ts +35 -0
- package/src/index.ts +4 -28
- package/src/library/realtime.ts +12 -3
- package/src/pages/activity.ts +4 -0
- package/src/pages/overview.ts +4 -3
- package/src/pages/toolbar.ts +28 -0
- package/src/pages/uploads.ts +5 -0
- package/src/routes/media/manage.ts +17 -4
- package/src/test/antelope.test.ts +13 -4
- package/src/test/integration/media-activity-overview.test.ts +5 -0
- package/src/test/unit/library/realtime.test.ts +53 -0
- package/src/test/unit/pages/toolbar.test.ts +92 -0
- package/src/test/unit/routes/preset-row.test.ts +39 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { computed, effectScope, nextTick, ref } from 'vue'
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
|
+
import './fixtures/serverRender'
|
|
4
|
+
import type { ExplorerContext } from '../app/composables/library/useExplorerCommands'
|
|
5
|
+
import { useExplorerDetailsDrawer } from '../app/composables/library/useExplorerDetailsDrawer'
|
|
6
|
+
import type { ExplorerLayout } from '../app/composables/library/useExplorerLayout'
|
|
7
|
+
import type { DrawerRowHeader } from '#dms-ui/app/composables/containers/types'
|
|
8
|
+
|
|
9
|
+
// Narrower than the inline details panel, the explorer shows its details in
|
|
10
|
+
// the DMS drawer: it opens and closes with the layout's state, closing it
|
|
11
|
+
// turns the state off, and it follows the explorer's width and lifetime.
|
|
12
|
+
|
|
13
|
+
interface OpenedDrawer {
|
|
14
|
+
options: { direction: string; componentOptions?: unknown; rowHeader: DrawerRowHeader }
|
|
15
|
+
close: ReturnType<typeof vi.fn>
|
|
16
|
+
patch: ReturnType<typeof vi.fn>
|
|
17
|
+
settle: () => Promise<void>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface TestFile {
|
|
21
|
+
id: string
|
|
22
|
+
name: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let opened: OpenedDrawer[] = []
|
|
26
|
+
|
|
27
|
+
function openDrawer(options: OpenedDrawer['options']) {
|
|
28
|
+
let resolve!: () => void
|
|
29
|
+
const result = new Promise<void>((done) => (resolve = done))
|
|
30
|
+
const drawer: OpenedDrawer = {
|
|
31
|
+
options,
|
|
32
|
+
close: vi.fn(() => resolve()),
|
|
33
|
+
patch: vi.fn(),
|
|
34
|
+
settle: async () => {
|
|
35
|
+
resolve()
|
|
36
|
+
await result
|
|
37
|
+
await nextTick()
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
opened.push(drawer)
|
|
41
|
+
return { result, close: drawer.close, patch: drawer.patch }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const FILES: TestFile[] = [
|
|
45
|
+
{ id: 'a', name: 'a.png' },
|
|
46
|
+
{ id: 'b', name: 'b.pdf' },
|
|
47
|
+
{ id: 'c', name: 'c.jpg' },
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
function setup(isWide = false) {
|
|
51
|
+
const layout = { isDetailsDrawerOpen: ref(false), hasInlineDetails: ref(isWide) } as unknown as ExplorerLayout
|
|
52
|
+
const assets = ref(FILES)
|
|
53
|
+
const selectedIds = ref<string[]>([])
|
|
54
|
+
const select = vi.fn((id: string) => (selectedIds.value = [id]))
|
|
55
|
+
const focusedAsset = computed(() =>
|
|
56
|
+
selectedIds.value.length === 1 ? assets.value.find((file) => file.id === selectedIds.value[0]) : undefined,
|
|
57
|
+
)
|
|
58
|
+
const library = { listing: { assets }, selection: { focusedAsset, select } }
|
|
59
|
+
const context = { library, commands: {} } as unknown as ExplorerContext
|
|
60
|
+
const scope = effectScope()
|
|
61
|
+
scope.run(() => useExplorerDetailsDrawer(layout, context))
|
|
62
|
+
return { layout, scope, selectedIds, select }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function toggle(layout: ExplorerLayout, isOpen: boolean): Promise<void> {
|
|
66
|
+
layout.isDetailsDrawerOpen.value = isOpen
|
|
67
|
+
await nextTick()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
opened = []
|
|
72
|
+
vi.stubGlobal('useDrawer', () => ({ open: openDrawer }))
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
describe('details drawer', () => {
|
|
76
|
+
it('opens on the right, and closes with the state', async () => {
|
|
77
|
+
const { layout } = setup()
|
|
78
|
+
await toggle(layout, true)
|
|
79
|
+
expect(opened).toHaveLength(1)
|
|
80
|
+
expect(opened[0]!.options.direction).toBe('right')
|
|
81
|
+
// Nothing handed as props: the body injects what the explorer provides.
|
|
82
|
+
expect(opened[0]!.options.componentOptions).toBeUndefined()
|
|
83
|
+
await toggle(layout, false)
|
|
84
|
+
expect(opened[0]!.close).toHaveBeenCalledOnce()
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('turns the state off when the drawer is dismissed', async () => {
|
|
88
|
+
const { layout } = setup()
|
|
89
|
+
await toggle(layout, true)
|
|
90
|
+
await opened[0]!.settle()
|
|
91
|
+
expect(layout.isDetailsDrawerOpen.value).toBe(false)
|
|
92
|
+
await toggle(layout, true)
|
|
93
|
+
expect(opened).toHaveLength(2)
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('puts the drawer away while the details sit inline, and brings it back', async () => {
|
|
97
|
+
const { layout } = setup()
|
|
98
|
+
await toggle(layout, true)
|
|
99
|
+
layout.hasInlineDetails.value = true
|
|
100
|
+
await nextTick()
|
|
101
|
+
expect(opened[0]!.close).toHaveBeenCalledOnce()
|
|
102
|
+
await nextTick()
|
|
103
|
+
expect(layout.isDetailsDrawerOpen.value).toBe(true)
|
|
104
|
+
layout.hasInlineDetails.value = false
|
|
105
|
+
await nextTick()
|
|
106
|
+
expect(opened).toHaveLength(2)
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
it('never opens while the details sit inline', async () => {
|
|
110
|
+
const { layout } = setup(true)
|
|
111
|
+
await toggle(layout, true)
|
|
112
|
+
expect(opened).toHaveLength(0)
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
it('closes with the explorer', async () => {
|
|
116
|
+
const { layout, scope } = setup()
|
|
117
|
+
await toggle(layout, true)
|
|
118
|
+
scope.stop()
|
|
119
|
+
expect(opened[0]!.close).toHaveBeenCalledOnce()
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('heads a single file with its name and place among the files shown', async () => {
|
|
123
|
+
const { layout, selectedIds } = setup()
|
|
124
|
+
selectedIds.value = ['b']
|
|
125
|
+
await toggle(layout, true)
|
|
126
|
+
const header = opened[0]!.options.rowHeader
|
|
127
|
+
expect(header.title).toBe('b.pdf')
|
|
128
|
+
expect(header.navigation).toMatchObject({ index: 1, total: 3, hasPrev: true, hasNext: true })
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
it('keeps its own title without a single file', async () => {
|
|
132
|
+
const { layout, selectedIds } = setup()
|
|
133
|
+
selectedIds.value = ['a', 'b']
|
|
134
|
+
await toggle(layout, true)
|
|
135
|
+
expect(opened[0]!.options.rowHeader).toEqual({})
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it('steps through the files by selecting them, and follows the selection', async () => {
|
|
139
|
+
const { layout, selectedIds, select } = setup()
|
|
140
|
+
selectedIds.value = ['a']
|
|
141
|
+
await toggle(layout, true)
|
|
142
|
+
expect(opened[0]!.options.rowHeader.navigation?.hasPrev).toBe(false)
|
|
143
|
+
opened[0]!.options.rowHeader.navigation?.next()
|
|
144
|
+
expect(select).toHaveBeenCalledWith('b', { extend: false, toggle: false })
|
|
145
|
+
await nextTick()
|
|
146
|
+
const patched = opened[0]!.patch.mock.lastCall?.[0] as { rowHeader: DrawerRowHeader }
|
|
147
|
+
expect(patched.rowHeader.title).toBe('b.pdf')
|
|
148
|
+
expect(patched.rowHeader.navigation?.index).toBe(1)
|
|
149
|
+
})
|
|
150
|
+
})
|
|
@@ -61,6 +61,7 @@ provideGlobal('useRegionalFormat', () => ({ formatNumber: (value: number) => Str
|
|
|
61
61
|
provideGlobal('useToast', () => ({ add: noop }))
|
|
62
62
|
provideGlobal('useConfirm', () => ({ confirm: async () => false }))
|
|
63
63
|
provideGlobal('useOverlay', () => ({ create: () => ({ open: async () => undefined }) }))
|
|
64
|
+
provideGlobal('useDrawer', () => ({ open: noop }))
|
|
64
65
|
provideGlobal('useApiError', noop)
|
|
65
66
|
provideGlobal('useUnsavedChanges', noop)
|
|
66
67
|
provideGlobal('usePageLiveRefresh', noop)
|
|
@@ -198,3 +199,72 @@ export function inBrowserApp<T>(setup: () => T, respond: Backend = () => ({})):
|
|
|
198
199
|
reads: () => reads.map((read) => describeRead(read.method, read.url, read.query)),
|
|
199
200
|
}
|
|
200
201
|
}
|
|
202
|
+
|
|
203
|
+
/** What `suspendedMount` gives back. */
|
|
204
|
+
export interface SuspendedMount {
|
|
205
|
+
/** Whether the Suspense waited for the component: it was not shown at once. */
|
|
206
|
+
waited: boolean
|
|
207
|
+
/** The backend requests made before the Suspense showed it, as `METHOD url?query`. */
|
|
208
|
+
readsBeforeShown: string[]
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Vue's renderer on bare objects: a browser mount and its Suspense, without a DOM.
|
|
212
|
+
const blankRenderer = vue.createRenderer<object, object>({
|
|
213
|
+
createElement: () => ({}),
|
|
214
|
+
createText: () => ({}),
|
|
215
|
+
createComment: () => ({}),
|
|
216
|
+
setText: noop,
|
|
217
|
+
setElementText: noop,
|
|
218
|
+
insert: noop,
|
|
219
|
+
remove: noop,
|
|
220
|
+
parentNode: () => null,
|
|
221
|
+
nextSibling: () => null,
|
|
222
|
+
patchProp: noop,
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Mounts `component` as a client navigation does, on the renderer's browser
|
|
227
|
+
* data layer with nothing read before, under the page's Suspense: whether the
|
|
228
|
+
* page waits for it, and what it read by the time it is shown. The test build
|
|
229
|
+
* compiles components for the server, so it renders nothing: the markup is
|
|
230
|
+
* `serverRender`'s to check.
|
|
231
|
+
*/
|
|
232
|
+
export async function suspendedMount(component: Component, options: { respond?: Backend } = {}): Promise<SuspendedMount> {
|
|
233
|
+
backend = options.respond ?? (() => ({}))
|
|
234
|
+
reads.length = 0
|
|
235
|
+
const runtime = engine.createDmsFrontendRuntime(undefined, {}, false)
|
|
236
|
+
let waited = false
|
|
237
|
+
let shown: (readsBeforeShown: string[]) => void = noop
|
|
238
|
+
const isShown = new Promise<string[]>((resolve) => {
|
|
239
|
+
shown = resolve
|
|
240
|
+
})
|
|
241
|
+
const app = blankRenderer.createApp({
|
|
242
|
+
render: () =>
|
|
243
|
+
h(
|
|
244
|
+
vue.Suspense,
|
|
245
|
+
{
|
|
246
|
+
onPending: () => {
|
|
247
|
+
waited = true
|
|
248
|
+
},
|
|
249
|
+
onResolve: () => shown(reads.map((read) => describeRead(read.method, read.url, read.query))),
|
|
250
|
+
},
|
|
251
|
+
{ default: () => h(component) },
|
|
252
|
+
),
|
|
253
|
+
})
|
|
254
|
+
engine.provideDmsFrontendRuntime(app, runtime)
|
|
255
|
+
// What the server build of a component records of itself, while it renders nowhere.
|
|
256
|
+
app.provide(vue.ssrContextKey, {})
|
|
257
|
+
for (const name of UI_COMPONENTS) app.component(name, uiStub(name))
|
|
258
|
+
Object.assign(app.config.globalProperties, autoImports)
|
|
259
|
+
app.config.warnHandler = noop
|
|
260
|
+
// The window the blocks listen on once mounted (a drop of files) and the history the library follows, for the time of the mount.
|
|
261
|
+
vi.stubGlobal('window', { addEventListener: noop, removeEventListener: noop, history: { state: null, replaceState: noop } })
|
|
262
|
+
try {
|
|
263
|
+
app.mount({})
|
|
264
|
+
const readsBeforeShown = await isShown
|
|
265
|
+
app.unmount()
|
|
266
|
+
return { waited, readsBeforeShown }
|
|
267
|
+
} finally {
|
|
268
|
+
vi.stubGlobal('window', undefined)
|
|
269
|
+
}
|
|
270
|
+
}
|
|
@@ -7,6 +7,13 @@ type Messages = { [key: string]: string | Messages }
|
|
|
7
7
|
const LOCALES_DIR = join(__dirname, '../i18n/locales')
|
|
8
8
|
const APP_DIR = join(__dirname, '../app')
|
|
9
9
|
const KEY_PATTERN = /\bt\(\s*'(dms_media\.[a-z0-9_.-]+)'/g
|
|
10
|
+
// What one line of an overview KPI card holds at four columns (183px of 12px
|
|
11
|
+
// text at 1440px wide): a detail on two lines makes the cards taller than their
|
|
12
|
+
// skeleton, and every block below moves when they land.
|
|
13
|
+
const KPI_DETAIL_MAX_LENGTH = 32
|
|
14
|
+
const KPI_DETAILS = ['files_detail', 'storage_detail', 'storage_quota_detail', 'public_share', 'missing_alt_none', 'missing_alt_public']
|
|
15
|
+
// The widest values a detail is written with.
|
|
16
|
+
const WIDEST_PARAMS: Record<string, string> = { files: '99,999', percent: '100', quota: '100 GB' }
|
|
10
17
|
|
|
11
18
|
function load(file: string): Messages {
|
|
12
19
|
return JSON.parse(readFileSync(join(LOCALES_DIR, file), 'utf8')) as Messages
|
|
@@ -34,6 +41,16 @@ describe('media locales', () => {
|
|
|
34
41
|
expect(leaves(french).sort()).toEqual(leaves(english).sort())
|
|
35
42
|
})
|
|
36
43
|
|
|
44
|
+
it('keeps each overview KPI detail on one line of its card', () => {
|
|
45
|
+
for (const messages of [english, french]) {
|
|
46
|
+
const kpis = ((messages.dms_media as Messages).overview as Messages).kpis as Messages
|
|
47
|
+
const written = KPI_DETAILS.flatMap((key) =>
|
|
48
|
+
(kpis[key] as string).split(' | ').map((form) => form.replace(/\{(\w+)\}/g, (_, name: string) => WIDEST_PARAMS[name] ?? name)),
|
|
49
|
+
)
|
|
50
|
+
expect(written.filter((text) => text.length > KPI_DETAIL_MAX_LENGTH)).toEqual([])
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
|
|
37
54
|
it('translates every literal key the layer uses', () => {
|
|
38
55
|
const known = new Set(leaves(english))
|
|
39
56
|
const used = sources(APP_DIR).flatMap((file) =>
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { defineComponent, h } from 'vue'
|
|
2
2
|
import { describe, expect, it } from 'vitest'
|
|
3
|
-
import { serverRender, type BackendRead } from './fixtures/serverRender'
|
|
3
|
+
import { serverRender, suspendedMount, type BackendRead } from './fixtures/serverRender'
|
|
4
4
|
import AssetValue from '../app/components/field/AssetValue.vue'
|
|
5
5
|
import Explorer from '../app/components/Explorer.vue'
|
|
6
6
|
import FileHeader from '../app/components/FileHeader.vue'
|
|
7
7
|
import FilePreview from '../app/components/FilePreview.vue'
|
|
8
8
|
import FileProperties from '../app/components/FileProperties.vue'
|
|
9
|
+
import FirstRun from '../app/components/FirstRun.vue'
|
|
9
10
|
import ImageEditor from '../app/components/ImageEditor.vue'
|
|
10
11
|
import PresetCards from '../app/components/PresetCards.vue'
|
|
11
12
|
import RecentFiles from '../app/components/RecentFiles.vue'
|
|
13
|
+
import UploadQueue from '../app/components/UploadQueue.vue'
|
|
14
|
+
import UploadStrip from '../app/components/UploadStrip.vue'
|
|
12
15
|
import { useFieldFolders } from '../app/composables/useFieldFolders'
|
|
13
16
|
import type { MediaAsset, MediaFolder } from '../app/types/media'
|
|
14
17
|
|
|
@@ -84,7 +87,7 @@ function backend({ url }: BackendRead): unknown {
|
|
|
84
87
|
return { assets: FILES }
|
|
85
88
|
case '/api/media/presets':
|
|
86
89
|
return {
|
|
87
|
-
presets: [{ id: 'thumb', width: 300, height: 300, fit: 'cover', cacheKey: 'thumb.1', rendered: 1, urlPattern: '', exampleUrl: null }],
|
|
90
|
+
presets: [{ id: 'thumb', width: 300, height: 300, fit: 'cover', cacheKey: 'thumb.1', rendered: 1, urlPattern: '', exampleUrl: null, examplePreviewUrl: null }],
|
|
88
91
|
cache: { schedule: '', lastSweepAt: null, lastSweepRemoved: null, publicTtlSeconds: 0, privateTtlSeconds: 0 },
|
|
89
92
|
isDefault: true,
|
|
90
93
|
example: null,
|
|
@@ -122,6 +125,21 @@ describe('server render: the blocks read with the page and hand it over', () =>
|
|
|
122
125
|
expect(page.html).toContain('thumb')
|
|
123
126
|
})
|
|
124
127
|
|
|
128
|
+
it('image sizes: the example loads on the dashboard origin, the copied link stays absolute', async () => {
|
|
129
|
+
const exampleUrl = 'https://api.example.com/media/a1/thumb/lighthouse.png'
|
|
130
|
+
const examplePreviewUrl = '/media/a1/thumb/lighthouse.png'
|
|
131
|
+
const presets = {
|
|
132
|
+
presets: [{ id: 'thumb', width: 300, height: 300, fit: 'cover', cacheKey: 'thumb.1', rendered: 1, urlPattern: '', exampleUrl, examplePreviewUrl }],
|
|
133
|
+
cache: { schedule: '', lastSweepAt: null, lastSweepRemoved: null, publicTtlSeconds: 0, privateTtlSeconds: 0 },
|
|
134
|
+
isDefault: false,
|
|
135
|
+
example: { id: 'a1', name: 'lighthouse.png', width: 1200, height: 800 },
|
|
136
|
+
}
|
|
137
|
+
const page = await serverRender(PresetCards, {}, { respond: (read) => (read.url === '/api/media/presets' ? presets : backend(read)) })
|
|
138
|
+
expect(page.html).toContain(`src="${examplePreviewUrl}"`)
|
|
139
|
+
expect(page.html).not.toContain(`src="${exampleUrl}"`)
|
|
140
|
+
expect(page.html).toContain(exampleUrl)
|
|
141
|
+
})
|
|
142
|
+
|
|
125
143
|
it('file page: one read of the file and its neighbours for the three blocks, and the image read URL', async () => {
|
|
126
144
|
const page = await render(FilePage, {}, '/modules/media/file?asset=a2')
|
|
127
145
|
expect(page.reads.sort()).toEqual(
|
|
@@ -214,3 +232,30 @@ describe('server render: the blocks read with the page and hand it over', () =>
|
|
|
214
232
|
expect(page.html).toContain('Demo covers')
|
|
215
233
|
})
|
|
216
234
|
})
|
|
235
|
+
|
|
236
|
+
// A page block that waits for its reads in `setup` is part of the page's
|
|
237
|
+
// Suspense: a client navigation shows it with its data, never a skeleton that
|
|
238
|
+
// the data then pushes around.
|
|
239
|
+
const PAGE_BLOCKS: [string, Parameters<typeof serverRender>[0], string[], string][] = [
|
|
240
|
+
['image sizes', PresetCards, ['GET /api/media/presets'], 'thumb'],
|
|
241
|
+
['recent files', RecentFiles, ['GET /api/media/stats/recent', 'GET /api/media/tree'], 'lighthouse.png'],
|
|
242
|
+
['upload strip', UploadStrip, ['GET /api/media/tree'], 'dms_media.upload_strip.choose'],
|
|
243
|
+
['upload queue', UploadQueue, ['GET /api/media/tree'], 'dms_media.queue.empty_description_drop'],
|
|
244
|
+
['first run', FirstRun, ['GET /api/media/tree'], ''],
|
|
245
|
+
['library', Explorer, ['GET /api/media/tree'], 'Catalog'],
|
|
246
|
+
]
|
|
247
|
+
|
|
248
|
+
describe('page blocks: shown with the page, without a skeleton', () => {
|
|
249
|
+
it.each(PAGE_BLOCKS)('%s: a client navigation waits for its reads', async (_, block, reads) => {
|
|
250
|
+
const mounted = await suspendedMount(block, { respond: backend })
|
|
251
|
+
expect(mounted.waited).toBe(true)
|
|
252
|
+
expect(mounted.readsBeforeShown).toEqual(expect.arrayContaining(reads))
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
it.each(PAGE_BLOCKS)('%s: the server render shows its data, no skeleton', async (_, block, reads, shown) => {
|
|
256
|
+
const page = await render(block)
|
|
257
|
+
expect(page.reads).toEqual(expect.arrayContaining(reads))
|
|
258
|
+
expect(page.html).toContain(shown)
|
|
259
|
+
expect(page.html).not.toContain('data-stub="USkeleton"')
|
|
260
|
+
})
|
|
261
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/dms-media",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
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",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"@antelopejs/interface-core": ">=0.2.4 <1.0.0",
|
|
69
69
|
"@antelopejs/interface-database": ">=0.1.10 <1.0.0",
|
|
70
70
|
"@antelopejs/interface-database-decorators": ">=0.1.9 <1.0.0",
|
|
71
|
-
"@antelopejs/interface-dms": ">=0.
|
|
71
|
+
"@antelopejs/interface-dms": ">=0.8.0 <1.0.0",
|
|
72
72
|
"@antelopejs/interface-dms-media": ">=0.3.0 <0.4.0",
|
|
73
73
|
"@antelopejs/interface-file-storage": ">=0.1.4 <1.0.0",
|
|
74
74
|
"node-cron": "^4.2.1",
|
|
@@ -76,9 +76,9 @@
|
|
|
76
76
|
"zod": "~3.24.2"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@antelopejs/core": ">=1.
|
|
80
|
-
"@antelopejs/dms": ">=0.
|
|
81
|
-
"@antelopejs/dms-frontend": "0.
|
|
79
|
+
"@antelopejs/core": ">=1.17.0 <2",
|
|
80
|
+
"@antelopejs/dms": ">=0.10.0 <1.0.0",
|
|
81
|
+
"@antelopejs/dms-frontend": "0.8.0",
|
|
82
82
|
"@antelopejs/tooling-configs": ">=0.0.9 <1.0.0",
|
|
83
83
|
"@types/chai": "^4.3.20",
|
|
84
84
|
"@types/mocha": "^10",
|
|
@@ -106,5 +106,6 @@
|
|
|
106
106
|
"skills": [
|
|
107
107
|
"./skills"
|
|
108
108
|
]
|
|
109
|
-
}
|
|
109
|
+
},
|
|
110
|
+
"dmsFrontend": "dist/frontend-module.js"
|
|
110
111
|
}
|
|
@@ -12,6 +12,10 @@ Asset library: folders with per-folder ACL, direct-to-storage uploads, stable `/
|
|
|
12
12
|
Owner pages under `/modules/media` (overview, files, uploads, file, editor, activity, presets). Members never open them:
|
|
13
13
|
they reach media through `AssetType` fields on project pages. User docs: `docs/` of this package, published at
|
|
14
14
|
https://dms.antelopejs.com/docs/modules/media.
|
|
15
|
+
Overview, uploads and activity are `live` pages (shared `rememberKey: "media"`) opening on the DMS `pageToolbar({ period: false })`
|
|
16
|
+
(last read + Direct / Pause, block id `toolbar`); the upload history table is `liveHold`. Needs interface-dms with `base/page-toolbar`.
|
|
17
|
+
Every data block carries `realtimeTopic: MEDIA_LIBRARY_TOPIC`; custom components refresh through `onLibraryChange` (DMS
|
|
18
|
+
`usePageLiveRefresh`, so Pause holds them). Announcements are coalesced and carry `payload.count` (changes they stand for).
|
|
15
19
|
|
|
16
20
|
## Setup
|
|
17
21
|
|
|
@@ -100,6 +104,8 @@ export async function declareMedia(tenantId: string): Promise<void> {
|
|
|
100
104
|
- The module declares `/media/**` to the frontend server (`backendProxies`, `auth: "session"`): the same links work on
|
|
101
105
|
the dashboard's origin, a private file opening for a signed-in member. Copied links start with `publicBaseUrl`.
|
|
102
106
|
- Authenticated: `GET /api/media/assets/:id/read-url?preset=`.
|
|
107
|
+
- An image the dashboard shows uses a relative `/media/...` path or a signed read URL, never a `publicBaseUrl` link:
|
|
108
|
+
the API's origin carries no session cookie, so a private file answers 401 there.
|
|
103
109
|
|
|
104
110
|
## Gotchas
|
|
105
111
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type {
|
|
3
|
+
AddFrontendModuleOptions,
|
|
4
|
+
FrontendBackendProxy,
|
|
5
|
+
} from "@antelopejs/interface-dms/page";
|
|
6
|
+
|
|
7
|
+
/** The frontend module the dashboard loads: its blocks, viewers and fields. */
|
|
8
|
+
export const MEDIA_FRONTEND_MODULE = "@antelopejs/dms-media-frontend-vue";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The file links a dashboard page shows (`/media/<id>/<name>`), which the
|
|
12
|
+
* backend serves: proxied by the frontend server with the member's session,
|
|
13
|
+
* so that a private file opens for a member signed in, as on the API origin.
|
|
14
|
+
*/
|
|
15
|
+
export const MEDIA_DELIVERY_PROXY: FrontendBackendProxy = {
|
|
16
|
+
path: "/media/**",
|
|
17
|
+
auth: "session",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* This module's frontend, from its configuration alone: the backend registers
|
|
22
|
+
* it with `AddFrontendModule`, and `@antelopejs/dms-frontend` calls this same
|
|
23
|
+
* function (declared as `dmsFrontend` in package.json) to build and start the
|
|
24
|
+
* frontend without a backend. It reads nothing but its arguments.
|
|
25
|
+
*/
|
|
26
|
+
export function frontendModule(): AddFrontendModuleOptions {
|
|
27
|
+
return {
|
|
28
|
+
name: MEDIA_FRONTEND_MODULE,
|
|
29
|
+
sourcePath: path.join(__dirname, "../frontend-vue"),
|
|
30
|
+
renderer: { name: "vue", version: "3" },
|
|
31
|
+
configKey: "dmsMedia",
|
|
32
|
+
priority: 0,
|
|
33
|
+
backendProxies: [MEDIA_DELIVERY_PROXY],
|
|
34
|
+
};
|
|
35
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
1
|
import { ImplementInterface } from "@antelopejs/interface-core";
|
|
3
|
-
import {
|
|
4
|
-
AddFrontendModule,
|
|
5
|
-
type FrontendBackendProxy,
|
|
6
|
-
} from "@antelopejs/interface-dms/page";
|
|
2
|
+
import { AddFrontendModule } from "@antelopejs/interface-dms/page";
|
|
7
3
|
import { Logging } from "@antelopejs/interface-core/logging";
|
|
8
4
|
import "./db";
|
|
9
5
|
import type { ScheduledTask } from "node-cron";
|
|
10
6
|
import { type DmsMediaConfig, configureMediaModule } from "./config";
|
|
11
7
|
import { registerMediaCrons } from "./crons";
|
|
8
|
+
import { frontendModule } from "./frontend-module";
|
|
12
9
|
import { cancelLibraryChange } from "./library/realtime";
|
|
13
10
|
|
|
14
11
|
export * from "./acl";
|
|
@@ -18,6 +15,7 @@ export * from "./constants";
|
|
|
18
15
|
export * from "./crons";
|
|
19
16
|
export * from "./db";
|
|
20
17
|
export * from "./derivatives";
|
|
18
|
+
export * from "./frontend-module";
|
|
21
19
|
export * from "./pages";
|
|
22
20
|
export * from "./presets";
|
|
23
21
|
export * from "./routes";
|
|
@@ -26,35 +24,13 @@ export * from "./types";
|
|
|
26
24
|
|
|
27
25
|
let cronTasks: ScheduledTask[] = [];
|
|
28
26
|
|
|
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
|
-
|
|
42
27
|
export async function construct(config: DmsMediaConfig = {}): Promise<void> {
|
|
43
28
|
configureMediaModule(config);
|
|
44
29
|
ImplementInterface(
|
|
45
30
|
await import("@antelopejs/interface-dms-media"),
|
|
46
31
|
await import("./implementations/interface-dms-media"),
|
|
47
32
|
);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
await AddFrontendModule({
|
|
51
|
-
name: MEDIA_FRONTEND_MODULE,
|
|
52
|
-
sourcePath,
|
|
53
|
-
renderer: { name: "vue", version: "3" },
|
|
54
|
-
configKey: "dmsMedia",
|
|
55
|
-
priority: 0,
|
|
56
|
-
backendProxies: [MEDIA_DELIVERY_PROXY],
|
|
57
|
-
});
|
|
33
|
+
await AddFrontendModule(frontendModule());
|
|
58
34
|
}
|
|
59
35
|
|
|
60
36
|
export function start(): void {
|
package/src/library/realtime.ts
CHANGED
|
@@ -10,12 +10,18 @@ const LIBRARY_CHANGED = "changed";
|
|
|
10
10
|
|
|
11
11
|
let pending: ReturnType<typeof setTimeout> | undefined;
|
|
12
12
|
let pendingDueAt = 0;
|
|
13
|
+
let pendingChanges = 0;
|
|
13
14
|
let version = 0;
|
|
14
15
|
|
|
15
16
|
async function publishNow(): Promise<void> {
|
|
16
17
|
pending = undefined;
|
|
18
|
+
// A paused page counts `payload.count` as that many missed changes, not one per announcement.
|
|
19
|
+
const count = pendingChanges;
|
|
20
|
+
pendingChanges = 0;
|
|
17
21
|
try {
|
|
18
|
-
await PublishMessage(MEDIA_LIBRARY_TOPIC, LIBRARY_CHANGED
|
|
22
|
+
await PublishMessage(MEDIA_LIBRARY_TOPIC, LIBRARY_CHANGED, {
|
|
23
|
+
payload: { count },
|
|
24
|
+
});
|
|
19
25
|
} catch (error) {
|
|
20
26
|
Logging.Error("Failed to publish a media library change", error);
|
|
21
27
|
}
|
|
@@ -23,11 +29,13 @@ async function publishNow(): Promise<void> {
|
|
|
23
29
|
|
|
24
30
|
/**
|
|
25
31
|
* Tells the pages showing the library that it changed, so their blocks read
|
|
26
|
-
* their routes again. The message carries
|
|
27
|
-
* its reader may see. An announcement already
|
|
32
|
+
* their routes again. The message carries only how many changes it stands
|
|
33
|
+
* for: each block re-reads what its reader may see. An announcement already
|
|
34
|
+
* due sooner absorbs this one.
|
|
28
35
|
*/
|
|
29
36
|
export function announceLibraryChange(delayMs = COALESCE_WINDOW_MS): void {
|
|
30
37
|
version += 1;
|
|
38
|
+
pendingChanges += 1;
|
|
31
39
|
const dueAt = Date.now() + delayMs;
|
|
32
40
|
if (pending && pendingDueAt <= dueAt) return;
|
|
33
41
|
clearTimeout(pending);
|
|
@@ -45,4 +53,5 @@ export function libraryVersion(): number {
|
|
|
45
53
|
export function cancelLibraryChange(): void {
|
|
46
54
|
clearTimeout(pending);
|
|
47
55
|
pending = undefined;
|
|
56
|
+
pendingChanges = 0;
|
|
48
57
|
}
|
package/src/pages/activity.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { MEDIA_LIBRARY_TOPIC } from "../constants";
|
|
|
7
7
|
import { ACTIVITY_FILTERS, type ActivityFilter } from "../library/activity";
|
|
8
8
|
import { libraryCategory, MEDIA_MODULE_ID } from "./module";
|
|
9
9
|
import { blockMeta } from "./texts";
|
|
10
|
+
import { MEDIA_LIVE, mediaPageToolbar } from "./toolbar";
|
|
10
11
|
|
|
11
12
|
const TEXTS = "$dms_media.activity_page";
|
|
12
13
|
const FEED_LENGTH = 50;
|
|
@@ -57,9 +58,12 @@ export class MediaActivityPage extends PageController(
|
|
|
57
58
|
icon: "i-ph-clock-counter-clockwise",
|
|
58
59
|
hidden: true,
|
|
59
60
|
order: 5,
|
|
61
|
+
live: MEDIA_LIVE,
|
|
60
62
|
},
|
|
61
63
|
DefaultLayout(),
|
|
62
64
|
) {
|
|
65
|
+
static toolbar = mediaPageToolbar();
|
|
66
|
+
|
|
63
67
|
static feed = Card()
|
|
64
68
|
.meta(blockMeta("activity_log", "i-ph-clock-counter-clockwise"))
|
|
65
69
|
.child("filters", filteredFeeds());
|
package/src/pages/overview.ts
CHANGED
|
@@ -12,10 +12,9 @@ import { MEDIA_ROUTES, viewLink } from "../library/links";
|
|
|
12
12
|
import { libraryCategory, MEDIA_MODULE_ID } from "./module";
|
|
13
13
|
import { blockMeta } from "./texts";
|
|
14
14
|
import { MEDIA_LIBRARY_TOPIC } from "../constants";
|
|
15
|
+
import { MEDIA_LIVE, mediaPageToolbar } from "./toolbar";
|
|
15
16
|
|
|
16
17
|
const TEXTS = "$dms_media.overview";
|
|
17
|
-
/** Shortest interval, in seconds, between two refetches of a block while files upload. */
|
|
18
|
-
const LIVE_MAX_RATE_SECONDS = 2;
|
|
19
18
|
const GAP = "1rem";
|
|
20
19
|
const MIN_COLUMN_WIDTH = "320px";
|
|
21
20
|
const WIDE_SPAN = 2;
|
|
@@ -83,7 +82,7 @@ export class MediaOverviewPage extends PageController(
|
|
|
83
82
|
module: MEDIA_MODULE_ID,
|
|
84
83
|
icon: "i-ph-squares-four",
|
|
85
84
|
order: 0,
|
|
86
|
-
live:
|
|
85
|
+
live: MEDIA_LIVE,
|
|
87
86
|
},
|
|
88
87
|
DefaultLayout({
|
|
89
88
|
headerActions: [
|
|
@@ -98,6 +97,8 @@ export class MediaOverviewPage extends PageController(
|
|
|
98
97
|
],
|
|
99
98
|
}),
|
|
100
99
|
) {
|
|
100
|
+
static toolbar = mediaPageToolbar();
|
|
101
|
+
|
|
101
102
|
static firstRun = CustomComponent("DmsMediaFirstRun").meta(
|
|
102
103
|
blockMeta("first_run", "i-ph-sparkle"),
|
|
103
104
|
);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { pageToolbar } from "@antelopejs/interface-dms/base/page-toolbar";
|
|
2
|
+
import type { PageLiveOptions } from "@antelopejs/interface-dms/page";
|
|
3
|
+
import { MEDIA_MODULE_ID } from "./module";
|
|
4
|
+
import { blockMeta } from "./texts";
|
|
5
|
+
|
|
6
|
+
/** Shortest interval, in seconds, between two refetches of a block while files upload. */
|
|
7
|
+
const LIVE_MAX_RATE_SECONDS = 2;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Live mode of the media pages that follow the library as it changes. They
|
|
11
|
+
* share one Direct / Pause choice: pausing the overview pauses the uploads too.
|
|
12
|
+
*/
|
|
13
|
+
export const MEDIA_LIVE: PageLiveOptions = {
|
|
14
|
+
maxRate: LIVE_MAX_RATE_SECONDS,
|
|
15
|
+
rememberKey: MEDIA_MODULE_ID,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The DMS page toolbar of a live media page, first in its body: when the page
|
|
20
|
+
* last read the library and Direct / Pause. No period: the library's figures
|
|
21
|
+
* are a snapshot, not a window of time.
|
|
22
|
+
*/
|
|
23
|
+
export function mediaPageToolbar() {
|
|
24
|
+
return pageToolbar({
|
|
25
|
+
live: { missedLabel: "$dms_media.live.missed" },
|
|
26
|
+
period: false,
|
|
27
|
+
}).meta(blockMeta("page_toolbar", "i-ph-sliders-horizontal"));
|
|
28
|
+
}
|
package/src/pages/uploads.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { libraryCategory, MEDIA_MODULE_ID } from "./module";
|
|
|
10
10
|
import { blockMeta } from "./texts";
|
|
11
11
|
import { uploadAvailability } from "./upload-availability";
|
|
12
12
|
import { MEDIA_LIBRARY_TOPIC } from "../constants";
|
|
13
|
+
import { MEDIA_LIVE, mediaPageToolbar } from "./toolbar";
|
|
13
14
|
|
|
14
15
|
const TEXTS = "$dms_media.uploads";
|
|
15
16
|
const HISTORY_PAGE_SIZE = 10;
|
|
@@ -19,6 +20,7 @@ const history = TableView.fromSource({
|
|
|
19
20
|
caption: `${TEXTS}.history.title`,
|
|
20
21
|
fetchUrl: "/api/media/upload/batches",
|
|
21
22
|
realtimeTopic: MEDIA_LIBRARY_TOPIC,
|
|
23
|
+
liveHold: true,
|
|
22
24
|
layout: "full",
|
|
23
25
|
density: "compact",
|
|
24
26
|
pageSize: HISTORY_PAGE_SIZE,
|
|
@@ -117,6 +119,7 @@ export class MediaUploadsPage extends PageController(
|
|
|
117
119
|
module: MEDIA_MODULE_ID,
|
|
118
120
|
icon: "i-ph-cloud-arrow-up",
|
|
119
121
|
order: 2,
|
|
122
|
+
live: MEDIA_LIVE,
|
|
120
123
|
},
|
|
121
124
|
DefaultLayout({
|
|
122
125
|
headerActions: [
|
|
@@ -132,6 +135,8 @@ export class MediaUploadsPage extends PageController(
|
|
|
132
135
|
],
|
|
133
136
|
}),
|
|
134
137
|
) {
|
|
138
|
+
static toolbar = mediaPageToolbar();
|
|
139
|
+
|
|
135
140
|
static queue = CustomComponent("DmsMediaUploadQueue").meta(
|
|
136
141
|
blockMeta("upload_queue", "i-ph-cloud-arrow-up"),
|
|
137
142
|
);
|