inlaycms 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +462 -2
- package/assets/admin/admin.css +2 -0
- package/assets/admin/admin.js +1 -0
- package/assets/admin/editor.js +125 -0
- package/dist/adapters/admin/activity.d.ts +17 -0
- package/dist/adapters/admin/activity.js +59 -0
- package/dist/adapters/admin/assets.d.ts +14 -0
- package/dist/adapters/admin/assets.js +64 -0
- package/dist/adapters/admin/attention.d.ts +15 -0
- package/dist/adapters/admin/attention.js +34 -0
- package/dist/adapters/admin/context.d.ts +40 -0
- package/dist/adapters/admin/context.js +142 -0
- package/dist/adapters/admin/form/walk.d.ts +61 -0
- package/dist/adapters/admin/form/walk.js +565 -0
- package/dist/adapters/admin/pages.d.ts +38 -0
- package/dist/adapters/admin/pages.js +66 -0
- package/dist/adapters/admin/publish.d.ts +12 -0
- package/dist/adapters/admin/publish.js +195 -0
- package/dist/adapters/admin/routes.d.ts +47 -0
- package/dist/adapters/admin/routes.js +255 -0
- package/dist/adapters/admin/screens/backups.d.ts +11 -0
- package/dist/adapters/admin/screens/backups.js +223 -0
- package/dist/adapters/admin/screens/dashboard.d.ts +4 -0
- package/dist/adapters/admin/screens/dashboard.js +160 -0
- package/dist/adapters/admin/screens/editor.d.ts +67 -0
- package/dist/adapters/admin/screens/editor.js +416 -0
- package/dist/adapters/admin/screens/history.d.ts +4 -0
- package/dist/adapters/admin/screens/history.js +105 -0
- package/dist/adapters/admin/screens/lists.d.ts +4 -0
- package/dist/adapters/admin/screens/lists.js +297 -0
- package/dist/adapters/admin/screens/media.d.ts +20 -0
- package/dist/adapters/admin/screens/media.js +186 -0
- package/dist/adapters/admin/screens/pickers.d.ts +29 -0
- package/dist/adapters/admin/screens/pickers.js +134 -0
- package/dist/adapters/admin/screens/preview-pane.d.ts +10 -0
- package/dist/adapters/admin/screens/preview-pane.js +74 -0
- package/dist/adapters/admin/screens/redirects.d.ts +4 -0
- package/dist/adapters/admin/screens/redirects.js +137 -0
- package/dist/adapters/admin/screens/releases.d.ts +7 -0
- package/dist/adapters/admin/screens/releases.js +287 -0
- package/dist/adapters/admin/screens/search.d.ts +22 -0
- package/dist/adapters/admin/screens/search.js +113 -0
- package/dist/adapters/admin/screens/security.d.ts +4 -0
- package/dist/adapters/admin/screens/security.js +85 -0
- package/dist/adapters/admin/screens/users.d.ts +4 -0
- package/dist/adapters/admin/screens/users.js +330 -0
- package/dist/adapters/admin/theme.d.ts +1 -0
- package/dist/adapters/admin/theme.js +1 -0
- package/dist/adapters/admin/translations.d.ts +16 -0
- package/dist/adapters/admin/translations.js +23 -0
- package/dist/adapters/admin/upload.d.ts +8 -0
- package/dist/adapters/admin/upload.js +116 -0
- package/dist/adapters/admin/views/data-table.d.ts +82 -0
- package/dist/adapters/admin/views/data-table.js +117 -0
- package/dist/adapters/admin/views/icons.d.ts +48 -0
- package/dist/adapters/admin/views/icons.js +47 -0
- package/dist/adapters/admin/views/layout.d.ts +51 -0
- package/dist/adapters/admin/views/layout.js +145 -0
- package/dist/adapters/admin/views/sheet.d.ts +15 -0
- package/dist/adapters/admin/views/sheet.js +6 -0
- package/dist/adapters/admin/views/status.d.ts +32 -0
- package/dist/adapters/admin/views/status.js +74 -0
- package/dist/adapters/auth/handler.d.ts +10 -0
- package/dist/adapters/auth/handler.js +63 -0
- package/dist/adapters/auth/request.d.ts +8 -0
- package/dist/adapters/auth/request.js +14 -0
- package/dist/adapters/cli/bin.d.ts +2 -0
- package/dist/adapters/cli/bin.js +42 -0
- package/dist/adapters/cli/main.d.ts +7 -0
- package/dist/adapters/cli/main.js +982 -0
- package/dist/adapters/cli/remote.d.ts +52 -0
- package/dist/adapters/cli/remote.js +161 -0
- package/dist/adapters/mcp/agent-refs.d.ts +9 -0
- package/dist/adapters/mcp/agent-refs.js +25 -0
- package/dist/adapters/mcp/documents.d.ts +15 -0
- package/dist/adapters/mcp/documents.js +26 -0
- package/dist/adapters/mcp/fetch-url.d.ts +19 -0
- package/dist/adapters/mcp/fetch-url.js +244 -0
- package/dist/adapters/mcp/request-state.d.ts +15 -0
- package/dist/adapters/mcp/request-state.js +38 -0
- package/dist/adapters/mcp/results.d.ts +20 -0
- package/dist/adapters/mcp/results.js +61 -0
- package/dist/adapters/mcp/route.d.ts +34 -0
- package/dist/adapters/mcp/route.js +52 -0
- package/dist/adapters/mcp/server.d.ts +44 -0
- package/dist/adapters/mcp/server.js +49 -0
- package/dist/adapters/mcp/tools/history.d.ts +5 -0
- package/dist/adapters/mcp/tools/history.js +84 -0
- package/dist/adapters/mcp/tools/media.d.ts +5 -0
- package/dist/adapters/mcp/tools/media.js +102 -0
- package/dist/adapters/mcp/tools/publish.d.ts +5 -0
- package/dist/adapters/mcp/tools/publish.js +157 -0
- package/dist/adapters/mcp/tools/read.d.ts +5 -0
- package/dist/adapters/mcp/tools/read.js +279 -0
- package/dist/adapters/mcp/tools/redirects.d.ts +5 -0
- package/dist/adapters/mcp/tools/redirects.js +74 -0
- package/dist/adapters/mcp/tools/write.d.ts +5 -0
- package/dist/adapters/mcp/tools/write.js +304 -0
- package/dist/adapters/site/backup-schedule.d.ts +8 -0
- package/dist/adapters/site/backup-schedule.js +31 -0
- package/dist/adapters/site/cache.d.ts +29 -0
- package/dist/adapters/site/cache.js +63 -0
- package/dist/adapters/site/context.d.ts +29 -0
- package/dist/adapters/site/context.js +278 -0
- package/dist/adapters/site/head.d.ts +23 -0
- package/dist/adapters/site/head.js +44 -0
- package/dist/adapters/site/limiter.d.ts +17 -0
- package/dist/adapters/site/limiter.js +39 -0
- package/dist/adapters/site/lock.d.ts +30 -0
- package/dist/adapters/site/lock.js +143 -0
- package/dist/adapters/site/media-routes.d.ts +4 -0
- package/dist/adapters/site/media-routes.js +55 -0
- package/dist/adapters/site/plugin.d.ts +122 -0
- package/dist/adapters/site/plugin.js +436 -0
- package/dist/adapters/site/preview.d.ts +36 -0
- package/dist/adapters/site/preview.js +82 -0
- package/dist/adapters/site/public.d.ts +6 -0
- package/dist/adapters/site/public.js +87 -0
- package/dist/adapters/site/render.d.ts +45 -0
- package/dist/adapters/site/render.js +191 -0
- package/dist/adapters/site/routes.d.ts +17 -0
- package/dist/adapters/site/routes.js +125 -0
- package/dist/adapters/site/sitemap.d.ts +10 -0
- package/dist/adapters/site/sitemap.js +10 -0
- package/dist/adapters/web.d.ts +22 -0
- package/dist/adapters/web.js +75 -0
- package/dist/config.d.ts +21 -0
- package/dist/config.js +58 -0
- package/dist/core/agent/format.d.ts +62 -0
- package/dist/core/agent/format.js +211 -0
- package/dist/core/agent/schema.d.ts +6 -0
- package/dist/core/agent/schema.js +86 -0
- package/dist/core/archive.d.ts +12 -0
- package/dist/core/archive.js +72 -0
- package/dist/core/auth/auth.d.ts +4911 -0
- package/dist/core/auth/auth.js +61 -0
- package/dist/core/auth/roles.d.ts +10 -0
- package/dist/core/auth/roles.js +38 -0
- package/dist/core/auth/service.d.ts +118 -0
- package/dist/core/auth/service.js +424 -0
- package/dist/core/auth/upload-token.d.ts +8 -0
- package/dist/core/auth/upload-token.js +27 -0
- package/dist/core/backup/backup.d.ts +28 -0
- package/dist/core/backup/backup.js +126 -0
- package/dist/core/backup/restore.d.ts +41 -0
- package/dist/core/backup/restore.js +264 -0
- package/dist/core/backup/schedule.d.ts +12 -0
- package/dist/core/backup/schedule.js +29 -0
- package/dist/core/boot.d.ts +63 -0
- package/dist/core/boot.js +141 -0
- package/dist/core/check.d.ts +32 -0
- package/dist/core/check.js +111 -0
- package/dist/core/content/activity.d.ts +8 -0
- package/dist/core/content/activity.js +101 -0
- package/dist/core/content/delete.d.ts +5 -0
- package/dist/core/content/delete.js +100 -0
- package/dist/core/content/diff.d.ts +6 -0
- package/dist/core/content/diff.js +129 -0
- package/dist/core/content/dry-run.d.ts +24 -0
- package/dist/core/content/dry-run.js +69 -0
- package/dist/core/content/gaps.d.ts +25 -0
- package/dist/core/content/gaps.js +50 -0
- package/dist/core/content/hidden.d.ts +33 -0
- package/dist/core/content/hidden.js +103 -0
- package/dist/core/content/history.d.ts +15 -0
- package/dist/core/content/history.js +62 -0
- package/dist/core/content/patch.d.ts +40 -0
- package/dist/core/content/patch.js +287 -0
- package/dist/core/content/path.d.ts +6 -0
- package/dist/core/content/path.js +38 -0
- package/dist/core/content/publish.d.ts +26 -0
- package/dist/core/content/publish.js +211 -0
- package/dist/core/content/read.d.ts +99 -0
- package/dist/core/content/read.js +141 -0
- package/dist/core/content/reader.d.ts +37 -0
- package/dist/core/content/reader.js +195 -0
- package/dist/core/content/refs.d.ts +44 -0
- package/dist/core/content/refs.js +161 -0
- package/dist/core/content/release-migrations.d.ts +12 -0
- package/dist/core/content/release-migrations.js +154 -0
- package/dist/core/content/save.d.ts +25 -0
- package/dist/core/content/save.js +87 -0
- package/dist/core/content/schema.d.ts +22 -0
- package/dist/core/content/schema.js +127 -0
- package/dist/core/content/search.d.ts +8 -0
- package/dist/core/content/search.js +89 -0
- package/dist/core/content/shipped-input.d.ts +39 -0
- package/dist/core/content/shipped-input.js +221 -0
- package/dist/core/content/shipped.d.ts +112 -0
- package/dist/core/content/shipped.js +437 -0
- package/dist/core/content/slug.d.ts +23 -0
- package/dist/core/content/slug.js +182 -0
- package/dist/core/content/stats.d.ts +11 -0
- package/dist/core/content/stats.js +30 -0
- package/dist/core/content/translate.d.ts +3 -0
- package/dist/core/content/translate.js +68 -0
- package/dist/core/content/usages.d.ts +13 -0
- package/dist/core/content/usages.js +70 -0
- package/dist/core/content/validate.d.ts +21 -0
- package/dist/core/content/validate.js +124 -0
- package/dist/core/content/write.d.ts +10 -0
- package/dist/core/content/write.js +93 -0
- package/dist/core/core.d.ts +227 -0
- package/dist/core/core.js +251 -0
- package/dist/core/db/connection.d.ts +6 -0
- package/dist/core/db/connection.js +12 -0
- package/dist/core/db/migrate.d.ts +9 -0
- package/dist/core/db/migrate.js +42 -0
- package/dist/core/db/migrations/0001_content.d.ts +2 -0
- package/dist/core/db/migrations/0001_content.js +69 -0
- package/dist/core/db/migrations/0002_media.d.ts +2 -0
- package/dist/core/db/migrations/0002_media.js +26 -0
- package/dist/core/db/migrations/0003_redirects.d.ts +2 -0
- package/dist/core/db/migrations/0003_redirects.js +19 -0
- package/dist/core/db/migrations/0004_token_cutoffs.d.ts +3 -0
- package/dist/core/db/migrations/0004_token_cutoffs.js +8 -0
- package/dist/core/db/migrations/0005_site_lock.d.ts +3 -0
- package/dist/core/db/migrations/0005_site_lock.js +10 -0
- package/dist/core/db/migrations/0006_releases.d.ts +3 -0
- package/dist/core/db/migrations/0006_releases.js +34 -0
- package/dist/core/db/schema.d.ts +155 -0
- package/dist/core/db/schema.js +1 -0
- package/dist/core/errors.d.ts +27 -0
- package/dist/core/errors.js +15 -0
- package/dist/core/export/export.d.ts +17 -0
- package/dist/core/export/export.js +185 -0
- package/dist/core/export/format.d.ts +241 -0
- package/dist/core/export/format.js +106 -0
- package/dist/core/export/import.d.ts +54 -0
- package/dist/core/export/import.js +180 -0
- package/dist/core/export/read.d.ts +16 -0
- package/dist/core/export/read.js +234 -0
- package/dist/core/export/replace.d.ts +17 -0
- package/dist/core/export/replace.js +36 -0
- package/dist/core/export/report.d.ts +55 -0
- package/dist/core/export/report.js +50 -0
- package/dist/core/export/schema.d.ts +8 -0
- package/dist/core/export/schema.js +47 -0
- package/dist/core/export/stage.d.ts +25 -0
- package/dist/core/export/stage.js +192 -0
- package/dist/core/fields/builtins.d.ts +70 -0
- package/dist/core/fields/builtins.js +335 -0
- package/dist/core/fields/define.d.ts +86 -0
- package/dist/core/fields/define.js +34 -0
- package/dist/core/fields/walk.d.ts +49 -0
- package/dist/core/fields/walk.js +270 -0
- package/dist/core/fields/widgets.d.ts +27 -0
- package/dist/core/fields/widgets.js +330 -0
- package/dist/core/fields/zod-internals.d.ts +29 -0
- package/dist/core/fields/zod-internals.js +28 -0
- package/dist/core/media/detect.d.ts +5 -0
- package/dist/core/media/detect.js +66 -0
- package/dist/core/media/labels.d.ts +6 -0
- package/dist/core/media/labels.js +17 -0
- package/dist/core/media/library.d.ts +45 -0
- package/dist/core/media/library.js +239 -0
- package/dist/core/media/store.d.ts +11 -0
- package/dist/core/media/store.js +49 -0
- package/dist/core/media/variants.d.ts +10 -0
- package/dist/core/media/variants.js +59 -0
- package/dist/core/messages/en.d.ts +1278 -0
- package/dist/core/messages/en.js +1287 -0
- package/dist/core/messages/index.d.ts +7 -0
- package/dist/core/messages/index.js +14 -0
- package/dist/core/preview.d.ts +16 -0
- package/dist/core/preview.js +42 -0
- package/dist/core/redirects/collapse.d.ts +68 -0
- package/dist/core/redirects/collapse.js +153 -0
- package/dist/core/redirects/csv.d.ts +15 -0
- package/dist/core/redirects/csv.js +68 -0
- package/dist/core/redirects/redirects.d.ts +58 -0
- package/dist/core/redirects/redirects.js +545 -0
- package/dist/core/registry/content.d.ts +26 -0
- package/dist/core/registry/content.js +9 -0
- package/dist/core/registry/define.d.ts +145 -0
- package/dist/core/registry/define.js +41 -0
- package/dist/core/registry/migration.d.ts +44 -0
- package/dist/core/registry/migration.js +4 -0
- package/dist/core/registry/registry.d.ts +18 -0
- package/dist/core/registry/registry.js +255 -0
- package/dist/core/registry/render.d.ts +98 -0
- package/dist/core/registry/render.js +1 -0
- package/dist/core/registry/route.d.ts +42 -0
- package/dist/core/registry/route.js +3 -0
- package/dist/core/release/bundle.d.ts +21 -0
- package/dist/core/release/bundle.js +252 -0
- package/dist/core/release/keys.d.ts +11 -0
- package/dist/core/release/keys.js +60 -0
- package/dist/core/release/manifest.d.ts +103 -0
- package/dist/core/release/manifest.js +138 -0
- package/dist/core/release/pack.d.ts +20 -0
- package/dist/core/release/pack.js +97 -0
- package/dist/core/release/pointer.d.ts +19 -0
- package/dist/core/release/pointer.js +53 -0
- package/dist/core/release/read.d.ts +59 -0
- package/dist/core/release/read.js +256 -0
- package/dist/core/report.d.ts +31 -0
- package/dist/core/report.js +37 -0
- package/dist/core/richtext/html.d.ts +15 -0
- package/dist/core/richtext/html.js +81 -0
- package/dist/core/richtext/markdown.d.ts +19 -0
- package/dist/core/richtext/markdown.js +951 -0
- package/dist/core/richtext/schema.d.ts +98 -0
- package/dist/core/richtext/schema.js +275 -0
- package/dist/core/site/live.d.ts +56 -0
- package/dist/core/site/live.js +145 -0
- package/dist/core/site/paths.d.ts +15 -0
- package/dist/core/site/paths.js +64 -0
- package/dist/core/site/resolve.d.ts +9 -0
- package/dist/core/site/resolve.js +202 -0
- package/dist/core/site/sitemap.d.ts +11 -0
- package/dist/core/site/sitemap.js +24 -0
- package/dist/core/site-lock/site-lock.d.ts +21 -0
- package/dist/core/site-lock/site-lock.js +65 -0
- package/dist/core/site-lock/token.d.ts +7 -0
- package/dist/core/site-lock/token.js +24 -0
- package/dist/core/theme.d.ts +22 -0
- package/dist/core/theme.js +133 -0
- package/dist/core/types.d.ts +253 -0
- package/dist/core/types.js +1 -0
- package/dist/core/version.d.ts +1 -0
- package/dist/core/version.js +5 -0
- package/dist/host/activate.d.ts +53 -0
- package/dist/host/activate.js +162 -0
- package/dist/host/app.d.ts +46 -0
- package/dist/host/app.js +129 -0
- package/dist/host/bin.d.ts +5 -0
- package/dist/host/bin.js +8 -0
- package/dist/host/config.d.ts +36 -0
- package/dist/host/config.js +152 -0
- package/dist/host/dev.d.ts +10 -0
- package/dist/host/dev.js +293 -0
- package/dist/host/diff.d.ts +78 -0
- package/dist/host/diff.js +346 -0
- package/dist/host/hooks.d.ts +41 -0
- package/dist/host/hooks.js +49 -0
- package/dist/host/ipc.d.ts +123 -0
- package/dist/host/ipc.js +61 -0
- package/dist/host/preview-proxy.d.ts +24 -0
- package/dist/host/preview-proxy.js +154 -0
- package/dist/host/preview-worker.d.ts +42 -0
- package/dist/host/preview-worker.js +242 -0
- package/dist/host/primary.d.ts +38 -0
- package/dist/host/primary.js +357 -0
- package/dist/host/push.d.ts +125 -0
- package/dist/host/push.js +420 -0
- package/dist/host/serve.d.ts +16 -0
- package/dist/host/serve.js +150 -0
- package/dist/host/store.d.ts +48 -0
- package/dist/host/store.js +109 -0
- package/dist/host/worker.d.ts +67 -0
- package/dist/host/worker.js +310 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +32 -0
- package/dist/jsx/html.d.ts +16 -0
- package/dist/jsx/html.js +65 -0
- package/dist/jsx/jsx-dev-runtime.d.ts +4 -0
- package/dist/jsx/jsx-dev-runtime.js +5 -0
- package/dist/jsx/jsx-runtime.d.ts +17 -0
- package/dist/jsx/jsx-runtime.js +41 -0
- package/dist/site.d.ts +17 -0
- package/dist/site.js +14 -0
- package/package.json +111 -3
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "inlaycms/jsx-runtime";
|
|
2
|
+
import { isRasterImage, typeLabel } from '../../../core/media/detect.js';
|
|
3
|
+
import { formatSize } from '../../../core/media/labels.js';
|
|
4
|
+
import { t } from '../../../core/messages/index.js';
|
|
5
|
+
import { renderToString } from '../../../jsx/html.js';
|
|
6
|
+
import { adminActor, HTML, notFound } from '../context.js';
|
|
7
|
+
import { Alert } from '../views/layout.js';
|
|
8
|
+
const MEDIA_PAGE = 24;
|
|
9
|
+
const ENTRY_LIMIT = 20;
|
|
10
|
+
const DOCUMENT_LIMIT = 10;
|
|
11
|
+
const textOf = (value) => (typeof value === 'string' ? value : '');
|
|
12
|
+
/** Lower-case text without accents, for matching a search. */
|
|
13
|
+
const fold = (text) => text.normalize('NFKD').replace(/\p{M}/gu, '').toLowerCase();
|
|
14
|
+
const withQuery = (base, params) => {
|
|
15
|
+
const query = new URLSearchParams(Object.entries(params).filter(([, v]) => v !== '')).toString();
|
|
16
|
+
return query === '' ? base : `${base}?${query}`;
|
|
17
|
+
};
|
|
18
|
+
function PickButton({ pick }) {
|
|
19
|
+
return (_jsx("li", { children: _jsxs("button", { type: "button", "data-pick": JSON.stringify(pick), class: "btn btn-ghost h-auto min-h-12 w-full justify-start gap-3 py-2 text-left font-normal", children: [pick.thumb !== undefined && _jsx("img", { src: pick.thumb, alt: "", loading: "lazy", class: "h-12 w-12 shrink-0 rounded object-cover" }), _jsx("span", { class: "break-words", children: pick.label })] }) }));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A web address to link to, for rich text's link picker: `client/admin/picker.ts` turns it into the pick
|
|
23
|
+
* `{ value: 'url:<address>', label: <address> }`. Not a `<form>`, since the picker may sit inside the editor's form.
|
|
24
|
+
*/
|
|
25
|
+
export function WebAddress() {
|
|
26
|
+
return (_jsxs("div", { "data-pick-web": true, class: "flex flex-col gap-2 rounded-box border border-base-300 p-4", children: [_jsx("label", { for: "picker-web", class: "text-sm font-medium", children: t('admin.picker.webAddress') }), _jsx("input", { type: "text", inputmode: "url", id: "picker-web", autocomplete: "off", "aria-describedby": "picker-web-hint", class: "input input-bordered w-full" }), _jsx("p", { id: "picker-web-hint", class: "text-sm text-base-content/70", children: t('admin.picker.webHint') }), _jsx("p", { id: "picker-web-problem", "data-pick-web-problem": true, hidden: true, class: "text-sm text-error", children: t('admin.picker.webInvalid') }), _jsx("div", { children: _jsx("button", { type: "button", "data-pick-web-use": true, class: "btn btn-sm", children: t('admin.picker.webUse') }) })] }));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A picker fragment: an optional part above the search (the upload form), a labeled search box that reloads only
|
|
30
|
+
* the results, the result count (announced politely), the results and paging.
|
|
31
|
+
*/
|
|
32
|
+
function Picker({ url, searchLabel, q, picks, top, nav }) {
|
|
33
|
+
return (_jsxs("div", { class: "flex flex-col gap-4", children: [top, _jsxs("div", { class: "flex flex-col gap-1", children: [_jsx("label", { for: "picker-q", class: "text-sm font-medium", children: searchLabel }), _jsx("input", { type: "search", id: "picker-q", name: "q", value: q, autocomplete: "off", class: "input input-bordered w-full", "hx-get": url, "hx-trigger": "input changed delay:300ms, search", "hx-target": "#picker-results", "hx-select": "#picker-results", "hx-swap": "outerHTML", "hx-select-oob": "#picker-count:innerHTML" })] }), _jsx("p", { id: "picker-count", "aria-live": "polite", class: "text-sm text-base-content/70", children: picks.length === 0 ? t('admin.picker.none') : t('admin.picker.count', { count: picks.length }) }), _jsxs("div", { id: "picker-results", class: "flex flex-col gap-2", children: [_jsx("ul", { class: "flex flex-col gap-1", children: picks.map((pick) => (_jsx(PickButton, { pick: pick }))) }), nav] })] }));
|
|
34
|
+
}
|
|
35
|
+
async function sendFragment(reply, body) {
|
|
36
|
+
return reply.code(200).type(HTML).send(await renderToString(body));
|
|
37
|
+
}
|
|
38
|
+
const mediaPick = (media) => ({
|
|
39
|
+
value: media.id,
|
|
40
|
+
label: media.filename,
|
|
41
|
+
...(isRasterImage(media.mime) && { thumb: `/media/${media.id}/320.webp` }),
|
|
42
|
+
});
|
|
43
|
+
const fits = (kind, media) => kind === 'file' || media.mime.startsWith('image/');
|
|
44
|
+
const kindOf = (raw) => (raw === 'file' ? 'file' : 'image');
|
|
45
|
+
/**
|
|
46
|
+
* The media picker: an upload form, then the library's files (images only for `image`), 24 at a time. After an
|
|
47
|
+
* upload, the new files come first and any problems are shown above.
|
|
48
|
+
*/
|
|
49
|
+
export async function mediaPicker(ctx, opts) {
|
|
50
|
+
const { core, uploads } = ctx;
|
|
51
|
+
const { kind, outcome } = opts;
|
|
52
|
+
const q = (opts.q ?? '').trim();
|
|
53
|
+
const page = opts.page ?? 1;
|
|
54
|
+
const found = await core.listMedia({
|
|
55
|
+
...(kind === 'image' && { kind: 'image' }),
|
|
56
|
+
...(q !== '' && { search: q }),
|
|
57
|
+
limit: MEDIA_PAGE + 1,
|
|
58
|
+
offset: (page - 1) * MEDIA_PAGE,
|
|
59
|
+
});
|
|
60
|
+
const stored = outcome?.stored ?? [];
|
|
61
|
+
const fresh = stored.filter((m) => fits(kind, m));
|
|
62
|
+
const problems = [
|
|
63
|
+
...(outcome?.problems ?? []),
|
|
64
|
+
...stored.filter((m) => !fits(kind, m)).map((m) => t('admin.picker.notImage', { filename: m.filename })),
|
|
65
|
+
];
|
|
66
|
+
const freshIds = new Set(fresh.map((m) => m.id));
|
|
67
|
+
const files = [...fresh, ...found.slice(0, MEDIA_PAGE).filter((m) => !freshIds.has(m.id))].slice(0, MEDIA_PAGE);
|
|
68
|
+
const hasNext = found.length > MEDIA_PAGE;
|
|
69
|
+
const url = withQuery('/admin/pick/media', { kind });
|
|
70
|
+
const pageUrl = (n) => withQuery('/admin/pick/media', { kind, q, page: n > 1 ? String(n) : '' });
|
|
71
|
+
const types = kind === 'image' ? uploads.types.filter((type) => type.startsWith('image/')) : uploads.types;
|
|
72
|
+
const top = (_jsxs(_Fragment, { children: [problems.length > 0 && (_jsx(Alert, { kind: "error", id: "picker-problems", children: _jsx("ul", { class: "list-disc pl-6", children: problems.map((problem) => (_jsx("li", { children: problem }))) }) })), _jsxs("form", { "hx-post": `/admin/media?pick=${kind}`, "hx-encoding": "multipart/form-data", "hx-target": "#inlay-picker-body", "hx-swap": "innerHTML", class: "flex flex-col gap-2 rounded-box border border-base-300 p-4", children: [_jsx("label", { for: "picker-upload", class: "text-sm font-medium", children: t('admin.picker.uploadFile') }), _jsx("input", { id: "picker-upload", name: "file", type: "file", accept: types.join(','), class: "file-input w-full", "aria-describedby": "picker-upload-hint" }), _jsx("p", { id: "picker-upload-hint", class: "text-sm text-base-content/70", children: t('admin.upload.fileHint', { types: types.map(typeLabel).join(', '), max: formatSize(uploads.maxBytes) }) }), _jsx("div", { children: _jsx("button", { type: "submit", class: "btn btn-sm", children: t('admin.picker.upload') }) })] })] }));
|
|
73
|
+
const nav = (page > 1 || hasNext) && (_jsxs("nav", { "aria-label": t('admin.list.page', { page }), class: "flex gap-2", children: [page > 1 && (_jsx("button", { type: "button", class: "btn btn-sm", "hx-get": pageUrl(page - 1), "hx-target": "#inlay-picker-body", "hx-swap": "innerHTML", children: t('admin.list.prev') })), hasNext && (_jsx("button", { type: "button", class: "btn btn-sm", "hx-get": pageUrl(page + 1), "hx-target": "#inlay-picker-body", "hx-swap": "innerHTML", children: t('admin.list.next') }))] }));
|
|
74
|
+
return renderToString(_jsx(Picker, { url: url, searchLabel: t('admin.picker.searchMedia'), q: q, picks: files.map(mediaPick), top: top, nav: nav }));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The fragments the editor's pickers load into the shared dialog: media, entries of a collection, and pages to link
|
|
78
|
+
* to (with `web=1`, which rich text asks for, also a web address).
|
|
79
|
+
*/
|
|
80
|
+
export function registerPickers(scope, ctx) {
|
|
81
|
+
const { core } = ctx;
|
|
82
|
+
const { registry } = core;
|
|
83
|
+
const queryOf = (request) => request.query;
|
|
84
|
+
const localeOf = (raw) => (typeof raw === 'string' && registry.locales.includes(raw) ? raw : registry.defaultLocale);
|
|
85
|
+
scope.get('/admin/pick/media', async (request, reply) => {
|
|
86
|
+
const query = queryOf(request);
|
|
87
|
+
const asked = Number.parseInt(textOf(query.page), 10);
|
|
88
|
+
const page = Number.isSafeInteger(asked) && asked > 0 ? asked : 1;
|
|
89
|
+
const body = await mediaPicker(ctx, { kind: kindOf(query.kind), q: textOf(query.q), page });
|
|
90
|
+
return reply.code(200).type(HTML).send(body);
|
|
91
|
+
});
|
|
92
|
+
scope.get('/admin/pick/entries', async (request, reply) => {
|
|
93
|
+
const query = queryOf(request);
|
|
94
|
+
const collection = registry.site.collections.find((c) => c.name === query.collection);
|
|
95
|
+
if (!collection)
|
|
96
|
+
return notFound(reply, ctx, adminActor(request));
|
|
97
|
+
const locale = localeOf(query.locale);
|
|
98
|
+
const q = textOf(query.q).trim();
|
|
99
|
+
const found = await core.searchEntries(collection.name, q, { locale, limit: ENTRY_LIMIT });
|
|
100
|
+
const picks = found.map((entry) => ({ value: entry.groupId, label: entry.title }));
|
|
101
|
+
const url = withQuery('/admin/pick/entries', { collection: collection.name, locale });
|
|
102
|
+
return sendFragment(reply, _jsx(Picker, { url: url, searchLabel: t('admin.picker.search'), q: q, picks: picks }));
|
|
103
|
+
});
|
|
104
|
+
scope.get('/admin/pick/documents', async (request, reply) => {
|
|
105
|
+
const query = queryOf(request);
|
|
106
|
+
const locale = localeOf(query.locale);
|
|
107
|
+
const q = textOf(query.q).trim();
|
|
108
|
+
const words = fold(q).split(/\s+/).filter((w) => w !== '');
|
|
109
|
+
const singletons = registry.site.singletons.filter((s) => s.path !== null);
|
|
110
|
+
const pages = (await Promise.all(singletons.map(async (def) => {
|
|
111
|
+
const doc = await core.findSingleton(def.name);
|
|
112
|
+
return doc ? [{ def, doc }] : [];
|
|
113
|
+
}))).flat();
|
|
114
|
+
const routed = registry.site.collections.filter((c) => c.route !== null);
|
|
115
|
+
const entries = (await Promise.all(routed.map((c) => core.searchEntries(c.name, q, { locale, limit: DOCUMENT_LIMIT })))).flat();
|
|
116
|
+
const live = await core.liveDocuments([...pages.map((p) => p.doc.groupId), ...entries.map((e) => e.groupId)], locale, { state: 'preview' });
|
|
117
|
+
const pick = (groupId, fallbackTitle) => {
|
|
118
|
+
const doc = live.get(groupId);
|
|
119
|
+
const title = doc?.title ?? fallbackTitle;
|
|
120
|
+
return { value: groupId, label: doc?.path ? t('admin.picker.page', { title, path: doc.path }) : title };
|
|
121
|
+
};
|
|
122
|
+
const pagePicks = pages
|
|
123
|
+
.filter(({ def, doc }) => {
|
|
124
|
+
const found = live.get(doc.groupId);
|
|
125
|
+
const haystack = fold([def.label, found?.title ?? doc.title, found?.path ?? ''].join('\n'));
|
|
126
|
+
return words.every((w) => haystack.includes(w));
|
|
127
|
+
})
|
|
128
|
+
.map(({ doc }) => pick(doc.groupId, doc.title));
|
|
129
|
+
const picks = [...pagePicks, ...entries.map((e) => pick(e.groupId, e.title))];
|
|
130
|
+
const url = withQuery('/admin/pick/documents', { locale });
|
|
131
|
+
const top = query.web === '1' ? _jsx(WebAddress, {}) : undefined;
|
|
132
|
+
return sendFragment(reply, _jsx(Picker, { url: url, searchLabel: t('admin.picker.search'), q: q, picks: picks, top: top }));
|
|
133
|
+
});
|
|
134
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FastifyInstance } from 'fastify';
|
|
2
|
+
import type { DocumentSummary, LiveDocument } from '../../../core/types.js';
|
|
3
|
+
import { type AdminContext } from '../context.js';
|
|
4
|
+
/** The address of a document's live preview pane. */
|
|
5
|
+
export declare const panePath: (id: string) => string;
|
|
6
|
+
/** An empty page with the pane's headers. Each update loads it into the hidden frame before writing the page into it, so the page's scripts start in a fresh window. */
|
|
7
|
+
export declare const blankPath: (id: string) => string;
|
|
8
|
+
/** The document's live (head) version when the editor shows a preview pane for it: its template has `render` and its live path is not null. */
|
|
9
|
+
export declare function paneDocument(ctx: AdminContext, doc: DocumentSummary): Promise<LiveDocument | null>;
|
|
10
|
+
export declare function registerPreviewPane(scope: FastifyInstance, ctx: AdminContext): void;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { documentSchema } from '../../../core/content/schema.js';
|
|
2
|
+
import { t } from '../../../core/messages/index.js';
|
|
3
|
+
import { escapeHtml } from '../../../jsx/html.js';
|
|
4
|
+
import { renderPane } from '../../site/render.js';
|
|
5
|
+
import { adminActor, formValues, HTML, notFound } from '../context.js';
|
|
6
|
+
import { parseDocumentForm } from '../form/walk.js';
|
|
7
|
+
/** The address of a document's live preview pane. */
|
|
8
|
+
export const panePath = (id) => `/admin/documents/${id}/preview`;
|
|
9
|
+
/** An empty page with the pane's headers. Each update loads it into the hidden frame before writing the page into it, so the page's scripts start in a fresh window. */
|
|
10
|
+
export const blankPath = (id) => `/admin/documents/${id}/preview/blank`;
|
|
11
|
+
/** The pane's own policy: it may only be framed by the admin. Set only on pane documents, so the admin's 404 page keeps the admin's. */
|
|
12
|
+
const PANE_CSP = "frame-ancestors 'self'";
|
|
13
|
+
const BLANK = '<!doctype html><html><head><meta charset="utf-8"><title></title></head><body></body></html>';
|
|
14
|
+
/** The document's live (head) version when the editor shows a preview pane for it: its template has `render` and its live path is not null. */
|
|
15
|
+
export async function paneDocument(ctx, doc) {
|
|
16
|
+
const { core } = ctx;
|
|
17
|
+
if (!core.registry.getType(doc.type).template.render)
|
|
18
|
+
return null;
|
|
19
|
+
const live = (await core.liveDocuments([doc.groupId], doc.locale, { state: 'preview' })).get(doc.groupId);
|
|
20
|
+
if (!live || live.documentId !== doc.id || live.path === null)
|
|
21
|
+
return null;
|
|
22
|
+
return live;
|
|
23
|
+
}
|
|
24
|
+
const page = (title, items = []) => `<!doctype html><html><head><meta charset="utf-8"><title>${escapeHtml(title)}</title></head><body><h1>${escapeHtml(title)}</h1>${items.length > 0 ? `<ul>${items.map((i) => `<li>${escapeHtml(i)}</li>`).join('')}</ul>` : ''}</body></html>`;
|
|
25
|
+
export function registerPreviewPane(scope, ctx) {
|
|
26
|
+
const { core } = ctx;
|
|
27
|
+
const { registry } = core;
|
|
28
|
+
async function paneOf(id) {
|
|
29
|
+
const summary = await core.getDocument(id);
|
|
30
|
+
if (!summary || summary.deletedAt !== null)
|
|
31
|
+
return null;
|
|
32
|
+
return paneDocument(ctx, summary);
|
|
33
|
+
}
|
|
34
|
+
async function respond(request, reply, submitted) {
|
|
35
|
+
const actor = adminActor(request);
|
|
36
|
+
const { id } = request.params;
|
|
37
|
+
const live = await paneOf(id);
|
|
38
|
+
if (!live)
|
|
39
|
+
return notFound(reply, ctx, actor);
|
|
40
|
+
reply.header('content-security-policy', PANE_CSP);
|
|
41
|
+
let data = live.data;
|
|
42
|
+
if (submitted) {
|
|
43
|
+
const parsed = parseDocumentForm(registry, live.type, formValues(request));
|
|
44
|
+
const result = documentSchema(registry, live.type, 'draft').safeParse(parsed);
|
|
45
|
+
data = result.success ? result.data : parsed;
|
|
46
|
+
}
|
|
47
|
+
const fail = (status, message, items) => submitted
|
|
48
|
+
? reply.code(status).type('application/json; charset=utf-8').send({ message })
|
|
49
|
+
: reply.code(status === 422 ? 200 : status).type(HTML).send(page(message, items));
|
|
50
|
+
try {
|
|
51
|
+
const result = await renderPane(core, { ...live, data }, { page: 1, baseUrl: ctx.baseUrl });
|
|
52
|
+
if (result.ok)
|
|
53
|
+
return reply.code(200).type(HTML).send(result.html);
|
|
54
|
+
const issues = result.issues;
|
|
55
|
+
const problem = issues[0]?.message ?? '';
|
|
56
|
+
const message = issues.length > 1
|
|
57
|
+
? t('admin.preview.incompleteMore', { problem, n: issues.length - 1 })
|
|
58
|
+
: t('admin.preview.incomplete', { problem });
|
|
59
|
+
return fail(422, submitted ? message : t('admin.preview.notReady'), issues.map((i) => i.message));
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
request.log.error(e);
|
|
63
|
+
return fail(500, t('admin.preview.failed'));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
scope.get('/admin/documents/:id/preview', (request, reply) => respond(request, reply, false));
|
|
67
|
+
scope.post('/admin/documents/:id/preview', (request, reply) => respond(request, reply, true));
|
|
68
|
+
scope.get('/admin/documents/:id/preview/blank', async (request, reply) => {
|
|
69
|
+
const { id } = request.params;
|
|
70
|
+
if (!(await paneOf(id)))
|
|
71
|
+
return notFound(reply, ctx, adminActor(request));
|
|
72
|
+
return reply.code(200).header('content-security-policy', PANE_CSP).type(HTML).send(BLANK);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "inlaycms/jsx-runtime";
|
|
2
|
+
import { InlayError } from '../../../core/errors.js';
|
|
3
|
+
import { t } from '../../../core/messages/index.js';
|
|
4
|
+
import { adminActor, formOf, HTML, noticeOf, notFound } from '../context.js';
|
|
5
|
+
import { DataTable, readTableQuery } from '../views/data-table.js';
|
|
6
|
+
import { Icon } from '../views/icons.js';
|
|
7
|
+
import { Alert, adminPage, Time } from '../views/layout.js';
|
|
8
|
+
import { Sheet } from '../views/sheet.js';
|
|
9
|
+
const sourceName = (s) => t(`admin.redirects.source.${s}`);
|
|
10
|
+
/** The redirects: a searchable table, an add form, and a CSV import. */
|
|
11
|
+
export function registerRedirects(scope, ctx) {
|
|
12
|
+
const { core } = ctx;
|
|
13
|
+
const asCtx = (actor) => ({ actor, source: 'admin' });
|
|
14
|
+
const send = async (reply, status, opts, body) => reply.code(status).type(HTML).send(await adminPage(ctx, { ...opts, status }, body));
|
|
15
|
+
function Target({ redirect, docs }) {
|
|
16
|
+
if ('path' in redirect.to)
|
|
17
|
+
return _jsx("code", { children: redirect.to.path });
|
|
18
|
+
const doc = docs.get(redirect.to.document);
|
|
19
|
+
return doc === undefined ? (_jsx("span", { children: t('admin.redirects.missingPage') })) : (_jsx("a", { href: `/admin/documents/${encodeURIComponent(doc.documentId)}`, class: "link", children: doc.title }));
|
|
20
|
+
}
|
|
21
|
+
async function list(request, reply, status, sheets = {}) {
|
|
22
|
+
const form = sheets.add ?? {};
|
|
23
|
+
const imp = sheets.import ?? { csv: '', problems: [] };
|
|
24
|
+
const sheet = request.query.sheet;
|
|
25
|
+
const addOpen = sheets.add !== undefined || sheet === 'add';
|
|
26
|
+
const importOpen = sheets.import !== undefined || sheet === 'import';
|
|
27
|
+
const actor = adminActor(request);
|
|
28
|
+
const query = request.query;
|
|
29
|
+
const table = readTableQuery(query, { sorts: [], defaultSort: 'from', defaultDir: 'asc' });
|
|
30
|
+
const q = table.q;
|
|
31
|
+
const all = await core.listRedirects();
|
|
32
|
+
const wanted = new Set(all.flatMap((r) => ('document' in r.to ? [r.to.document] : [])));
|
|
33
|
+
if (form.values?.to_document)
|
|
34
|
+
wanted.add(form.values.to_document);
|
|
35
|
+
const docs = wanted.size === 0 ? new Map() : await core.liveDocuments([...wanted], core.registry.defaultLocale, { state: 'preview' });
|
|
36
|
+
const needle = q.toLowerCase();
|
|
37
|
+
const shown = needle === ''
|
|
38
|
+
? all
|
|
39
|
+
: all.filter((r) => {
|
|
40
|
+
const to = 'path' in r.to ? r.to.path : (docs.get(r.to.document)?.title ?? '');
|
|
41
|
+
return [r.from, to, r.note ?? ''].some((s) => s.toLowerCase().includes(needle));
|
|
42
|
+
});
|
|
43
|
+
const values = form.values ?? {};
|
|
44
|
+
const mode = values.to_mode === 'document' ? 'document' : 'path';
|
|
45
|
+
const chosen = values.to_document ? docs.get(values.to_document)?.title : undefined;
|
|
46
|
+
const picker = `/admin/pick/documents?${new URLSearchParams({ locale: core.registry.defaultLocale }).toString()}`;
|
|
47
|
+
const error = form.error;
|
|
48
|
+
const body = (_jsxs("div", { class: "flex flex-col gap-8", children: [_jsx(DataTable, { id: "redirects", caption: t('admin.redirects.table'), base: "/admin/redirects", query: table, rows: shown, rowKey: (r) => String(r.id), rowLabel: (r) => r.from, search: { label: t('admin.redirects.search') }, empty: t('admin.redirects.empty'), columns: [
|
|
49
|
+
{ key: 'from', label: t('admin.redirects.from'), cell: (r) => _jsx("code", { children: r.from }) },
|
|
50
|
+
{ key: 'to', label: t('admin.redirects.to'), cell: (r) => _jsx(Target, { redirect: r, docs: docs }) },
|
|
51
|
+
{ key: 'type', label: t('admin.redirects.type'), cell: (r) => t(r.status === 301 ? 'admin.redirects.permanent' : 'admin.redirects.temporary') },
|
|
52
|
+
{
|
|
53
|
+
key: 'origin',
|
|
54
|
+
label: t('admin.redirects.origin'),
|
|
55
|
+
cell: (r) => (_jsxs(_Fragment, { children: [sourceName(r.source), ", ", r.createdBy, ", ", _jsx(Time, { iso: r.createdAt, relative: true })] })),
|
|
56
|
+
},
|
|
57
|
+
{ key: 'note', label: t('admin.redirects.note'), cell: (r) => r.note ?? '' },
|
|
58
|
+
], rowActions: (r) => [{ label: t('admin.redirects.delete'), icon: 'trash', href: `/admin/redirects/${r.id}/delete`, danger: true, method: 'post' }] }), _jsxs(Sheet, { id: "add-redirect", title: t('admin.redirects.addHeading'), description: t('admin.redirects.addDescription'), open: addOpen, action: "/admin/redirects", submit: t('admin.redirects.add'), children: [error && (_jsx(Alert, { kind: "error", id: "redirect-error", children: _jsxs("div", { children: [_jsx("p", { children: error.message }), (error.details.issues ?? []).length > 0 && (_jsx("ul", { class: "list-disc pl-5", children: (error.details.issues ?? []).map((issue) => (_jsx("li", { children: issue.message }))) }))] }) })), _jsxs("div", { class: "flex flex-col gap-1.5", children: [_jsx("label", { for: "from", class: "text-sm font-medium", children: t('admin.redirects.from') }), _jsx("input", { id: "from", name: "from", type: "text", value: values.from ?? '', class: "input w-full font-mono", placeholder: t('admin.redirects.fromPlaceholder'), "aria-describedby": "from-hint" }), _jsx("p", { id: "from-hint", class: "text-xs text-base-content/70", children: t('admin.redirects.fromHint') })] }), _jsxs("fieldset", { class: "flex flex-col gap-3", children: [_jsx("legend", { class: "mb-1.5 text-sm font-medium", children: t('admin.redirects.toMode') }), _jsxs("div", { class: "join w-full", children: [_jsx("input", { class: "join-item btn btn-sm flex-1", type: "radio", id: "to-mode-path", name: "to_mode", value: "path", "aria-label": t('admin.redirects.toPath'), checked: mode === 'path' }), _jsx("input", { class: "join-item btn btn-sm flex-1", type: "radio", id: "to-mode-document", name: "to_mode", value: "document", "aria-label": t('admin.redirects.toDocument'), checked: mode === 'document' })] }), _jsxs("div", { class: "flex flex-col gap-1.5", "data-shown-when": "to_mode=path", hidden: mode !== 'path', children: [_jsx("label", { for: "to_path", class: "text-sm font-medium", children: t('admin.redirects.toPathLabel') }), _jsx("input", { id: "to_path", name: "to_path", type: "text", value: values.to_path ?? '', class: "input w-full font-mono", placeholder: t('admin.redirects.toPathPlaceholder'), "aria-describedby": "to-path-hint" }), _jsx("p", { id: "to-path-hint", class: "text-xs text-base-content/70", children: t('admin.redirects.toPathHint') })] }), _jsxs("div", { "data-shown-when": "to_mode=document", hidden: mode !== 'document', "data-picker": picker, "data-name": "to_document", class: "flex items-center gap-3 rounded-field border border-base-300 px-3 py-2.5", children: [_jsx("input", { type: "hidden", name: "to_document", value: values.to_document ?? '', "data-picker-value": true }), _jsx("span", { id: "to-document-chosen", "data-picker-label": true, "data-empty": t('admin.form.nothingChosen'), class: "min-w-0 flex-1 truncate text-sm text-base-content/60", children: chosen ?? t('admin.form.nothingChosen') }), _jsx("button", { type: "button", id: "to-document", "data-picker-open": true, class: "btn btn-sm", "aria-describedby": "to-document-chosen", children: t('admin.redirects.choose') }), _jsx("button", { type: "button", "data-picker-clear": true, class: "btn btn-ghost btn-sm", children: t('admin.form.clear') })] })] }), _jsxs("div", { class: "flex flex-col gap-1.5", children: [_jsx("label", { for: "status", class: "text-sm font-medium", children: t('admin.redirects.type') }), _jsxs("select", { id: "status", name: "status", class: "select w-full", children: [_jsx("option", { value: "301", selected: values.status !== '302', children: t('admin.redirects.permanent') }), _jsx("option", { value: "302", selected: values.status === '302', children: t('admin.redirects.temporary') })] })] }), _jsxs("div", { class: "flex flex-col gap-1.5", children: [_jsx("label", { for: "note", class: "text-sm font-medium", children: t('admin.redirects.noteLabel') }), _jsx("input", { id: "note", name: "note", type: "text", value: values.note ?? '', class: "input w-full" })] })] }), _jsxs(Sheet, { id: "import-redirects", size: "lg", title: t('admin.redirects.importTitle'), description: t('admin.redirects.importDescription'), open: importOpen, action: "/admin/redirects/import", enctype: "multipart/form-data", submit: t('admin.redirects.importSubmit'), children: [imp.problems.length > 0 && (_jsx(Alert, { kind: "error", id: "import-problems", children: _jsxs("div", { children: [imp.summary !== undefined && _jsx("p", { class: "font-semibold", children: imp.summary }), _jsx("ul", { class: "list-disc pl-5", children: imp.problems.map((p) => (_jsx("li", { children: p }))) })] }) })), _jsxs("div", { id: "csv-hint", class: "rounded-field bg-base-200 px-4 py-3 text-sm", children: [_jsx("p", { children: t('admin.redirects.importHint') }), _jsx("pre", { class: "mt-2 overflow-x-auto font-mono text-xs text-base-content/80", children: t('admin.redirects.importExample') })] }), _jsxs("div", { class: "flex flex-col gap-1.5", children: [_jsx("label", { for: "file", class: "text-sm font-medium", children: t('admin.redirects.csvFile') }), _jsx("input", { id: "file", name: "file", type: "file", accept: ".csv,text/csv", class: "file-input w-full", "aria-describedby": "csv-hint" })] }), _jsxs("div", { class: "flex flex-col gap-1.5", children: [_jsx("label", { for: "csv", class: "text-sm font-medium", children: t('admin.redirects.csvText') }), _jsx("textarea", { id: "csv", name: "csv", rows: "10", class: "textarea w-full font-mono text-sm", "aria-describedby": "csv-hint", children: imp.csv })] })] })] }));
|
|
59
|
+
const notice = noticeOf(query);
|
|
60
|
+
const actions = (_jsxs(_Fragment, { children: [_jsxs("button", { type: "button", class: "btn btn-sm", "data-sheet-open": "import-redirects", children: [_jsx(Icon, { name: "upload" }), t('admin.redirects.import')] }), _jsxs("button", { type: "button", class: "btn btn-primary btn-sm", "data-sheet-open": "add-redirect", children: [_jsx(Icon, { name: "plus" }), t('admin.redirects.addHeading')] })] }));
|
|
61
|
+
return send(reply, status, { title: t('admin.redirects.title'), description: t('admin.redirects.intro'), actions, actor, section: 'redirects', ...(notice !== undefined && { notice }) }, body);
|
|
62
|
+
}
|
|
63
|
+
scope.get('/admin/redirects', (request, reply) => list(request, reply, 200));
|
|
64
|
+
scope.post('/admin/redirects', async (request, reply) => {
|
|
65
|
+
const actor = adminActor(request);
|
|
66
|
+
const form = formOf(request);
|
|
67
|
+
const to = form.to_mode === 'document' ? { document: (form.to_document ?? '').trim() } : (form.to_path ?? '').trim();
|
|
68
|
+
const input = {
|
|
69
|
+
from: (form.from ?? '').trim(),
|
|
70
|
+
to,
|
|
71
|
+
status: form.status === '302' ? 302 : 301,
|
|
72
|
+
...((form.note ?? '').trim() !== '' && { note: (form.note ?? '').trim() }),
|
|
73
|
+
};
|
|
74
|
+
try {
|
|
75
|
+
await core.createRedirect(input, asCtx(actor));
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
if (!(e instanceof InlayError) || e.code !== 'validation')
|
|
79
|
+
throw e;
|
|
80
|
+
return list(request, reply, 400, { add: { values: form, error: e } });
|
|
81
|
+
}
|
|
82
|
+
return reply.redirect('/admin/redirects?notice=redirectAdded', 303);
|
|
83
|
+
});
|
|
84
|
+
scope.get('/admin/redirects/import', (_request, reply) => reply.redirect('/admin/redirects?sheet=import', 303));
|
|
85
|
+
/** The CSV text of an import: an uploaded file, then the textarea. */
|
|
86
|
+
async function receiveCsv(request) {
|
|
87
|
+
if (!request.isMultipart())
|
|
88
|
+
return formOf(request).csv ?? '';
|
|
89
|
+
let file = '';
|
|
90
|
+
let text = '';
|
|
91
|
+
for await (const part of request.parts()) {
|
|
92
|
+
if (part.type === 'file') {
|
|
93
|
+
const data = await part.toBuffer();
|
|
94
|
+
if (data.length > 0)
|
|
95
|
+
file = data.toString('utf8');
|
|
96
|
+
}
|
|
97
|
+
else if (part.fieldname === 'csv' && typeof part.value === 'string') {
|
|
98
|
+
text = part.value;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return file !== '' ? file : text;
|
|
102
|
+
}
|
|
103
|
+
scope.post('/admin/redirects/import', async (request, reply) => {
|
|
104
|
+
const actor = adminActor(request);
|
|
105
|
+
const csv = await receiveCsv(request);
|
|
106
|
+
if (csv.trim() === '')
|
|
107
|
+
return list(request, reply, 400, { import: { csv: '', problems: [t('admin.redirects.importNothing')] } });
|
|
108
|
+
try {
|
|
109
|
+
const { created, updated } = await core.importRedirects(csv, asCtx(actor));
|
|
110
|
+
return reply.redirect(`/admin/redirects?notice=imported&created=${created}&updated=${updated}`, 303);
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
if (!(e instanceof InlayError) || e.code !== 'validation')
|
|
114
|
+
throw e;
|
|
115
|
+
const lines = e.details.lines ?? [];
|
|
116
|
+
const problems = lines.length > 0 ? lines.map((l) => l.message) : (e.details.issues ?? []).map((i) => i.message);
|
|
117
|
+
return list(request, reply, 400, {
|
|
118
|
+
import: { csv, problems: problems.length > 0 ? problems : [e.message], ...(problems.length > 0 && { summary: e.message }) },
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
scope.post('/admin/redirects/:id/delete', async (request, reply) => {
|
|
123
|
+
const actor = adminActor(request);
|
|
124
|
+
const id = Number(request.params.id);
|
|
125
|
+
if (!Number.isSafeInteger(id))
|
|
126
|
+
return notFound(reply, ctx, actor);
|
|
127
|
+
try {
|
|
128
|
+
await core.deleteRedirect(id, asCtx(actor));
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
if (e instanceof InlayError && e.code === 'not_found')
|
|
132
|
+
return notFound(reply, ctx, actor);
|
|
133
|
+
throw e;
|
|
134
|
+
}
|
|
135
|
+
return reply.redirect('/admin/redirects?notice=redirectRemoved', 303);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FastifyInstance } from 'fastify';
|
|
2
|
+
import { type AdminContext } from '../context.js';
|
|
3
|
+
/**
|
|
4
|
+
* The owner's Releases screen, when the admin has the database and the releases folder: the list with an upload
|
|
5
|
+
* sheet, each release's page (what it changes, preview, activate, delete). Preview and activation need `ctx.host`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function registerReleases(scope: FastifyInstance, ctx: AdminContext): void;
|