@antelopejs/dms-media 0.3.0 → 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.
- package/README.md +5 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/pages/uploads.js +2 -1
- package/dist/pages/uploads.js.map +1 -1
- package/dist/test/antelope.test.js +3 -2
- package/dist/test/antelope.test.js.map +1 -1
- package/dist/test/helpers/pages.js +3 -2
- package/dist/test/helpers/pages.js.map +1 -1
- package/dist/test/integration/frontend-module.test.d.ts +1 -0
- package/dist/test/integration/frontend-module.test.js +13 -0
- package/dist/test/integration/frontend-module.test.js.map +1 -0
- package/dist/test/unit/config.test.js +0 -4
- package/dist/test/unit/config.test.js.map +1 -1
- package/frontend-vue/app/components/FileProperties.vue +9 -3
- package/frontend-vue/app/components/FirstRun.vue +1 -1
- package/frontend-vue/app/components/ImageEditor.vue +43 -26
- package/frontend-vue/app/components/PresetCards.vue +3 -11
- package/frontend-vue/app/components/RecentFiles.vue +6 -14
- package/frontend-vue/app/components/UploadQueue.vue +1 -1
- package/frontend-vue/app/components/UploadStrip.vue +1 -1
- package/frontend-vue/app/components/dialogs/DestinationDialog.vue +1 -2
- package/frontend-vue/app/components/explorer/ExplorerInspector.vue +17 -16
- package/frontend-vue/app/components/explorer/ExplorerShell.vue +11 -3
- package/frontend-vue/app/components/explorer/ExplorerToolbar.vue +2 -1
- package/frontend-vue/app/components/field/AssetValue.vue +12 -13
- package/frontend-vue/app/components/file/FileViewer.vue +1 -14
- package/frontend-vue/app/composables/library/useLibraryListing.ts +180 -79
- package/frontend-vue/app/composables/library/useLibraryTree.ts +31 -15
- package/frontend-vue/app/composables/library/useMediaLibrary.ts +17 -7
- package/frontend-vue/app/composables/uploadLimits.ts +25 -0
- package/frontend-vue/app/composables/useAssetContent.ts +20 -0
- package/frontend-vue/app/composables/useCurrentFile.ts +10 -8
- package/frontend-vue/app/composables/useFieldFolders.ts +19 -18
- package/frontend-vue/app/composables/useFileDetails.ts +117 -90
- package/frontend-vue/app/composables/useMediaApi.ts +18 -24
- package/frontend-vue/i18n/locales/media-en-GB.json +1 -0
- package/frontend-vue/i18n/locales/media-fr-FR.json +1 -0
- package/frontend-vue/package.json +2 -1
- package/frontend-vue/pnpm-lock.yaml +17 -2
- package/frontend-vue/tests/engines.test.ts +20 -0
- package/frontend-vue/tests/fixtures/inertia.ts +8 -0
- package/frontend-vue/tests/fixtures/serverRender.ts +200 -0
- package/frontend-vue/tests/fixtures/unhead.ts +3 -0
- package/frontend-vue/tests/fixtures/vueI18n.ts +4 -0
- package/frontend-vue/tests/libraryListing.test.ts +120 -0
- package/frontend-vue/tests/serverRender.test.ts +215 -0
- package/frontend-vue/vitest.config.ts +21 -0
- package/package.json +16 -10
- package/src/index.ts +19 -2
- package/src/pages/uploads.ts +2 -1
- package/src/test/antelope.test.ts +3 -2
- package/src/test/helpers/pages.ts +3 -2
- package/src/test/integration/frontend-module.test.ts +13 -0
- package/src/test/unit/config.test.ts +0 -5
- package/frontend-vue/app/composables/useSharedTree.ts +0 -73
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createSharedComposable } from '@vueuse/core'
|
|
2
1
|
import type { AssetSortKey, AssetTypeGroup, SortDirection } from '../types/media'
|
|
3
2
|
import type { FileListingOrder } from '../utils/mediaFiles'
|
|
4
3
|
import MediaLightbox from '../components/shared/MediaLightbox.vue'
|
|
@@ -11,16 +10,18 @@ function queryValue<T extends string>(value: unknown, allowed: readonly T[]): T
|
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
|
-
* The file the file page shows, named by its `asset` query parameter
|
|
15
|
-
*
|
|
16
|
-
* rename in the properties shows in the header at once
|
|
17
|
-
*
|
|
13
|
+
* The file the file page shows, named by its `asset` query parameter. Each of
|
|
14
|
+
* the page's blocks (header, viewer, properties) reads it, and they share the
|
|
15
|
+
* read: a rename in the properties shows in the header at once, and a server
|
|
16
|
+
* render reads the file once. Its `sort`, `direction` and `type` parameters
|
|
17
|
+
* keep the explorer's order for previous and next.
|
|
18
18
|
*/
|
|
19
|
-
export
|
|
19
|
+
export function useCurrentFile() {
|
|
20
20
|
const route = useDmsRoute()
|
|
21
21
|
const router = useDmsRouter()
|
|
22
22
|
const overlay = useOverlay()
|
|
23
|
-
const
|
|
23
|
+
const createLightbox = () => overlay.create(MediaLightbox)
|
|
24
|
+
let lightbox: ReturnType<typeof createLightbox> | undefined
|
|
24
25
|
const assetId = computed(() => (typeof route.query.asset === 'string' ? route.query.asset : undefined))
|
|
25
26
|
const order = computed<FileListingOrder>(() => ({
|
|
26
27
|
sort: queryValue(route.query.sort, SORT_KEYS),
|
|
@@ -37,6 +38,7 @@ export const useCurrentFile = createSharedComposable(() => {
|
|
|
37
38
|
async function fullscreen(): Promise<void> {
|
|
38
39
|
const asset = file.asset.value
|
|
39
40
|
if (!asset) return
|
|
41
|
+
lightbox ??= createLightbox()
|
|
40
42
|
const shownId = await lightbox.open({
|
|
41
43
|
assets: file.siblings.value.length ? file.siblings.value : [asset],
|
|
42
44
|
startId: asset.id,
|
|
@@ -51,4 +53,4 @@ export const useCurrentFile = createSharedComposable(() => {
|
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
return { ...file, assetId, order, open, fullscreen, edit }
|
|
54
|
-
}
|
|
56
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ComputedRef } from 'vue'
|
|
2
|
-
import type { MediaFolder } from '../types/media'
|
|
2
|
+
import type { BoundFolderAnswer, MediaFolder } from '../types/media'
|
|
3
3
|
|
|
4
4
|
interface FolderSource {
|
|
5
5
|
/** The folder the field's binding created, when it has one the user can see. */
|
|
@@ -11,34 +11,35 @@ interface FolderSource {
|
|
|
11
11
|
ensureLoaded: () => Promise<void>
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* A bound field only needs its own folder: it reads that one alone, not the
|
|
16
|
+
* whole tree, with the page. A failed read keeps the folder last read.
|
|
17
|
+
*/
|
|
15
18
|
function useBoundFolder(bindingId: string): FolderSource {
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
+
// Read again on each library change, its own trigger: the page's refreshes leave it alone.
|
|
20
|
+
const read = useApiData<BoundFolderAnswer>(MEDIA_READS.boundFolder(bindingId), { refreshOnPageRefresh: false })
|
|
21
|
+
const folder = computed(() => read.data.value?.folder ?? undefined)
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
onMounted(() => void load())
|
|
29
|
-
onLibraryChange(load)
|
|
23
|
+
watch(
|
|
24
|
+
read.data,
|
|
25
|
+
(answer) => {
|
|
26
|
+
if (answer) rememberUploadLimits(answer)
|
|
27
|
+
},
|
|
28
|
+
{ immediate: true },
|
|
29
|
+
)
|
|
30
|
+
onLibraryChange(() => read.refresh())
|
|
30
31
|
|
|
31
32
|
return {
|
|
32
|
-
boundFolder:
|
|
33
|
+
boundFolder: folder,
|
|
33
34
|
folders: computed(() => (folder.value ? [folder.value] : [])),
|
|
34
35
|
canWriteRoot: computed(() => false),
|
|
35
|
-
ensureLoaded: () => (
|
|
36
|
+
ensureLoaded: () => (read.data.value ? Promise.resolve() : read.refresh()),
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
/** A field without a binding picks anywhere: it shares the page's folder tree. */
|
|
40
41
|
function useTreeFolders(): FolderSource {
|
|
41
|
-
const { tree, reload } =
|
|
42
|
+
const { tree, refresh: reload } = useLibraryTree()
|
|
42
43
|
return {
|
|
43
44
|
boundFolder: computed(() => undefined),
|
|
44
45
|
folders: computed(() => tree.value?.folders ?? []),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ApiDataContext, ApiDataResult } from '#dms-core/app/composables/auth/useApiData'
|
|
1
2
|
import type { AssetDetails, AssetPage, AssetVisibility, MediaAsset } from '../types/media'
|
|
2
3
|
import type { FileListingOrder } from '../utils/mediaFiles'
|
|
3
4
|
|
|
@@ -6,30 +7,109 @@ const SIBLINGS_HALF_WINDOW = SIBLINGS_PAGE_SIZE / 2
|
|
|
6
7
|
const SIBLINGS_EDGE_MARGIN = 20
|
|
7
8
|
const DEFAULT_SIBLINGS_SORT = 'name'
|
|
8
9
|
|
|
10
|
+
/** The page of the file's folder the previous and next files come from. */
|
|
11
|
+
interface SiblingsWindow {
|
|
12
|
+
folderId: string
|
|
13
|
+
/** The order it was read in, as `orderKey` writes it. */
|
|
14
|
+
order: string
|
|
15
|
+
/** A write may have moved the file among them: the next read of the file reads them again. */
|
|
16
|
+
isStale?: boolean
|
|
17
|
+
assets: MediaAsset[]
|
|
18
|
+
offset: number
|
|
19
|
+
total: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** What the file page reads at once: the file, and the files around it in its folder. */
|
|
23
|
+
interface FileRead {
|
|
24
|
+
details: AssetDetails
|
|
25
|
+
siblings: SiblingsWindow
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const orderKey = (order: FileListingOrder) => JSON.stringify([order.sort, order.direction, order.type])
|
|
29
|
+
|
|
30
|
+
function isNearWindowEdge(window: SiblingsWindow, id: string): boolean {
|
|
31
|
+
const position = window.assets.findIndex((entry) => entry.id === id)
|
|
32
|
+
if (position < 0) return true
|
|
33
|
+
const hasBefore = window.offset > 0
|
|
34
|
+
const hasAfter = window.offset + window.assets.length < window.total
|
|
35
|
+
return (hasBefore && position < SIBLINGS_EDGE_MARGIN) || (hasAfter && position >= window.assets.length - SIBLINGS_EDGE_MARGIN)
|
|
36
|
+
}
|
|
37
|
+
|
|
9
38
|
/**
|
|
10
39
|
* One file of the library, its neighbours in the folder (in the order and
|
|
11
|
-
* filter the explorer showed them in) and the writes on it.
|
|
12
|
-
*
|
|
13
|
-
* a
|
|
40
|
+
* filter the explorer showed them in) and the writes on it. The file and its
|
|
41
|
+
* neighbours are read with the page, under one key per file: the page's blocks
|
|
42
|
+
* share the read, and a server render hands it over. Moving to the next file
|
|
43
|
+
* reads that file alone while it sits well inside the neighbours already read.
|
|
44
|
+
* It follows the library's realtime topic, so a change made elsewhere (a
|
|
45
|
+
* revert, a rename, a deletion) shows at once.
|
|
14
46
|
*/
|
|
15
47
|
export function useFileDetails(assetId: Ref<string | undefined>, order: Ref<FileListingOrder> = ref({})) {
|
|
16
48
|
const api = useMediaApi()
|
|
17
49
|
const { t } = useI18n()
|
|
18
50
|
const toast = useToast()
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
51
|
+
const { tree, refresh: refreshTree } = useLibraryTree()
|
|
52
|
+
|
|
53
|
+
async function readSiblings(fetch: ApiDataContext['$authFetch'], signal: AbortSignal, folderId: string, id: string): Promise<SiblingsWindow> {
|
|
54
|
+
const current = order.value
|
|
55
|
+
const page = (offset: number) =>
|
|
56
|
+
fetch<AssetPage>(MEDIA_READS.folderAssets(folderId), {
|
|
57
|
+
query: { ...current, sort: current.sort ?? DEFAULT_SIBLINGS_SORT, offset, limit: SIBLINGS_PAGE_SIZE },
|
|
58
|
+
signal,
|
|
59
|
+
})
|
|
60
|
+
let offset = 0
|
|
61
|
+
let found = await page(offset)
|
|
62
|
+
const holds = (candidate: AssetPage) => candidate.assets.some((entry) => entry.id === id)
|
|
63
|
+
while (!holds(found) && found.assets.length > 0 && offset + found.assets.length < found.total) {
|
|
64
|
+
offset += found.assets.length
|
|
65
|
+
found = await page(offset)
|
|
66
|
+
}
|
|
67
|
+
const position = found.assets.findIndex((entry) => entry.id === id)
|
|
68
|
+
const isInFirstHalf = offset === 0 && position < SIBLINGS_HALF_WINDOW
|
|
69
|
+
const centered = position < 0 || isInFirstHalf ? offset : Math.max(0, offset + position - SIBLINGS_HALF_WINDOW)
|
|
70
|
+
if (centered !== offset) found = await page(centered)
|
|
71
|
+
return { folderId, order: orderKey(current), assets: found.assets, offset: centered, total: found.total }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const read: ApiDataResult<FileRead> = useApiData<FileRead>(
|
|
75
|
+
() => (assetId.value ? `dms-media:file:${assetId.value}:${orderKey(order.value)}` : null),
|
|
76
|
+
async ({ $authFetch, signal }): Promise<FileRead> => {
|
|
77
|
+
const id = assetId.value!
|
|
78
|
+
const details = await $authFetch<AssetDetails>(MEDIA_READS.details(id), { signal })
|
|
79
|
+
// The neighbours last read, by this key or the previous file's.
|
|
80
|
+
const previous = read.data.value?.siblings
|
|
81
|
+
const keepsWindow =
|
|
82
|
+
previous !== undefined &&
|
|
83
|
+
!previous.isStale &&
|
|
84
|
+
previous.folderId === details.asset.folderId &&
|
|
85
|
+
previous.order === orderKey(order.value) &&
|
|
86
|
+
!isNearWindowEdge(previous, id)
|
|
87
|
+
return { details, siblings: keepsWindow ? previous : await readSiblings($authFetch, signal, details.asset.folderId, id) }
|
|
88
|
+
},
|
|
89
|
+
// Read again on each library change, its own trigger: the page's refreshes leave it alone.
|
|
90
|
+
{ refreshOnPageRefresh: false },
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
const error = computed(() => read.error.value)
|
|
94
|
+
/** A failed read shows no file, whatever it showed before. */
|
|
95
|
+
const details = computed(() => (error.value ? null : (read.data.value?.details ?? null)))
|
|
96
|
+
/** The file shown was deleted: it is gone on the next read, not a link to a file that never was. */
|
|
97
|
+
const isDeleted = computed(
|
|
98
|
+
() => isNotFoundError(error.value) && read.data.value?.details.asset.id === assetId.value,
|
|
99
|
+
)
|
|
100
|
+
const siblingsWindow = computed(() => read.data.value?.siblings)
|
|
101
|
+
const siblings = computed(() => {
|
|
102
|
+
const list = siblingsWindow.value?.assets ?? []
|
|
103
|
+
return isDeleted.value ? list.filter((entry) => entry.id !== assetId.value) : list
|
|
104
|
+
})
|
|
105
|
+
const isLoading = computed(() => read.pending.value)
|
|
106
|
+
/** The folder of the file last read, kept once it is gone. */
|
|
107
|
+
const lastFolderId = computed(() => read.data.value?.details.asset.folderId ?? null)
|
|
28
108
|
|
|
29
109
|
const asset = computed(() => details.value?.asset)
|
|
30
110
|
const localIndex = computed(() => siblings.value.findIndex((entry) => entry.id === assetId.value))
|
|
31
|
-
const index = computed(() => (localIndex.value < 0 ? -1 :
|
|
32
|
-
const total = computed(() =>
|
|
111
|
+
const index = computed(() => (localIndex.value < 0 ? -1 : (siblingsWindow.value?.offset ?? 0) + localIndex.value))
|
|
112
|
+
const total = computed(() => siblingsWindow.value?.total ?? 0)
|
|
33
113
|
const previous = computed(() => (localIndex.value > 0 ? siblings.value[localIndex.value - 1] : undefined))
|
|
34
114
|
const next = computed(() =>
|
|
35
115
|
localIndex.value >= 0 && localIndex.value < siblings.value.length - 1 ? siblings.value[localIndex.value + 1] : undefined,
|
|
@@ -39,72 +119,28 @@ export function useFileDetails(assetId: Ref<string | undefined>, order: Ref<File
|
|
|
39
119
|
() => Boolean(details.value?.folder.rights.manage) && Boolean(tree.value?.isOwner),
|
|
40
120
|
)
|
|
41
121
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
/** The page of the folder holding the file, re-read around it when it sits near an end. */
|
|
52
|
-
async function loadSiblings(folderId: string, id: string): Promise<void> {
|
|
53
|
-
let offset = 0
|
|
54
|
-
let page = await fetchSiblings(folderId, offset)
|
|
55
|
-
const holds = (candidate: AssetPage) => candidate.assets.some((entry) => entry.id === id)
|
|
56
|
-
while (!holds(page) && page.assets.length > 0 && offset + page.assets.length < page.total) {
|
|
57
|
-
offset += page.assets.length
|
|
58
|
-
page = await fetchSiblings(folderId, offset)
|
|
59
|
-
}
|
|
60
|
-
const found = page.assets.findIndex((entry) => entry.id === id)
|
|
61
|
-
const isInFirstHalf = offset === 0 && found < SIBLINGS_HALF_WINDOW
|
|
62
|
-
const centered = found < 0 || isInFirstHalf ? offset : Math.max(0, offset + found - SIBLINGS_HALF_WINDOW)
|
|
63
|
-
if (centered !== offset) page = await fetchSiblings(folderId, centered)
|
|
64
|
-
siblings.value = page.assets
|
|
65
|
-
siblingsOffset.value = centered
|
|
66
|
-
siblingsTotal.value = page.total
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function isNearWindowEdge(id: string): boolean {
|
|
70
|
-
const position = siblings.value.findIndex((entry) => entry.id === id)
|
|
71
|
-
if (position < 0) return true
|
|
72
|
-
const hasBefore = siblingsOffset.value > 0
|
|
73
|
-
const hasAfter = siblingsOffset.value + siblings.value.length < siblingsTotal.value
|
|
74
|
-
return (hasBefore && position < SIBLINGS_EDGE_MARGIN) || (hasAfter && position >= siblings.value.length - SIBLINGS_EDGE_MARGIN)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function markUnavailable(cause: unknown): void {
|
|
78
|
-
const wasShown = details.value?.asset.id === assetId.value
|
|
79
|
-
if (wasShown && isNotFoundError(cause)) {
|
|
80
|
-
isDeleted.value = true
|
|
81
|
-
siblings.value = siblings.value.filter((entry) => entry.id !== assetId.value)
|
|
82
|
-
}
|
|
83
|
-
details.value = null
|
|
84
|
-
error.value = cause
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async function load(id: string, refreshSiblings = false): Promise<void> {
|
|
88
|
-
isLoading.value = true
|
|
89
|
-
try {
|
|
90
|
-
const loaded = await api.details(id)
|
|
91
|
-
const folderChanged = loaded.asset.folderId !== details.value?.asset.folderId
|
|
92
|
-
details.value = loaded
|
|
93
|
-
lastFolderId.value = loaded.asset.folderId
|
|
94
|
-
error.value = null
|
|
95
|
-
isDeleted.value = false
|
|
96
|
-
if (refreshSiblings || folderChanged || isNearWindowEdge(id)) await loadSiblings(loaded.asset.folderId, id)
|
|
97
|
-
} catch (cause) {
|
|
98
|
-
markUnavailable(cause)
|
|
99
|
-
} finally {
|
|
100
|
-
isLoading.value = false
|
|
101
|
-
}
|
|
122
|
+
/**
|
|
123
|
+
* Reads the file again; with `rereadSiblings`, its neighbours too. The
|
|
124
|
+
* blocks asking at once share one request.
|
|
125
|
+
*/
|
|
126
|
+
function load(rereadSiblings = false): Promise<void> {
|
|
127
|
+
const shown = read.data.value
|
|
128
|
+
if (rereadSiblings && shown) read.data.value = { ...shown, siblings: { ...shown.siblings, isStale: true } }
|
|
129
|
+
return read.refresh({ dedupe: 'defer' })
|
|
102
130
|
}
|
|
103
131
|
|
|
132
|
+
/** Shows a write at once, before the read that confirms it. */
|
|
104
133
|
function patch(changes: Partial<MediaAsset>): void {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
134
|
+
const shown = read.data.value
|
|
135
|
+
if (!shown || error.value) return
|
|
136
|
+
const id = shown.details.asset.id
|
|
137
|
+
read.data.value = {
|
|
138
|
+
details: { ...shown.details, asset: { ...shown.details.asset, ...changes } },
|
|
139
|
+
siblings: {
|
|
140
|
+
...shown.siblings,
|
|
141
|
+
assets: shown.siblings.assets.map((entry) => (entry.id === id ? { ...entry, ...changes } : entry)),
|
|
142
|
+
},
|
|
143
|
+
}
|
|
108
144
|
}
|
|
109
145
|
|
|
110
146
|
async function rename(name: string): Promise<boolean> {
|
|
@@ -113,7 +149,7 @@ export function useFileDetails(assetId: Ref<string | undefined>, order: Ref<File
|
|
|
113
149
|
patch({ name })
|
|
114
150
|
try {
|
|
115
151
|
await api.updateAsset(current.id, { name })
|
|
116
|
-
await load(
|
|
152
|
+
await load(true)
|
|
117
153
|
return true
|
|
118
154
|
} catch (cause) {
|
|
119
155
|
patch({ name: current.name })
|
|
@@ -139,7 +175,7 @@ export function useFileDetails(assetId: Ref<string | undefined>, order: Ref<File
|
|
|
139
175
|
try {
|
|
140
176
|
const outcome = await api.setAssetsVisibility([id], visibility)
|
|
141
177
|
if (outcome.refused.length) throw { data: { message: outcome.refused[0]?.message } }
|
|
142
|
-
await load(
|
|
178
|
+
await load()
|
|
143
179
|
return true
|
|
144
180
|
} catch (cause) {
|
|
145
181
|
useApiError(cause, { title: t('dms_media.toasts.visibility_failed') })
|
|
@@ -165,7 +201,7 @@ export function useFileDetails(assetId: Ref<string | undefined>, order: Ref<File
|
|
|
165
201
|
try {
|
|
166
202
|
const outcome = await api.moveAssets([current.id], folderId)
|
|
167
203
|
if (outcome.refused.length) throw { data: { message: outcome.refused[0]?.message } }
|
|
168
|
-
await load(
|
|
204
|
+
await load()
|
|
169
205
|
toast.add({ title: t('dms_media.toasts.moved', { count: 1 }, 1), color: 'success' })
|
|
170
206
|
} catch (cause) {
|
|
171
207
|
useApiError(cause, { title: t('dms_media.toasts.move_failed') })
|
|
@@ -187,17 +223,9 @@ export function useFileDetails(assetId: Ref<string | undefined>, order: Ref<File
|
|
|
187
223
|
}
|
|
188
224
|
|
|
189
225
|
function refresh(): void {
|
|
190
|
-
if (assetId.value) void load(
|
|
226
|
+
if (assetId.value) void load(true)
|
|
191
227
|
}
|
|
192
228
|
|
|
193
|
-
watch(
|
|
194
|
-
assetId,
|
|
195
|
-
(id) => {
|
|
196
|
-
if (id) void load(id)
|
|
197
|
-
},
|
|
198
|
-
{ immediate: true },
|
|
199
|
-
)
|
|
200
|
-
watch(() => JSON.stringify(order.value), refresh)
|
|
201
229
|
onLibraryChange(refresh)
|
|
202
230
|
|
|
203
231
|
return {
|
|
@@ -215,7 +243,6 @@ export function useFileDetails(assetId: Ref<string | undefined>, order: Ref<File
|
|
|
215
243
|
lastFolderId,
|
|
216
244
|
canWrite,
|
|
217
245
|
canChangeVisibility,
|
|
218
|
-
load,
|
|
219
246
|
refresh,
|
|
220
247
|
refreshTree,
|
|
221
248
|
rename,
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AssetDetails,
|
|
3
|
-
AssetPage,
|
|
4
3
|
AssetVisibility,
|
|
5
|
-
BoundFolderAnswer,
|
|
6
4
|
BulkOutcome,
|
|
7
5
|
FolderImpact,
|
|
8
6
|
FolderVisibility,
|
|
9
|
-
ListingParams,
|
|
10
7
|
MediaAsset,
|
|
11
|
-
MediaTree,
|
|
12
|
-
PresetsResponse,
|
|
13
|
-
SearchParams,
|
|
14
8
|
SmartView,
|
|
15
9
|
} from '../types/media'
|
|
16
10
|
|
|
@@ -63,34 +57,35 @@ export interface ReadUrl {
|
|
|
63
57
|
expiresAt: number
|
|
64
58
|
}
|
|
65
59
|
|
|
66
|
-
/**
|
|
60
|
+
/** The URLs of the reads the pages render, which `useApiData` reads and shares by URL. */
|
|
61
|
+
export const MEDIA_READS = {
|
|
62
|
+
tree: `${API}/tree`,
|
|
63
|
+
recent: `${API}/stats/recent`,
|
|
64
|
+
presets: `${API}/presets`,
|
|
65
|
+
boundFolder: (bindingId: string) => `${API}/bindings/${encodeURIComponent(bindingId)}/folder`,
|
|
66
|
+
asset: (assetId: string) => `${API}/assets/${assetId}`,
|
|
67
|
+
details: (assetId: string) => `${API}/assets/${assetId}/details`,
|
|
68
|
+
readUrl: (assetId: string) => `${API}/assets/${assetId}/read-url`,
|
|
69
|
+
folderAssets: (folderId: string) => `${API}/folders/${folderId}/assets`,
|
|
70
|
+
smartView: (view: SmartView) => `${API}/views/${view}`,
|
|
71
|
+
search: `${API}/search`,
|
|
72
|
+
} as const
|
|
73
|
+
|
|
74
|
+
/** Typed calls to the media API, through the authenticated DMS fetch: the writes, and the reads a click or a viewer makes itself. */
|
|
67
75
|
export function useMediaApi() {
|
|
68
76
|
const { $authFetch } = useAuthFetch()
|
|
69
77
|
const post = <T>(path: string, body?: object) =>
|
|
70
78
|
$authFetch<T>(`${API}${path}`, { method: 'POST', body })
|
|
71
79
|
|
|
72
80
|
return {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
boundFolder: (bindingId: string) =>
|
|
76
|
-
$authFetch<BoundFolderAnswer>(`${API}/bindings/${encodeURIComponent(bindingId)}/folder`),
|
|
77
|
-
folderAssets: (folderId: string, query: ListingParams = {}) =>
|
|
78
|
-
$authFetch<AssetPage>(`${API}/folders/${folderId}/assets`, { query }),
|
|
79
|
-
smartView: (view: SmartView, query: ListingParams = {}) =>
|
|
80
|
-
$authFetch<AssetPage>(`${API}/views/${view}`, { query }),
|
|
81
|
-
search: (query: SearchParams) =>
|
|
82
|
-
$authFetch<AssetPage>(`${API}/search`, { query }),
|
|
83
|
-
asset: (assetId: string) =>
|
|
84
|
-
$authFetch<{ asset: MediaAsset }>(`${API}/assets/${assetId}`),
|
|
85
|
-
details: (assetId: string) =>
|
|
86
|
-
$authFetch<AssetDetails>(`${API}/assets/${assetId}/details`),
|
|
81
|
+
asset: (assetId: string) => $authFetch<{ asset: MediaAsset }>(MEDIA_READS.asset(assetId)),
|
|
82
|
+
details: (assetId: string) => $authFetch<AssetDetails>(MEDIA_READS.details(assetId)),
|
|
87
83
|
previews: (ids: string[]) =>
|
|
88
84
|
post<{ previews: Record<string, string> }>('/previews', { ids }),
|
|
89
85
|
readUrl: (assetId: string, preset?: string) =>
|
|
90
|
-
$authFetch<ReadUrl>(
|
|
86
|
+
$authFetch<ReadUrl>(MEDIA_READS.readUrl(assetId), {
|
|
91
87
|
query: preset ? { preset } : {},
|
|
92
88
|
}),
|
|
93
|
-
recent: () => $authFetch<{ assets: MediaAsset[] }>(`${API}/stats/recent`),
|
|
94
89
|
createFolder: (name: string, parentId?: string) =>
|
|
95
90
|
post<{ id: string }>('/folders', { name, parentId }),
|
|
96
91
|
createStarterFolders: (folders: StarterFolder[]) =>
|
|
@@ -132,7 +127,6 @@ export function useMediaApi() {
|
|
|
132
127
|
post<{ asset: MediaAsset }>(`/assets/${assetId}/revert`),
|
|
133
128
|
star: (kind: 'asset' | 'folder', targetId: string, starred: boolean) =>
|
|
134
129
|
post('/favorites', { kind, targetId, starred }),
|
|
135
|
-
presets: () => $authFetch<PresetsResponse>(`${API}/presets`),
|
|
136
130
|
}
|
|
137
131
|
}
|
|
138
132
|
|
|
@@ -1011,6 +1011,7 @@
|
|
|
1011
1011
|
"tab_failed": "Failed today",
|
|
1012
1012
|
"attention": "Needs attention",
|
|
1013
1013
|
"open_folder": "Open the folder",
|
|
1014
|
+
"row_actions": "Actions for the upload to {folder}",
|
|
1014
1015
|
"failed_names": "1 of {total} failed: {names} | {failed} of {total} failed: {names}"
|
|
1015
1016
|
},
|
|
1016
1017
|
"title": "Uploads",
|
|
@@ -1011,6 +1011,7 @@
|
|
|
1011
1011
|
"tab_failed": "En échec aujourd'hui",
|
|
1012
1012
|
"attention": "À traiter",
|
|
1013
1013
|
"open_folder": "Ouvrir le dossier",
|
|
1014
|
+
"row_actions": "Actions pour l'import dans {folder}",
|
|
1014
1015
|
"failed_names": "1 sur {total} en échec : {names} | {failed} sur {total} en échec : {names}"
|
|
1015
1016
|
},
|
|
1016
1017
|
"title": "Imports",
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"main": "./dms.frontend.ts",
|
|
7
7
|
"packageManager": "pnpm@10.6.5",
|
|
8
8
|
"engines": {
|
|
9
|
-
"@antelopejs/dms-frontend": ">=0.
|
|
9
|
+
"@antelopejs/dms-frontend": ">=0.6.0 <0.7.0"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"dev": "pnpm --dir ../playground frontend:dev",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@nuxt/ui": "4.10.0",
|
|
30
30
|
"@typescript-eslint/parser": "^8.0.0",
|
|
31
|
+
"@vitejs/plugin-vue": "^6.0.10",
|
|
31
32
|
"eslint": "^9.0.0",
|
|
32
33
|
"eslint-plugin-vue": "^10.0.0",
|
|
33
34
|
"prettier": "^3.5.3",
|
|
@@ -33,6 +33,9 @@ importers:
|
|
|
33
33
|
'@typescript-eslint/parser':
|
|
34
34
|
specifier: ^8.0.0
|
|
35
35
|
version: 8.65.0(eslint@9.39.5(jiti@2.7.0))(typescript@6.0.3)
|
|
36
|
+
'@vitejs/plugin-vue':
|
|
37
|
+
specifier: ^6.0.10
|
|
38
|
+
version: 6.0.10(vite@7.3.6(jiti@2.7.0)(lightningcss@1.33.0)(terser@5.49.0)(yaml@2.9.0))(vue@3.5.40(typescript@6.0.3))
|
|
36
39
|
eslint:
|
|
37
40
|
specifier: ^9.0.0
|
|
38
41
|
version: 9.39.5(jiti@2.7.0)
|
|
@@ -1383,6 +1386,13 @@ packages:
|
|
|
1383
1386
|
peerDependencies:
|
|
1384
1387
|
vue: '>=3.5.18'
|
|
1385
1388
|
|
|
1389
|
+
'@vitejs/plugin-vue@6.0.10':
|
|
1390
|
+
resolution: {integrity: sha512-b80aUQh3n+qEzzZm5oQp3rT2QImeCx58K6eFl/RkJ3d65KW0kTuv5lNsLRVAjbW9YRUpo/wzmvzMgV34bTAItA==}
|
|
1391
|
+
engines: {node: ^20.19.0 || >=22.12.0}
|
|
1392
|
+
peerDependencies:
|
|
1393
|
+
vite: ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0
|
|
1394
|
+
vue: ^3.2.25 || ^3.6.0-rc.10
|
|
1395
|
+
|
|
1386
1396
|
'@vitest/expect@3.2.7':
|
|
1387
1397
|
resolution: {integrity: sha512-E8eBXaKibuvH2pSZErOjdVb5vF4PbKYcrnluBTYxEk1l/VhhwZg1kZQsdtjq+CsF5CFydf2Rdkz7jDHKSisi3w==}
|
|
1388
1398
|
|
|
@@ -3846,8 +3856,7 @@ snapshots:
|
|
|
3846
3856
|
'@rolldown/binding-win32-x64-msvc@1.2.0':
|
|
3847
3857
|
optional: true
|
|
3848
3858
|
|
|
3849
|
-
'@rolldown/pluginutils@1.0.1':
|
|
3850
|
-
optional: true
|
|
3859
|
+
'@rolldown/pluginutils@1.0.1': {}
|
|
3851
3860
|
|
|
3852
3861
|
'@rollup/rollup-android-arm-eabi@4.62.2':
|
|
3853
3862
|
optional: true
|
|
@@ -4355,6 +4364,12 @@ snapshots:
|
|
|
4355
4364
|
unhead: 2.1.16
|
|
4356
4365
|
vue: 3.5.40(typescript@6.0.3)
|
|
4357
4366
|
|
|
4367
|
+
'@vitejs/plugin-vue@6.0.10(vite@7.3.6(jiti@2.7.0)(lightningcss@1.33.0)(terser@5.49.0)(yaml@2.9.0))(vue@3.5.40(typescript@6.0.3))':
|
|
4368
|
+
dependencies:
|
|
4369
|
+
'@rolldown/pluginutils': 1.0.1
|
|
4370
|
+
vite: 7.3.6(jiti@2.7.0)(lightningcss@1.33.0)(terser@5.49.0)(yaml@2.9.0)
|
|
4371
|
+
vue: 3.5.40(typescript@6.0.3)
|
|
4372
|
+
|
|
4358
4373
|
'@vitest/expect@3.2.7':
|
|
4359
4374
|
dependencies:
|
|
4360
4375
|
'@types/chai': 5.2.3
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
import { describe, expect, it } from 'vitest'
|
|
4
|
+
|
|
5
|
+
type Manifest = { engines?: Record<string, string> }
|
|
6
|
+
|
|
7
|
+
function rendererRange(dir: string): string | undefined {
|
|
8
|
+
const manifest = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) as Manifest
|
|
9
|
+
return manifest.engines?.['@antelopejs/dms-frontend']
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// `ajs dms dev` refuses to start when a frontend module's range excludes the
|
|
13
|
+
// installed renderer, so the playground's own frontend must follow this layer.
|
|
14
|
+
describe('renderer range', () => {
|
|
15
|
+
it('is the same for the playground frontend as for this layer', () => {
|
|
16
|
+
const layer = rendererRange(join(__dirname, '..'))
|
|
17
|
+
expect(layer).toBeDefined()
|
|
18
|
+
expect(rendererRange(join(__dirname, '../../playground/frontend-vue'))).toBe(layer)
|
|
19
|
+
})
|
|
20
|
+
})
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// What the renderer imports of Inertia, which a server render of a component
|
|
2
|
+
// does not reach: the browser's page, links and visits.
|
|
3
|
+
export const Link = {}
|
|
4
|
+
export const router = {
|
|
5
|
+
visit: () => undefined,
|
|
6
|
+
on: () => () => undefined,
|
|
7
|
+
}
|
|
8
|
+
export const usePage = () => ({ url: undefined })
|