@kidecms/core 0.1.11 → 0.13.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/admin/components/AssetsGrid.tsx +366 -173
- package/admin/components/BlockEditor.tsx +260 -679
- package/admin/components/CheckboxField.tsx +2 -2
- package/admin/components/CollaborationReviewBar.tsx +384 -0
- package/admin/components/ColorField.tsx +87 -0
- package/admin/components/CommandPalette.tsx +169 -0
- package/admin/components/ContentEditor.tsx +687 -0
- package/admin/components/DocumentActions.tsx +4 -2
- package/admin/components/DocumentsDataTable.tsx +91 -10
- package/admin/components/FieldControl.astro +151 -26
- package/admin/components/FocalPointSelector.tsx +27 -1
- package/admin/components/InternalLinkPicker.tsx +4 -3
- package/admin/components/LinkField.tsx +126 -0
- package/admin/components/RelationField.tsx +105 -26
- package/admin/components/RepeaterInput.tsx +46 -0
- package/admin/components/RichTextEditor.tsx +44 -9
- package/admin/components/SharedSectionBlockField.tsx +93 -0
- package/admin/components/SidebarUserMenu.tsx +1 -1
- package/admin/components/Toast.astro +1 -1
- package/admin/components/TreeItemsEditor.tsx +20 -19
- package/admin/components/TreeSelect.tsx +2 -2
- package/admin/components/YoutubeField.tsx +48 -0
- package/admin/components/block-fields.tsx +777 -0
- package/admin/components/content-block-spec.ts +114 -0
- package/admin/components/slash-command.tsx +242 -0
- package/admin/components/tree-utils.ts +14 -2
- package/admin/components/ui/badge.tsx +2 -3
- package/admin/components/ui/button.tsx +5 -4
- package/admin/components/ui/checkbox.tsx +1 -1
- package/admin/components/ui/input.tsx +1 -1
- package/admin/components/ui/select.tsx +1 -1
- package/admin/components/ui/table.tsx +1 -1
- package/admin/components/ui/textarea.tsx +1 -1
- package/admin/layouts/AdminLayout.astro +323 -123
- package/admin/lib/access.ts +54 -0
- package/admin/lib/collaboration.ts +178 -0
- package/admin/lib/edit-data.ts +448 -0
- package/admin/views/AccessDeniedView.astro +8 -0
- package/admin/views/EditView.astro +706 -0
- package/admin/views/ListView.astro +202 -0
- package/admin/views/RecentView.astro +76 -0
- package/admin/views/SinglesView.astro +65 -0
- package/admin/views/edit/EditScripts.astro +145 -0
- package/admin/views/edit/ReverseReferencesList.astro +68 -0
- package/core/admin.ts +193 -0
- package/core/ai.ts +87 -0
- package/core/api.ts +1392 -0
- package/core/assets.ts +336 -0
- package/core/audit.ts +84 -0
- package/core/auth-config.ts +44 -0
- package/core/auth.ts +303 -0
- package/core/collaboration.ts +276 -0
- package/core/content.ts +27 -0
- package/core/create-admin.ts +28 -0
- package/core/define.ts +625 -0
- package/core/field-model.ts +172 -0
- package/core/generator.ts +519 -0
- package/core/http.ts +42 -0
- package/core/image.ts +219 -0
- package/core/index.ts +211 -0
- package/core/locks.ts +52 -0
- package/core/log.ts +37 -0
- package/core/migrate.ts +278 -0
- package/core/rate-limit.ts +110 -0
- package/core/request-scope.ts +33 -0
- package/core/richtext.ts +1 -0
- package/core/runtime.ts +63 -0
- package/core/schema.ts +32 -0
- package/core/search.ts +489 -0
- package/core/seed.ts +101 -0
- package/core/shared-sections.ts +96 -0
- package/core/tasks.ts +176 -0
- package/core/values.ts +433 -0
- package/core/webhooks.ts +85 -0
- package/core/youtube.ts +39 -0
- package/internals/cli.mjs +34 -0
- package/internals/context.ts +67 -0
- package/internals/create-admin.ts +40 -0
- package/internals/describe.ts +25 -0
- package/internals/eject.ts +144 -0
- package/internals/generator.ts +11 -0
- package/internals/integration.ts +481 -0
- package/internals/mcp.ts +397 -0
- package/internals/project.ts +26 -0
- package/internals/push.ts +160 -0
- package/internals/reindex.ts +11 -0
- package/internals/restore.ts +257 -0
- package/internals/seed.data.ts +7 -0
- package/internals/seed.ts +11 -0
- package/internals/upgrade.ts +776 -0
- package/{virtual.d.ts → internals/virtual.d.ts} +39 -5
- package/middleware/auth.ts +130 -17
- package/middleware/push.ts +121 -0
- package/package.json +55 -67
- package/platform/cloudflare/cf-env.ts +60 -0
- package/platform/cloudflare/database.ts +28 -0
- package/platform/cloudflare/globals.d.ts +5 -0
- package/platform/cloudflare/storage.ts +33 -0
- package/platform/cloudflare/uploads-route.ts +37 -0
- package/platform/node/database.ts +39 -0
- package/platform/node/storage.ts +52 -0
- package/routes/admin/[...path].astro +71 -0
- package/routes/{pages/admin → admin}/assets/[id].astro +25 -19
- package/routes/admin/assets/index.astro +90 -0
- package/routes/{pages/admin/login.astro → admin/forgot-password.astro} +21 -19
- package/routes/{pages/admin → admin}/invite.astro +6 -6
- package/routes/admin/login.astro +103 -0
- package/routes/admin/reset-password.astro +73 -0
- package/routes/{pages/admin → admin}/setup.astro +31 -8
- package/routes/api/{cms/[collection] → [collection]}/[...path].ts +66 -14
- package/routes/api/admin/search.ts +89 -0
- package/routes/api/{cms/assets → assets}/[id].ts +24 -14
- package/routes/api/{cms/assets → assets}/index.ts +4 -2
- package/routes/api/assets/upload.ts +147 -0
- package/routes/api/auth/forgot-password.ts +77 -0
- package/routes/api/{cms/auth → auth}/invite.ts +41 -9
- package/routes/api/auth/login.ts +167 -0
- package/routes/api/{cms/auth → auth}/logout.ts +11 -2
- package/routes/api/auth/reset-password.ts +85 -0
- package/routes/api/auth/setup.ts +110 -0
- package/routes/api/auth/sso/[provider]/start.ts +34 -0
- package/routes/api/collaboration/index.ts +106 -0
- package/routes/api/cron/_authorize.ts +25 -0
- package/routes/api/{cms/cron → cron}/publish.ts +3 -9
- package/routes/api/cron/tasks.ts +33 -0
- package/routes/api/forms/submit/[slug].ts +143 -0
- package/routes/api/img/[...path].ts +65 -0
- package/routes/api/{cms/preview → preview}/render.ts +8 -3
- package/routes/api/{cms/references → references}/[collection]/[id].ts +31 -1
- package/routes/api/webhooks/[provider].ts +54 -0
- package/README.md +0 -28
- package/dist/admin.d.ts +0 -33
- package/dist/admin.js +0 -92
- package/dist/ai.d.ts +0 -15
- package/dist/ai.js +0 -70
- package/dist/api.d.ts +0 -14
- package/dist/api.js +0 -833
- package/dist/assets.d.ts +0 -51
- package/dist/assets.js +0 -163
- package/dist/auth.d.ts +0 -30
- package/dist/auth.js +0 -132
- package/dist/content.d.ts +0 -3
- package/dist/content.js +0 -29
- package/dist/create-admin.d.ts +0 -5
- package/dist/create-admin.js +0 -23
- package/dist/define.d.ts +0 -254
- package/dist/define.js +0 -36
- package/dist/generator.d.ts +0 -9
- package/dist/generator.js +0 -370
- package/dist/image.d.ts +0 -9
- package/dist/image.js +0 -69
- package/dist/index.d.ts +0 -28
- package/dist/index.js +0 -16
- package/dist/integration.d.ts +0 -14
- package/dist/integration.js +0 -327
- package/dist/locks.d.ts +0 -7
- package/dist/locks.js +0 -37
- package/dist/richtext.d.ts +0 -1
- package/dist/richtext.js +0 -1
- package/dist/runtime.d.ts +0 -24
- package/dist/runtime.js +0 -26
- package/dist/schema.d.ts +0 -17
- package/dist/schema.js +0 -13
- package/dist/seed.d.ts +0 -2
- package/dist/seed.js +0 -84
- package/dist/values.d.ts +0 -8
- package/dist/values.js +0 -102
- package/dist/webhooks.d.ts +0 -2
- package/dist/webhooks.js +0 -73
- package/routes/api/cms/assets/upload.ts +0 -112
- package/routes/api/cms/auth/login.ts +0 -124
- package/routes/api/cms/auth/setup.ts +0 -77
- package/routes/api/cms/img/[...path].ts +0 -24
- package/routes/pages/admin/[...path].astro +0 -1107
- package/routes/pages/admin/assets/index.astro +0 -63
- /package/routes/api/{cms/ai → ai}/alt-text.ts +0 -0
- /package/routes/api/{cms/ai → ai}/seo.ts +0 -0
- /package/routes/api/{cms/ai → ai}/translate.ts +0 -0
- /package/routes/api/{cms/assets → assets}/folders.ts +0 -0
- /package/routes/api/{cms/locks → locks}/[...path].ts +0 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getCfEnv } from "./cf-env";
|
|
2
|
+
|
|
3
|
+
async function getBucket(): Promise<R2Bucket> {
|
|
4
|
+
const env = await getCfEnv();
|
|
5
|
+
const bucket = env.CMS_ASSETS;
|
|
6
|
+
if (!bucket) throw new Error("R2 bucket binding CMS_ASSETS not found. Check wrangler.toml.");
|
|
7
|
+
return bucket;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function toKey(storagePath: string): string {
|
|
11
|
+
return storagePath.startsWith("/") ? storagePath.slice(1) : storagePath;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function putFile(storagePath: string, data: ArrayBuffer | Uint8Array): Promise<void> {
|
|
15
|
+
await (await getBucket()).put(toKey(storagePath), data);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function getFile(storagePath: string): Promise<ArrayBuffer | null> {
|
|
19
|
+
const obj = await (await getBucket()).get(toKey(storagePath));
|
|
20
|
+
if (!obj) return null;
|
|
21
|
+
return obj.arrayBuffer();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Streams the R2 object body without buffering it in the Worker — used to serve public assets.
|
|
25
|
+
export async function getFileStream(storagePath: string): Promise<{ body: ReadableStream; size: number } | null> {
|
|
26
|
+
const obj = await (await getBucket()).get(toKey(storagePath));
|
|
27
|
+
if (!obj) return null;
|
|
28
|
+
return { body: obj.body, size: obj.size };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function deleteFile(storagePath: string): Promise<void> {
|
|
32
|
+
await (await getBucket()).delete(toKey(storagePath));
|
|
33
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { APIRoute } from "astro";
|
|
2
|
+
import { getFileStream } from "./storage";
|
|
3
|
+
|
|
4
|
+
export const prerender = false;
|
|
5
|
+
|
|
6
|
+
const MIME_TYPES: Record<string, string> = {
|
|
7
|
+
".jpg": "image/jpeg",
|
|
8
|
+
".jpeg": "image/jpeg",
|
|
9
|
+
".png": "image/png",
|
|
10
|
+
".gif": "image/gif",
|
|
11
|
+
".webp": "image/webp",
|
|
12
|
+
".avif": "image/avif",
|
|
13
|
+
".svg": "image/svg+xml",
|
|
14
|
+
".pdf": "application/pdf",
|
|
15
|
+
".mp4": "video/mp4",
|
|
16
|
+
".webm": "video/webm",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const GET: APIRoute = async ({ params }) => {
|
|
20
|
+
const filePath = `/uploads/${params.path}`;
|
|
21
|
+
const file = await getFileStream(filePath);
|
|
22
|
+
|
|
23
|
+
if (!file) {
|
|
24
|
+
return new Response("Not found", { status: 404 });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const ext = filePath.substring(filePath.lastIndexOf(".")).toLowerCase();
|
|
28
|
+
const contentType = MIME_TYPES[ext] || "application/octet-stream";
|
|
29
|
+
|
|
30
|
+
return new Response(file.body, {
|
|
31
|
+
headers: {
|
|
32
|
+
"Content-Type": contentType,
|
|
33
|
+
"Content-Length": String(file.size),
|
|
34
|
+
"Cache-Control": "public, max-age=31536000, immutable",
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { mkdirSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import Database from "better-sqlite3";
|
|
4
|
+
import { drizzle } from "drizzle-orm/better-sqlite3";
|
|
5
|
+
|
|
6
|
+
let dbInstance: ReturnType<typeof drizzle> | null = null;
|
|
7
|
+
let sqliteInstance: InstanceType<typeof Database> | null = null;
|
|
8
|
+
|
|
9
|
+
const getDbPath = () => {
|
|
10
|
+
const url = process.env.CMS_DATABASE_URL;
|
|
11
|
+
if (url) return url;
|
|
12
|
+
return path.join(process.cwd(), "data", "cms.db");
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// Startup does no schema work. The generated schema (from collections-as-code) is the
|
|
16
|
+
// source of truth, and `pnpm cms:push` is the single sync mechanism on the Node target —
|
|
17
|
+
// run it in dev and as a deploy step before `pnpm start`. (Cloudflare D1 syncs out of
|
|
18
|
+
// band via `wrangler d1 migrations apply`; see platform/cloudflare/database.ts.)
|
|
19
|
+
export const getDb = async () => {
|
|
20
|
+
if (dbInstance) return dbInstance;
|
|
21
|
+
|
|
22
|
+
const dbPath = getDbPath();
|
|
23
|
+
mkdirSync(path.dirname(dbPath), { recursive: true });
|
|
24
|
+
|
|
25
|
+
sqliteInstance = new Database(dbPath);
|
|
26
|
+
sqliteInstance.pragma("journal_mode = WAL");
|
|
27
|
+
sqliteInstance.pragma("foreign_keys = ON");
|
|
28
|
+
|
|
29
|
+
dbInstance = drizzle(sqliteInstance);
|
|
30
|
+
return dbInstance;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const closeDb = () => {
|
|
34
|
+
if (sqliteInstance) {
|
|
35
|
+
sqliteInstance.close();
|
|
36
|
+
sqliteInstance = null;
|
|
37
|
+
dbInstance = null;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createReadStream, existsSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { readFile, stat, unlink, writeFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { Readable } from "node:stream";
|
|
5
|
+
|
|
6
|
+
// Where /uploads/* files live on disk. Defaults to public/uploads for zero-config dev;
|
|
7
|
+
// set CMS_UPLOADS_DIR to a path outside the release tree so uploads survive deploys.
|
|
8
|
+
const uploadsDir = process.env.CMS_UPLOADS_DIR
|
|
9
|
+
? path.resolve(process.env.CMS_UPLOADS_DIR)
|
|
10
|
+
: path.join(process.cwd(), "public", "uploads");
|
|
11
|
+
|
|
12
|
+
// Map a "/uploads/<file>" storagePath onto uploadsDir, rejecting any traversal attempts.
|
|
13
|
+
function safeResolve(storagePath: string): string {
|
|
14
|
+
const rel = storagePath.replace(/^\/+/, "").replace(/^uploads(?:\/|$)/, "");
|
|
15
|
+
const resolved = path.resolve(uploadsDir, rel);
|
|
16
|
+
if (resolved !== uploadsDir && !resolved.startsWith(uploadsDir + path.sep)) {
|
|
17
|
+
throw new Error(`Invalid storage path: ${storagePath}`);
|
|
18
|
+
}
|
|
19
|
+
return resolved;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function putFile(storagePath: string, data: ArrayBuffer | Uint8Array): Promise<void> {
|
|
23
|
+
const filePath = safeResolve(storagePath);
|
|
24
|
+
const dir = path.dirname(filePath);
|
|
25
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
26
|
+
const buffer = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
27
|
+
await writeFile(filePath, buffer);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function getFile(storagePath: string): Promise<ArrayBuffer | null> {
|
|
31
|
+
const filePath = safeResolve(storagePath);
|
|
32
|
+
if (!existsSync(filePath)) return null;
|
|
33
|
+
const buffer = await readFile(filePath);
|
|
34
|
+
return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Stream a file from disk without buffering it — the stream-first read shared with the CF profile.
|
|
38
|
+
export async function getFileStream(storagePath: string): Promise<{ body: ReadableStream; size: number } | null> {
|
|
39
|
+
const filePath = safeResolve(storagePath);
|
|
40
|
+
if (!existsSync(filePath)) return null;
|
|
41
|
+
const { size } = await stat(filePath);
|
|
42
|
+
return { body: Readable.toWeb(createReadStream(filePath)) as ReadableStream, size };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function deleteFile(storagePath: string): Promise<void> {
|
|
46
|
+
const filePath = safeResolve(storagePath);
|
|
47
|
+
try {
|
|
48
|
+
await unlink(filePath);
|
|
49
|
+
} catch {
|
|
50
|
+
// File may already be deleted.
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
---
|
|
2
|
+
import AdminLayout from "../../admin/layouts/AdminLayout.astro";
|
|
3
|
+
import AccessDeniedView from "../../admin/views/AccessDeniedView.astro";
|
|
4
|
+
import EditView from "../../admin/views/EditView.astro";
|
|
5
|
+
import ListView from "../../admin/views/ListView.astro";
|
|
6
|
+
import RecentView from "../../admin/views/RecentView.astro";
|
|
7
|
+
import SinglesView from "../../admin/views/SinglesView.astro";
|
|
8
|
+
import config from "virtual:kide/config";
|
|
9
|
+
import { cms } from "virtual:kide/api";
|
|
10
|
+
import { initDateFormat, resolveAdminRoute } from "../../core";
|
|
11
|
+
import { canRead } from "../../admin/lib/access";
|
|
12
|
+
|
|
13
|
+
export const prerender = false;
|
|
14
|
+
|
|
15
|
+
initDateFormat(config, Astro.cookies.get("tz")?.value);
|
|
16
|
+
|
|
17
|
+
const route = resolveAdminRoute(Astro.params.path);
|
|
18
|
+
const user = Astro.locals.user;
|
|
19
|
+
const runtimeContext = user ? { user: { id: user.id, role: user.role, email: user.email } } : {};
|
|
20
|
+
const isEmbed = Astro.url.searchParams.get("_embed") === "1";
|
|
21
|
+
const accessibleCollections = config.collections.filter((c) => canRead(config, user, c.slug));
|
|
22
|
+
|
|
23
|
+
// /admin → /admin/recent
|
|
24
|
+
if (route.kind === "dashboard") return Astro.redirect("/admin/recent");
|
|
25
|
+
|
|
26
|
+
const collectionSlug = "collectionSlug" in route ? route.collectionSlug : null;
|
|
27
|
+
const collection = collectionSlug ? (cms.meta.getCollection(collectionSlug) as any) : null;
|
|
28
|
+
const canAccessCurrent =
|
|
29
|
+
route.kind === "recent" || route.kind === "singles" || !collectionSlug || canRead(config, user, collectionSlug);
|
|
30
|
+
|
|
31
|
+
// Singletons: redirect list/new to the single document's edit page
|
|
32
|
+
if (collection?.singleton && canAccessCurrent && (route.kind === "list" || route.kind === "new")) {
|
|
33
|
+
const cmsRuntime = cms as Record<string, any>;
|
|
34
|
+
const collectionApi = cmsRuntime[collection.slug];
|
|
35
|
+
const singleDocs = await collectionApi.find({ status: "any", limit: 1 }, runtimeContext);
|
|
36
|
+
const singletonId = (singleDocs[0] ?? (await collectionApi.create({}, runtimeContext)))._id;
|
|
37
|
+
return Astro.redirect(`/admin/${collection.slug}/${singletonId}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const title =
|
|
41
|
+
route.kind === "recent"
|
|
42
|
+
? "Recent | Kide CMS"
|
|
43
|
+
: route.kind === "singles"
|
|
44
|
+
? "Singles | Kide CMS"
|
|
45
|
+
: `${collection?.labels?.plural ?? "Admin"} | Kide CMS`;
|
|
46
|
+
|
|
47
|
+
const activeCollection = route.kind === "recent" ? "recent" : (collectionSlug ?? "singles");
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
<AdminLayout
|
|
51
|
+
title={title}
|
|
52
|
+
collections={accessibleCollections}
|
|
53
|
+
activeCollection={activeCollection}
|
|
54
|
+
embed={isEmbed}
|
|
55
|
+
customNav={config.admin?.nav}
|
|
56
|
+
>
|
|
57
|
+
{route.kind === "recent" && <RecentView />}
|
|
58
|
+
{route.kind === "singles" && <SinglesView />}
|
|
59
|
+
{route.kind !== "recent" && route.kind !== "singles" && !canAccessCurrent && <AccessDeniedView />}
|
|
60
|
+
{route.kind === "list" && canAccessCurrent && collection && <ListView collection={collection} />}
|
|
61
|
+
{
|
|
62
|
+
(route.kind === "new" || route.kind === "edit") && canAccessCurrent && collection && (
|
|
63
|
+
<EditView
|
|
64
|
+
collection={collection}
|
|
65
|
+
mode={route.kind}
|
|
66
|
+
documentId={route.kind === "edit" ? route.documentId : undefined}
|
|
67
|
+
variant={collection.slug === "users" || collection.slug === "form-submissions" ? "record" : "editorial"}
|
|
68
|
+
/>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
</AdminLayout>
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
---
|
|
2
|
-
import { ArrowLeft
|
|
2
|
+
import { ArrowLeft } from "lucide-react";
|
|
3
3
|
|
|
4
|
-
import AdminCard from "
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
4
|
+
import AdminCard from "../../../admin/components/AdminCard.astro";
|
|
5
|
+
import DocumentActions from "../../../admin/components/DocumentActions";
|
|
6
|
+
import AiGenerateButton from "../../../admin/components/AiGenerateButton";
|
|
7
|
+
import FocalPointSelector from "../../../admin/components/FocalPointSelector";
|
|
8
|
+
import UnsavedGuard from "../../../admin/components/UnsavedGuard";
|
|
9
|
+
import TreeSelect, { flattenByParent } from "../../../admin/components/TreeSelect";
|
|
10
|
+
import { buttonVariants } from "../../../admin/components/ui/button";
|
|
11
|
+
import { Label } from "../../../admin/components/ui/label";
|
|
12
|
+
import { Textarea } from "../../../admin/components/ui/textarea";
|
|
12
13
|
import config from "virtual:kide/config";
|
|
13
14
|
import { assets, folders, isAiEnabled } from "virtual:kide/runtime";
|
|
14
|
-
import { formatDate, initDateFormat } from "
|
|
15
|
-
import AdminLayout from "
|
|
15
|
+
import { formatDate, initDateFormat, DEFAULT_PRESETS } from "../../../core";
|
|
16
|
+
import AdminLayout from "../../../admin/layouts/AdminLayout.astro";
|
|
16
17
|
|
|
17
18
|
export const prerender = false;
|
|
18
19
|
|
|
@@ -32,6 +33,16 @@ if (!asset) return Astro.redirect("/admin/assets");
|
|
|
32
33
|
|
|
33
34
|
const aiEnabled = isAiEnabled();
|
|
34
35
|
const isImage = asset.mimeType.startsWith("image/");
|
|
36
|
+
|
|
37
|
+
// Distinct aspect ratios across configured + built-in presets, for the crop preview.
|
|
38
|
+
const mergedPresets = { ...DEFAULT_PRESETS, ...(config.images?.presets ?? {}) };
|
|
39
|
+
const cropPresets: Array<{ name: string; aspect: string }> = [];
|
|
40
|
+
const seenAspects = new Set<string>();
|
|
41
|
+
for (const [name, preset] of Object.entries(mergedPresets)) {
|
|
42
|
+
if (!preset.aspect || seenAspects.has(preset.aspect)) continue;
|
|
43
|
+
seenAspects.add(preset.aspect);
|
|
44
|
+
cropPresets.push({ name, aspect: preset.aspect });
|
|
45
|
+
}
|
|
35
46
|
const currentFolder = asset.folder ? await folders.findById(asset.folder) : null;
|
|
36
47
|
const allFolders = await folders.findAll();
|
|
37
48
|
|
|
@@ -55,7 +66,7 @@ const folderItems = flattenByParent(
|
|
|
55
66
|
activeCollection="assets"
|
|
56
67
|
customNav={config.admin?.nav}
|
|
57
68
|
>
|
|
58
|
-
<section class="space-y-6">
|
|
69
|
+
<section class="space-y-6 px-4 py-6 lg:py-8 lg:pr-8 lg:pl-12">
|
|
59
70
|
<div class="flex items-start justify-between gap-4">
|
|
60
71
|
<div>
|
|
61
72
|
<a
|
|
@@ -73,13 +84,7 @@ const folderItems = flattenByParent(
|
|
|
73
84
|
<button type="submit" form="asset-form" value="save" disabled class={buttonVariants({ variant: "outline" })}>
|
|
74
85
|
Save
|
|
75
86
|
</button>
|
|
76
|
-
<
|
|
77
|
-
<input type="hidden" name="_method" value="DELETE" />
|
|
78
|
-
<button type="submit" class={buttonVariants({ variant: "destructive" })}>
|
|
79
|
-
<Trash2 className="size-3.5" />
|
|
80
|
-
Delete
|
|
81
|
-
</button>
|
|
82
|
-
</form>
|
|
87
|
+
<DocumentActions client:load formId="asset-form" showDelete={true} />
|
|
83
88
|
</div>
|
|
84
89
|
|
|
85
90
|
<UnsavedGuard client:load formId="asset-form" isNew={false} isDraft={false} />
|
|
@@ -96,6 +101,7 @@ const folderItems = flattenByParent(
|
|
|
96
101
|
alt={asset.alt ?? asset.filename}
|
|
97
102
|
focalX={asset.focalX}
|
|
98
103
|
focalY={asset.focalY}
|
|
104
|
+
presets={cropPresets}
|
|
99
105
|
/>
|
|
100
106
|
</AdminCard>
|
|
101
107
|
)
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
---
|
|
2
|
+
import AssetsGrid from "../../../admin/components/AssetsGrid";
|
|
3
|
+
import config from "virtual:kide/config";
|
|
4
|
+
import { assets, folders } from "virtual:kide/runtime";
|
|
5
|
+
import AdminLayout from "../../../admin/layouts/AdminLayout.astro";
|
|
6
|
+
|
|
7
|
+
export const prerender = false;
|
|
8
|
+
|
|
9
|
+
const ASSET_PAGE_SIZE = 24;
|
|
10
|
+
|
|
11
|
+
const user = Astro.locals.user;
|
|
12
|
+
const accessibleCollections = config.collections.filter((c) => {
|
|
13
|
+
const rule = c.access?.read;
|
|
14
|
+
if (!rule) return true;
|
|
15
|
+
return rule({ user: user ?? null, doc: null, operation: "read", collection: c.slug });
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const folderParam = Astro.url.searchParams.get("folder");
|
|
19
|
+
// Three sidebar scopes:
|
|
20
|
+
// absent → "all" → every asset across all folders (unscoped)
|
|
21
|
+
// "unfiled" → "unfiled" → assets not in any folder (folder IS NULL)
|
|
22
|
+
// "<id>" → that folder
|
|
23
|
+
const scope = !folderParam ? "all" : folderParam === "unfiled" ? "unfiled" : folderParam;
|
|
24
|
+
// Map the scope to the core `folder` filter: undefined = unscoped, null = IS NULL, id = that folder.
|
|
25
|
+
const folderScope = scope === "all" ? undefined : scope === "unfiled" ? null : scope;
|
|
26
|
+
|
|
27
|
+
const search = (Astro.url.searchParams.get("q") ?? "").trim();
|
|
28
|
+
const requestedPage = Math.max(1, Number(Astro.url.searchParams.get("page") ?? "1"));
|
|
29
|
+
|
|
30
|
+
// Current folder (for the heading / breadcrumb trail) — only for a real folder scope.
|
|
31
|
+
const currentFolder = typeof folderScope === "string" ? await folders.findById(folderScope) : null;
|
|
32
|
+
if (typeof folderScope === "string" && !currentFolder) return Astro.redirect("/admin/assets");
|
|
33
|
+
|
|
34
|
+
// Every folder — the sticky sidebar renders the whole tree as drop targets.
|
|
35
|
+
const allFolders = await folders.findAll();
|
|
36
|
+
|
|
37
|
+
// Assets in the current scope, filtered by name and paginated.
|
|
38
|
+
const total = await assets.count({ folder: folderScope, search });
|
|
39
|
+
const totalPages = Math.max(1, Math.ceil(total / ASSET_PAGE_SIZE));
|
|
40
|
+
const page = Math.min(requestedPage, totalPages);
|
|
41
|
+
const folderAssets = await assets.find({
|
|
42
|
+
folder: folderScope,
|
|
43
|
+
search,
|
|
44
|
+
limit: ASSET_PAGE_SIZE,
|
|
45
|
+
offset: (page - 1) * ASSET_PAGE_SIZE,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Breadcrumb trail up to the current folder.
|
|
49
|
+
const breadcrumbs: Array<{ label: string; href: string; id: string }> = [];
|
|
50
|
+
if (currentFolder) {
|
|
51
|
+
let folder: typeof currentFolder | null = currentFolder;
|
|
52
|
+
const chain: typeof breadcrumbs = [];
|
|
53
|
+
while (folder) {
|
|
54
|
+
chain.unshift({ label: folder.name, href: `/admin/assets?folder=${folder._id}`, id: folder._id });
|
|
55
|
+
folder = folder.parent ? await folders.findById(folder.parent) : null;
|
|
56
|
+
}
|
|
57
|
+
breadcrumbs.push(...chain);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Serialize for the React island.
|
|
61
|
+
const folderData = allFolders.map((f) => ({ _id: f._id, name: f.name, parent: f.parent ?? null }));
|
|
62
|
+
const assetData = folderAssets.map((a) => ({
|
|
63
|
+
_id: a._id,
|
|
64
|
+
filename: a.filename,
|
|
65
|
+
mimeType: a.mimeType,
|
|
66
|
+
url: a.url,
|
|
67
|
+
alt: a.alt,
|
|
68
|
+
_createdAt: a._createdAt,
|
|
69
|
+
}));
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
<AdminLayout
|
|
73
|
+
title="Assets | Kide CMS"
|
|
74
|
+
collections={accessibleCollections}
|
|
75
|
+
activeCollection="assets"
|
|
76
|
+
customNav={config.admin?.nav}
|
|
77
|
+
>
|
|
78
|
+
<AssetsGrid
|
|
79
|
+
client:load
|
|
80
|
+
folders={folderData}
|
|
81
|
+
assets={assetData}
|
|
82
|
+
breadcrumbs={breadcrumbs}
|
|
83
|
+
scope={scope}
|
|
84
|
+
search={search}
|
|
85
|
+
page={page}
|
|
86
|
+
totalPages={totalPages}
|
|
87
|
+
total={total}
|
|
88
|
+
pageSize={ASSET_PAGE_SIZE}
|
|
89
|
+
/>
|
|
90
|
+
</AdminLayout>
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
---
|
|
2
2
|
import "virtual:kide/admin-css";
|
|
3
3
|
|
|
4
|
-
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "
|
|
5
|
-
import { Input } from "
|
|
6
|
-
import { Label } from "
|
|
7
|
-
import { buttonVariants } from "
|
|
4
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../../admin/components/ui/card";
|
|
5
|
+
import { Input } from "../../admin/components/ui/input";
|
|
6
|
+
import { Label } from "../../admin/components/ui/label";
|
|
7
|
+
import { buttonVariants } from "../../admin/components/ui/button";
|
|
8
|
+
import { resolveAdminAuth } from "../../core";
|
|
9
|
+
import config from "virtual:kide/config";
|
|
8
10
|
|
|
9
11
|
export const prerender = false;
|
|
10
12
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
const auth = resolveAdminAuth(config);
|
|
14
|
+
if (!auth.password.forgotPassword) return Astro.redirect("/admin/login");
|
|
15
|
+
|
|
16
|
+
const status = Astro.url.searchParams.get("status");
|
|
14
17
|
---
|
|
15
18
|
|
|
16
19
|
<!doctype html>
|
|
@@ -20,7 +23,7 @@ const errorMessage =
|
|
|
20
23
|
<meta name="viewport" content="width=device-width" />
|
|
21
24
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
|
22
25
|
<link rel="icon" href="/favicon.ico" />
|
|
23
|
-
<title>
|
|
26
|
+
<title>Reset password | Kide CMS</title>
|
|
24
27
|
</head>
|
|
25
28
|
<body class="bg-background text-foreground min-h-screen antialiased">
|
|
26
29
|
<div class="flex min-h-screen items-center justify-center px-4">
|
|
@@ -28,27 +31,26 @@ const errorMessage =
|
|
|
28
31
|
<h1 class="text-center text-xl font-semibold tracking-tight">Kide CMS</h1>
|
|
29
32
|
<Card>
|
|
30
33
|
<CardHeader>
|
|
31
|
-
<CardTitle>
|
|
32
|
-
<CardDescription>Enter your
|
|
34
|
+
<CardTitle>Reset password</CardTitle>
|
|
35
|
+
<CardDescription>Enter your email and we'll send a reset link</CardDescription>
|
|
33
36
|
</CardHeader>
|
|
34
37
|
<CardContent>
|
|
35
38
|
{
|
|
36
|
-
|
|
37
|
-
<div class="border-
|
|
38
|
-
|
|
39
|
+
status === "sent" && (
|
|
40
|
+
<div class="border-border bg-muted mb-4 rounded-lg border px-3 py-2 text-sm">
|
|
41
|
+
If that account exists, a reset link has been sent.
|
|
39
42
|
</div>
|
|
40
43
|
)
|
|
41
44
|
}
|
|
42
|
-
<form method="post" action="/api/cms/auth/
|
|
45
|
+
<form method="post" action="/api/cms/auth/forgot-password" class="grid gap-4">
|
|
43
46
|
<div class="grid gap-2">
|
|
44
47
|
<Label htmlFor="email">Email</Label>
|
|
45
48
|
<Input id="email" name="email" type="email" placeholder="admin@example.com" required autoFocus />
|
|
46
49
|
</div>
|
|
47
|
-
<
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
</
|
|
51
|
-
<button class={buttonVariants({ size: "lg", className: "w-full" })} type="submit"> Sign in </button>
|
|
50
|
+
<button class={buttonVariants({ size: "lg", className: "w-full" })} type="submit">Send reset link</button>
|
|
51
|
+
<a class="text-muted-foreground hover:text-foreground text-center text-sm" href="/admin/login">
|
|
52
|
+
Back to sign in
|
|
53
|
+
</a>
|
|
52
54
|
</form>
|
|
53
55
|
</CardContent>
|
|
54
56
|
</Card>
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
---
|
|
2
2
|
import "virtual:kide/admin-css";
|
|
3
3
|
|
|
4
|
-
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "
|
|
5
|
-
import { Input } from "
|
|
6
|
-
import { Label } from "
|
|
7
|
-
import { buttonVariants } from "
|
|
4
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../../admin/components/ui/card";
|
|
5
|
+
import { Input } from "../../admin/components/ui/input";
|
|
6
|
+
import { Label } from "../../admin/components/ui/label";
|
|
7
|
+
import { buttonVariants } from "../../admin/components/ui/button";
|
|
8
8
|
import { validateInvite } from "virtual:kide/runtime";
|
|
9
9
|
import { getDb } from "virtual:kide/db";
|
|
10
10
|
import { eq } from "drizzle-orm";
|
|
@@ -37,7 +37,7 @@ const errorMessage =
|
|
|
37
37
|
: error === "password"
|
|
38
38
|
? "Passwords do not match."
|
|
39
39
|
: error === "short"
|
|
40
|
-
? "Password must be at least
|
|
40
|
+
? "Password must be at least 12 characters."
|
|
41
41
|
: error === "expired" || error === "invalid"
|
|
42
42
|
? "This invite link has expired or already been used."
|
|
43
43
|
: null;
|
|
@@ -89,7 +89,7 @@ const errorMessage =
|
|
|
89
89
|
</div>
|
|
90
90
|
<div class="grid gap-2">
|
|
91
91
|
<Label htmlFor="password">Password</Label>
|
|
92
|
-
<Input id="password" name="password" type="password" placeholder="Min
|
|
92
|
+
<Input id="password" name="password" type="password" placeholder="Min 12 characters" required />
|
|
93
93
|
</div>
|
|
94
94
|
<div class="grid gap-2">
|
|
95
95
|
<Label htmlFor="confirmPassword">Confirm password</Label>
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
---
|
|
2
|
+
import "virtual:kide/admin-css";
|
|
3
|
+
|
|
4
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../../admin/components/ui/card";
|
|
5
|
+
import { Input } from "../../admin/components/ui/input";
|
|
6
|
+
import { Label } from "../../admin/components/ui/label";
|
|
7
|
+
import { buttonVariants } from "../../admin/components/ui/button";
|
|
8
|
+
import { resolveAdminAuth } from "../../core";
|
|
9
|
+
import config from "virtual:kide/config";
|
|
10
|
+
|
|
11
|
+
export const prerender = false;
|
|
12
|
+
|
|
13
|
+
const error = Astro.url.searchParams.get("error");
|
|
14
|
+
const errorMessage =
|
|
15
|
+
error === "invalid"
|
|
16
|
+
? "Invalid email or password."
|
|
17
|
+
: error === "missing"
|
|
18
|
+
? "Email and password are required."
|
|
19
|
+
: error === "disabled"
|
|
20
|
+
? "Password login is disabled."
|
|
21
|
+
: null;
|
|
22
|
+
const auth = resolveAdminAuth(config);
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
<!doctype html>
|
|
26
|
+
<html lang="en">
|
|
27
|
+
<head>
|
|
28
|
+
<meta charset="utf-8" />
|
|
29
|
+
<meta name="viewport" content="width=device-width" />
|
|
30
|
+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
|
31
|
+
<link rel="icon" href="/favicon.ico" />
|
|
32
|
+
<title>Sign in | Kide CMS</title>
|
|
33
|
+
</head>
|
|
34
|
+
<body class="bg-background text-foreground min-h-screen antialiased">
|
|
35
|
+
<div class="flex min-h-screen items-center justify-center px-4">
|
|
36
|
+
<div class="w-full max-w-sm space-y-6">
|
|
37
|
+
<h1 class="text-center text-xl font-semibold tracking-tight">Kide CMS</h1>
|
|
38
|
+
<Card>
|
|
39
|
+
<CardHeader>
|
|
40
|
+
<CardTitle>Sign in</CardTitle>
|
|
41
|
+
<CardDescription>Enter your credentials to continue</CardDescription>
|
|
42
|
+
</CardHeader>
|
|
43
|
+
<CardContent>
|
|
44
|
+
{
|
|
45
|
+
errorMessage && (
|
|
46
|
+
<div class="border-destructive/50 bg-destructive/10 text-destructive mb-4 rounded-lg border px-3 py-2 text-sm">
|
|
47
|
+
{errorMessage}
|
|
48
|
+
</div>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
<form method="post" action="/api/cms/auth/login" class="grid gap-4">
|
|
52
|
+
{
|
|
53
|
+
auth.password.enabled && (
|
|
54
|
+
<>
|
|
55
|
+
<div class="grid gap-2">
|
|
56
|
+
<Label htmlFor="email">Email</Label>
|
|
57
|
+
<Input id="email" name="email" type="email" placeholder="admin@example.com" required autoFocus />
|
|
58
|
+
</div>
|
|
59
|
+
<div class="grid gap-2">
|
|
60
|
+
<div class="flex items-center justify-between gap-3">
|
|
61
|
+
<Label htmlFor="password">Password</Label>
|
|
62
|
+
{auth.password.forgotPassword && (
|
|
63
|
+
<a class="text-muted-foreground hover:text-foreground text-xs" href="/admin/forgot-password">
|
|
64
|
+
Forgot password?
|
|
65
|
+
</a>
|
|
66
|
+
)}
|
|
67
|
+
</div>
|
|
68
|
+
<Input id="password" name="password" type="password" placeholder="Enter password" required />
|
|
69
|
+
</div>
|
|
70
|
+
<button class={buttonVariants({ size: "lg", className: "w-full" })} type="submit">
|
|
71
|
+
Sign in
|
|
72
|
+
</button>
|
|
73
|
+
</>
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
</form>
|
|
77
|
+
{
|
|
78
|
+
auth.ssoProviders.length > 0 && (
|
|
79
|
+
<div class="mt-4 grid gap-3">
|
|
80
|
+
{auth.password.enabled && (
|
|
81
|
+
<div class="text-muted-foreground flex items-center gap-3 text-xs">
|
|
82
|
+
<div class="bg-border h-px flex-1" />
|
|
83
|
+
<span>or</span>
|
|
84
|
+
<div class="bg-border h-px flex-1" />
|
|
85
|
+
</div>
|
|
86
|
+
)}
|
|
87
|
+
{auth.ssoProviders.map((provider) => (
|
|
88
|
+
<a
|
|
89
|
+
class={buttonVariants({ variant: "outline", size: "lg", className: "w-full" })}
|
|
90
|
+
href={`/api/cms/auth/sso/${provider.id}/start`}
|
|
91
|
+
>
|
|
92
|
+
Continue with {provider.label}
|
|
93
|
+
</a>
|
|
94
|
+
))}
|
|
95
|
+
</div>
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
</CardContent>
|
|
99
|
+
</Card>
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
</body>
|
|
103
|
+
</html>
|