Add R2 MEDIA binding and setup script
This commit is contained in:
@@ -11,6 +11,7 @@ const ROOT = dirname(SCRIPT_DIR);
|
||||
|
||||
const D1_PLACEHOLDER = "PASTE_D1_DATABASE_ID_HERE";
|
||||
const KV_PLACEHOLDER = "PASTE_KV_NAMESPACE_ID_HERE";
|
||||
const R2_BUCKET = "yingfung-solar-media";
|
||||
const WRANGLER = join(ROOT, "wrangler.jsonc");
|
||||
const SEED_FILE = join(ROOT, "migrations", "seed.sql");
|
||||
const ASTRO_CONFIG = join(ROOT, "astro.config.mjs");
|
||||
@@ -116,6 +117,21 @@ async function main() {
|
||||
console.log("KV id 已設定,略過。");
|
||||
}
|
||||
|
||||
console.log(`檢查 / 建立 R2 bucket「${R2_BUCKET}」…`);
|
||||
const r2List = runSoft("npx wrangler r2 bucket list");
|
||||
const r2Text = `${r2List.out || ""}\n${r2List.err || ""}`;
|
||||
if (new RegExp(`\\b${R2_BUCKET}\\b`).test(r2Text)) {
|
||||
console.log(" R2 bucket 已存在,略過。");
|
||||
} else {
|
||||
const r2 = runSoft(`npx wrangler r2 bucket create ${R2_BUCKET}`);
|
||||
if (r2.ok) {
|
||||
console.log(" R2 bucket 已建立。");
|
||||
} else {
|
||||
console.log(" 建立 R2 bucket 失敗(可能未開通 R2),請稍後手動執行: npm run r2:create");
|
||||
console.log(r2.out || r2.err || "");
|
||||
}
|
||||
}
|
||||
|
||||
const setPassword = await rl.question("而家設定後台密碼 ADMIN_PASSWORD?(y/N):");
|
||||
if (setPassword.trim().toLowerCase() === "y") {
|
||||
execSync("npx wrangler secret put ADMIN_PASSWORD", { stdio: "inherit" });
|
||||
|
||||
Reference in New Issue
Block a user