From b2fd3e72e6cf841f02c8fcbf13cba4160f94beaa Mon Sep 17 00:00:00 2001 From: anghunk Date: Mon, 9 Feb 2026 13:18:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E6=96=87=E7=AB=A0=E9=93=BE=E6=8E=A5=E5=AD=97=E6=AE=B5=E5=B9=B6?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=87=AA=E5=8A=A8=E8=BF=81=E7=A7=BB=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 Comment 表中添加 post_url 字段,用于存储文章完整 URL - 更新前后端 API 以返回 post_url 字段 - 管理后台评论列表显示文章链接(优先显示 post_url) - 移除前端调试日志并优化自动迁移脚本输出信息 - 通过脚本入口文件统一管理迁移任务 --- cwd-admin/src/views/CommentsView/index.vue | 4 +++- cwd-api/package.json | 2 +- cwd-api/scripts/auto_migrate.js | 14 ++------------ cwd-api/scripts/index.js | 1 + cwd-api/src/api/admin/listComments.ts | 1 + cwd-api/src/api/public/getComments.ts | 4 ++-- docs/widget/src/core/CWDComments.js | 1 - 7 files changed, 10 insertions(+), 17 deletions(-) create mode 100644 cwd-api/scripts/index.js diff --git a/cwd-admin/src/views/CommentsView/index.vue b/cwd-admin/src/views/CommentsView/index.vue index 0a7cef9..8cdb023 100644 --- a/cwd-admin/src/views/CommentsView/index.vue +++ b/cwd-admin/src/views/CommentsView/index.vue @@ -89,7 +89,9 @@ target="_blank" class="cell-path" :title="item.postSlug" - >{{ item.postSlug }} + {{ item.postUrl || item.postSlug }} +
diff --git a/cwd-api/package.json b/cwd-api/package.json index 050a5a4..8174cc5 100644 --- a/cwd-api/package.json +++ b/cwd-api/package.json @@ -2,7 +2,7 @@ "name": "cwd-api", "version": "0.0.18", "scripts": { - "deploy": "node scripts/auto_migrate.js && wrangler deploy", + "deploy": "node scripts/index.js && wrangler deploy", "dev": "wrangler dev", "start": "wrangler dev", "test": "vitest", diff --git a/cwd-api/scripts/auto_migrate.js b/cwd-api/scripts/auto_migrate.js index 3a0f9cc..c98b27d 100644 --- a/cwd-api/scripts/auto_migrate.js +++ b/cwd-api/scripts/auto_migrate.js @@ -39,17 +39,11 @@ function findDatabaseName() { function run() { try { - console.log('🔍 [Auto-Migrate] Detecting D1 database...'); const dbName = findDatabaseName(); if (!dbName) { - console.warn('⚠️ [Auto-Migrate] Could not detect database_name from wrangler config. Skipping.'); return; } - console.log(`✅ [Auto-Migrate] Found database: ${dbName}`); - - console.log('🔍 [Auto-Migrate] Checking schema status...'); try { - // Check if post_url column exists const checkCmd = `npx wrangler d1 execute ${dbName} --command "SELECT count(*) as count FROM pragma_table_info('Comment') WHERE name='post_url'" --remote --json`; const output = execSync(checkCmd, { encoding: 'utf-8', stdio: ['ignore', 'pipe', 'ignore'] }); @@ -57,16 +51,12 @@ function run() { const count = result[0]?.results?.[0]?.count; if (count > 0) { - console.log('✅ [Auto-Migrate] Schema is up to date.'); return; } } catch (e) { - console.warn('⚠️ [Auto-Migrate] Check failed (Database might be new or network error). Skipping migration to be safe.'); - console.warn(e.message); return; } - console.log('🚀 [Auto-Migrate] Applying migration...'); const sql = ` ALTER TABLE Comment ADD COLUMN post_url TEXT; UPDATE Comment SET post_url = post_slug; @@ -82,10 +72,10 @@ function run() { const migrateCmd = `npx wrangler d1 execute ${dbName} --command "${flatSql}" --remote --yes`; execSync(migrateCmd, { stdio: 'inherit' }); - console.log('✅ [Auto-Migrate] Completed successfully.'); + console.log('[Auto-Migrate] Migration applied for Comment.post_url.'); } catch (error) { - console.error('❌ [Auto-Migrate] Failed:', error.message); + console.error('[Auto-Migrate] Failed:', error.message); process.exit(1); } } diff --git a/cwd-api/scripts/index.js b/cwd-api/scripts/index.js new file mode 100644 index 0000000..14eff77 --- /dev/null +++ b/cwd-api/scripts/index.js @@ -0,0 +1 @@ +require('./auto_migrate'); diff --git a/cwd-api/src/api/admin/listComments.ts b/cwd-api/src/api/admin/listComments.ts index cb1aec1..edeebbf 100644 --- a/cwd-api/src/api/admin/listComments.ts +++ b/cwd-api/src/api/admin/listComments.ts @@ -54,6 +54,7 @@ export const listComments = async (c: Context<{ Bindings: Bindings }>) => { name: row.name, email: row.email, postSlug: row.post_slug, + postUrl: row.post_url, url: row.url, ipAddress: row.ip_address, contentText: row.content_text, diff --git a/cwd-api/src/api/public/getComments.ts b/cwd-api/src/api/public/getComments.ts index cc91a4d..c48a2c0 100644 --- a/cwd-api/src/api/public/getComments.ts +++ b/cwd-api/src/api/public/getComments.ts @@ -36,7 +36,7 @@ export const getComments = async (c: Context<{ Bindings: Bindings }>) => { let query = ` SELECT id, name, email, url, content_text as contentText, content_html as contentHtml, created, parent_id as parentId, - post_slug as postSlug, priority, COALESCE(likes, 0) as likes + post_slug as postSlug, post_url as postUrl, priority, COALESCE(likes, 0) as likes FROM Comment WHERE status = "approved" AND post_slug = ? ORDER BY priority DESC, created DESC @@ -46,7 +46,7 @@ export const getComments = async (c: Context<{ Bindings: Bindings }>) => { query = ` SELECT id, name, email, url, content_text as contentText, content_html as contentHtml, created, parent_id as parentId, - post_slug as postSlug, priority, COALESCE(likes, 0) as likes + post_slug as postSlug, post_url as postUrl, priority, COALESCE(likes, 0) as likes FROM Comment WHERE status = "approved" AND post_slug IN (${placeholders}) ORDER BY priority DESC, created DESC diff --git a/docs/widget/src/core/CWDComments.js b/docs/widget/src/core/CWDComments.js index bd6ccae..843b576 100644 --- a/docs/widget/src/core/CWDComments.js +++ b/docs/widget/src/core/CWDComments.js @@ -188,7 +188,6 @@ export class CWDComments { : this.config.commentPlaceholder; const api = createApiClient(this.config); - console.log(this.config) this.api = api; if (this.hostElement && this.mountPoint) { this.store = createCommentStore(