From d5a4846a053ee5516ced6082c4ef941350278fa7 Mon Sep 17 00:00:00 2001 From: seaHi Date: Wed, 29 Jul 2026 10:49:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E7=BB=93=E6=9E=84=E5=B9=B6=E6=B7=BB=E5=8A=A0=20R2=20?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- schema.sql | 51 ++++++++++++++++++++++++++++++++++++--- src/app.d.ts | 1 + worker-configuration.d.ts | 3 ++- wrangler.jsonc | 6 +++++ 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/schema.sql b/schema.sql index e51f933..6e13c23 100644 --- a/schema.sql +++ b/schema.sql @@ -2,7 +2,10 @@ DROP TABLE IF EXISTS post_tags; DROP TABLE IF EXISTS posts; DROP TABLE IF EXISTS tags; DROP TABLE IF EXISTS categories; +DROP TABLE IF EXISTS pages; +DROP TABLE IF EXISTS settings; DROP TABLE IF EXISTS users; +DROP TABLE IF EXISTS attachments; CREATE TABLE users ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -21,7 +24,6 @@ CREATE TABLE posts ( id INTEGER PRIMARY KEY AUTOINCREMENT, slug TEXT NOT NULL UNIQUE, title TEXT NOT NULL, - excerpt TEXT, content TEXT NOT NULL, author_id INTEGER NOT NULL, category_id INTEGER, @@ -31,6 +33,17 @@ CREATE TABLE posts ( FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE SET NULL ); +CREATE TABLE pages ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + slug TEXT NOT NULL UNIQUE, + title TEXT NOT NULL, + content TEXT NOT NULL, + author_id INTEGER NOT NULL, + published_at DATETIME DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (author_id) REFERENCES users(id) +); + CREATE TABLE tags ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL UNIQUE @@ -44,6 +57,22 @@ CREATE TABLE post_tags ( FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE ); +CREATE TABLE settings ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + key TEXT NOT NULL UNIQUE, + value TEXT NOT NULL, + updated_at DATETIME DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE attachments ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + filename TEXT NOT NULL, + key TEXT NOT NULL UNIQUE, + mime_type TEXT, + size INTEGER, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP +); + -- Insert a default user INSERT INTO users (username, password_hash) VALUES ('admin', 'admin'); @@ -51,14 +80,28 @@ INSERT INTO users (username, password_hash) VALUES ('admin', 'admin'); INSERT INTO categories (name, slug) VALUES ('默认分类', 'uncategorized'), ('技术分享', 'tech'), ('生活随笔', 'life'); -- Insert dummy posts -INSERT INTO posts (slug, title, excerpt, content, author_id, category_id) VALUES -('hello-world', 'Hello, BlogFlare!', 'This is my first post on BlogFlare.', 'Welcome to my new blog powered by **SvelteKit** and **Cloudflare D1**. +INSERT INTO posts (slug, title, content, author_id, category_id) VALUES +('hello-world', 'Hello, BlogFlare!', 'This is my first post on BlogFlare. + +Welcome to my new blog powered by **SvelteKit** and **Cloudflare D1**. > [!NOTE] > This is a DoIt style admonition! It is incredibly fast and cheap to host.', 1, 2), -('void-theme', 'The Beauty of VOID', 'Typography is essential.', 'Typecho Theme VOID inspired this design. It uses a very clean layout.', 1, 2); +('void-theme', 'The Beauty of VOID', 'Typography is essential. + +Typecho Theme VOID inspired this design. It uses a very clean layout.', 1, 2); INSERT INTO tags (name) VALUES ('Welcome'), ('Design'); INSERT INTO post_tags (post_id, tag_id) VALUES (1, 1), (2, 2); + +-- Insert default aliases settings +INSERT INTO settings (key, value) VALUES +('alias.post', '文章'), +('alias.category', '分类'), +('alias.tag', '标签'), +('alias.page', '页面'), +('site.title', 'BlogFlare'), +('site.description', 'A high-performance blog powered by Cloudflare D1, R2, and KV.'), +('r2.public_domain', 'https://assets.yourdomain.com'); diff --git a/src/app.d.ts b/src/app.d.ts index 79a056a..faa2a81 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -5,6 +5,7 @@ declare global { interface Platform { env: { DB: D1Database; + R2: R2Bucket; } & Env; context: ExecutionContext; caches: CacheStorage & { default: Cache }; diff --git a/worker-configuration.d.ts b/worker-configuration.d.ts index 91dfd68..0ad3cb2 100644 --- a/worker-configuration.d.ts +++ b/worker-configuration.d.ts @@ -1,7 +1,8 @@ /* eslint-disable */ -// Generated by Wrangler by running `wrangler types` (hash: 8a4682da07c612009fc47d01bb388537) +// Generated by Wrangler by running `wrangler types` (hash: 595eaffe197c5cd34fd594e9940c7cf0) // Runtime types generated with workerd@1.20260708.1 2026-07-12 nodejs_als interface __BaseEnv_Env { + R2: R2Bucket; DB: D1Database; } declare namespace Cloudflare { diff --git a/wrangler.jsonc b/wrangler.jsonc index 43799f7..b4cf849 100644 --- a/wrangler.jsonc +++ b/wrangler.jsonc @@ -12,5 +12,11 @@ "database_name": "blogflare-db", "database_id": "local" } + ], + "r2_buckets": [ + { + "binding": "R2", + "bucket_name": "blogflare-assets" + } ] }