支持在action中配置d1

このコミットが含まれているのは:
mtvpls
2026-01-30 15:46:43 +08:00
コミット 0237b77447
3個のファイルの変更32行の追加22行の削除
+9
ファイルの表示
@@ -67,6 +67,15 @@ jobs:
echo "INIT_CONFIG=${{ secrets.INIT_CONFIG }}" >> $GITHUB_ENV
echo "CONFIG_SUBSCRIPTION_URL=${{ secrets.CONFIG_SUBSCRIPTION_URL }}" >> $GITHUB_ENV
- name: Replace D1 Database ID in wrangler.toml
run: |
if [ -n "${{ secrets.D1_DATABASE_ID }}" ]; then
sed -i 's/REPLACE_WITH_YOUR_D1_DATABASE_ID/${{ secrets.D1_DATABASE_ID }}/g' wrangler.toml
echo "D1 Database ID replaced successfully"
else
echo "D1_DATABASE_ID secret not set, skipping replacement"
fi
- name: Update wrangler.toml with environment variables
run: |
# Function to append variable to wrangler.toml if it has a value
+1 -6
ファイルの表示
@@ -53,13 +53,12 @@ function getD1Adapter(): any {
const isCloudflare = process.env.CF_PAGES === '1' || process.env.BUILD_TARGET === 'cloudflare';
// 生产环境:Cloudflare Workers/Pages
if (isCloudflare && typeof process !== 'undefined' && (process as any).env?.DB) {
if (isCloudflare) {
console.log('Using Cloudflare D1 database');
return new CloudflareD1Adapter((process as any).env.DB);
}
// 开发环境:better-sqlite3
try {
const Database = require('better-sqlite3');
const path = require('path');
const fs = require('fs');
@@ -79,10 +78,6 @@ function getD1Adapter(): any {
console.log('Database location:', dbPath);
return new SQLiteAdapter(db);
} catch (err) {
console.error('Failed to initialize SQLite:', err);
throw err;
}
}
// 单例存储实例
+6
ファイルの表示
@@ -9,6 +9,12 @@ main = ".open-next/worker.js"
directory = ".open-next/assets"
binding = "ASSETS"
# D1 数据库绑定
[[d1_databases]]
binding = "DB"
database_name = "moontvplus"
database_id = "REPLACE_WITH_YOUR_D1_DATABASE_ID"
[vars]
NODE_ENV = "production"
BUILD_TARGET = "cloudflare"