@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.
Files changed (57) 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/pages/uploads.js +2 -1
  6. package/dist/pages/uploads.js.map +1 -1
  7. package/dist/test/antelope.test.js +3 -2
  8. package/dist/test/antelope.test.js.map +1 -1
  9. package/dist/test/helpers/pages.js +3 -2
  10. package/dist/test/helpers/pages.js.map +1 -1
  11. package/dist/test/integration/frontend-module.test.d.ts +1 -0
  12. package/dist/test/integration/frontend-module.test.js +13 -0
  13. package/dist/test/integration/frontend-module.test.js.map +1 -0
  14. package/dist/test/unit/config.test.js +0 -4
  15. package/dist/test/unit/config.test.js.map +1 -1
  16. package/frontend-vue/app/components/FileProperties.vue +9 -3
  17. package/frontend-vue/app/components/FirstRun.vue +1 -1
  18. package/frontend-vue/app/components/ImageEditor.vue +43 -26
  19. package/frontend-vue/app/components/PresetCards.vue +3 -11
  20. package/frontend-vue/app/components/RecentFiles.vue +6 -14
  21. package/frontend-vue/app/components/UploadQueue.vue +1 -1
  22. package/frontend-vue/app/components/UploadStrip.vue +1 -1
  23. package/frontend-vue/app/components/dialogs/DestinationDialog.vue +1 -2
  24. package/frontend-vue/app/components/explorer/ExplorerInspector.vue +17 -16
  25. package/frontend-vue/app/components/explorer/ExplorerShell.vue +11 -3
  26. package/frontend-vue/app/components/explorer/ExplorerToolbar.vue +2 -1
  27. package/frontend-vue/app/components/field/AssetValue.vue +12 -13
  28. package/frontend-vue/app/components/file/FileViewer.vue +1 -14
  29. package/frontend-vue/app/composables/library/useLibraryListing.ts +180 -79
  30. package/frontend-vue/app/composables/library/useLibraryTree.ts +31 -15
  31. package/frontend-vue/app/composables/library/useMediaLibrary.ts +17 -7
  32. package/frontend-vue/app/composables/uploadLimits.ts +25 -0
  33. package/frontend-vue/app/composables/useAssetContent.ts +20 -0
  34. package/frontend-vue/app/composables/useCurrentFile.ts +10 -8
  35. package/frontend-vue/app/composables/useFieldFolders.ts +19 -18
  36. package/frontend-vue/app/composables/useFileDetails.ts +117 -90
  37. package/frontend-vue/app/composables/useMediaApi.ts +18 -24
  38. package/frontend-vue/i18n/locales/media-en-GB.json +1 -0
  39. package/frontend-vue/i18n/locales/media-fr-FR.json +1 -0
  40. package/frontend-vue/package.json +2 -1
  41. package/frontend-vue/pnpm-lock.yaml +17 -2
  42. package/frontend-vue/tests/engines.test.ts +20 -0
  43. package/frontend-vue/tests/fixtures/inertia.ts +8 -0
  44. package/frontend-vue/tests/fixtures/serverRender.ts +200 -0
  45. package/frontend-vue/tests/fixtures/unhead.ts +3 -0
  46. package/frontend-vue/tests/fixtures/vueI18n.ts +4 -0
  47. package/frontend-vue/tests/libraryListing.test.ts +120 -0
  48. package/frontend-vue/tests/serverRender.test.ts +215 -0
  49. package/frontend-vue/vitest.config.ts +21 -0
  50. package/package.json +16 -10
  51. package/src/index.ts +19 -2
  52. package/src/pages/uploads.ts +2 -1
  53. package/src/test/antelope.test.ts +3 -2
  54. package/src/test/helpers/pages.ts +3 -2
  55. package/src/test/integration/frontend-module.test.ts +13 -0
  56. package/src/test/unit/config.test.ts +0 -5
  57. package/frontend-vue/app/composables/useSharedTree.ts +0 -73
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
 
@@ -33,13 +33,14 @@ const history = TableView.fromSource({
33
33
  },
34
34
  ],
35
35
  rowActions: {
36
+ menuLabel: `${TEXTS}.history.row_actions`,
36
37
  custom: [
37
38
  {
38
39
  label: `${TEXTS}.history.open_folder`,
39
40
  icon: "i-ph-folder-open",
40
41
  target: {
41
42
  type: "page",
42
- url: `${MEDIA_ROUTES.files}?folder={folderId}`,
43
+ url: `${MEDIA_ROUTES.files}?folder={{row.folderId}}`,
43
44
  },
44
45
  isDefault: true,
45
46
  },
@@ -6,6 +6,7 @@ import { defineConfig } from "@antelopejs/interface-core/config";
6
6
  import { MongoMemoryReplSet } from "mongodb-memory-server-core";
7
7
 
8
8
  const API_PORT = 5019;
9
+ const LOCAL_BUILD_COMMAND = process.env.DMS_PREBUILT ? [] : ["pnpm build"];
9
10
  const JWT_SECRET = "test-jwt-secret";
10
11
  const MONGO_BINARY_VERSION = "8.0.8";
11
12
  const SMTP_HOST = "127.0.0.1";
@@ -100,7 +101,7 @@ export default defineConfig({
100
101
  source: {
101
102
  type: "local",
102
103
  path: ".",
103
- installCommand: ["pnpm build"],
104
+ installCommand: LOCAL_BUILD_COMMAND,
104
105
  },
105
106
  config: {},
106
107
  },
@@ -108,7 +109,7 @@ export default defineConfig({
108
109
  source: {
109
110
  type: "package",
110
111
  package: "@antelopejs/dms",
111
- version: ">=0.7.18 <0.8.0",
112
+ version: ">=0.9.0 <1.0.0",
112
113
  },
113
114
  config: {
114
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
+ });
@@ -36,9 +36,4 @@ describe("[unit] config — configureMediaModule", () => {
36
36
  expect(presets.get("hero")?.width).to.equal(1200);
37
37
  expect(presets.has("thumb")).to.equal(false);
38
38
  });
39
-
40
- it("keeps the configured storage name", () => {
41
- configureMediaModule({ storage: "r2-main" });
42
- expect(getMediaConfig().storage).to.equal("r2-main");
43
- });
44
39
  });
@@ -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
- }