create-kide-app 0.0.5 → 0.0.7

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/index.js CHANGED
@@ -118,6 +118,13 @@ async function main() {
118
118
  cpSync(path.join(targetDir, "db.ts"), path.join(projectDir, "src/cms/core/db.ts"));
119
119
  cpSync(path.join(targetDir, "drizzle.config.ts"), path.join(projectDir, "drizzle.config.ts"));
120
120
 
121
+ if (target === "cloudflare") {
122
+ cpSync(path.join(targetDir, "storage.ts"), path.join(projectDir, "src/cms/core/storage.ts"));
123
+ const uploadsRouteDir = path.join(projectDir, "src/pages/uploads");
124
+ mkdirSync(uploadsRouteDir, { recursive: true });
125
+ cpSync(path.join(targetDir, "uploads-route.ts"), path.join(uploadsRouteDir, "[...path].ts"));
126
+ }
127
+
121
128
  const pkgPath = path.join(projectDir, "package.json");
122
129
  const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
123
130
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-kide-app",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "Scaffold a new Kide CMS project",
5
5
  "author": "Matti Hernesniemi",
6
6
  "license": "MIT",
@@ -0,0 +1,25 @@
1
+ import { env } from "cloudflare:workers";
2
+
3
+ function getBucket(): R2Bucket {
4
+ const bucket = (env as any).CMS_ASSETS as R2Bucket | undefined;
5
+ if (!bucket) throw new Error("R2 bucket binding CMS_ASSETS not found. Check wrangler.toml.");
6
+ return bucket;
7
+ }
8
+
9
+ function toKey(storagePath: string): string {
10
+ return storagePath.startsWith("/") ? storagePath.slice(1) : storagePath;
11
+ }
12
+
13
+ export async function putFile(storagePath: string, data: ArrayBuffer | Uint8Array): Promise<void> {
14
+ await getBucket().put(toKey(storagePath), data);
15
+ }
16
+
17
+ export async function getFile(storagePath: string): Promise<ArrayBuffer | null> {
18
+ const obj = await getBucket().get(toKey(storagePath));
19
+ if (!obj) return null;
20
+ return obj.arrayBuffer();
21
+ }
22
+
23
+ export async function deleteFile(storagePath: string): Promise<void> {
24
+ await getBucket().delete(toKey(storagePath));
25
+ }
@@ -0,0 +1,36 @@
1
+ import type { APIRoute } from "astro";
2
+ import { getFile } from "@/cms/core/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 data = await getFile(filePath);
22
+
23
+ if (!data) {
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(data, {
31
+ headers: {
32
+ "Content-Type": contentType,
33
+ "Cache-Control": "public, max-age=31536000, immutable",
34
+ },
35
+ });
36
+ };
@@ -7,6 +7,9 @@ binding = "CMS_DB"
7
7
  database_name = "{{PROJECT_NAME}}-db"
8
8
  database_id = "" # Run: npx wrangler d1 create {{PROJECT_NAME}}-db
9
9
 
10
+ [triggers]
11
+ crons = ["* * * * *"] # scheduled publishing — every minute
12
+
10
13
  [[r2_buckets]]
11
14
  binding = "CMS_ASSETS"
12
15
  bucket_name = "{{PROJECT_NAME}}-assets"