Skip to content

Commit 39eb84e

Browse files
author
zhoumian
committed
fix: 移除明文 tmdb_config.json,改用 Vite 构建时注入 VITE_TMDB_API_KEY
1 parent 4b34644 commit 39eb84e

4 files changed

Lines changed: 6 additions & 23 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ jobs:
7070
npm install
7171
npm run build
7272
working-directory: web/
73+
env:
74+
VITE_TMDB_API_KEY: ${{ secrets.TMDB_API_KEY }}
7375

7476
# ⑤ 上传 Pages 产物
7577
- name: 上传 Pages 产物

.github/workflows/fetch.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ jobs:
9797
- name: 生成前端数据
9898
run: python -m scripts.render
9999
env:
100-
TMDB_API_KEY: ${{ secrets.TMDB_API_KEY }}
101100
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
102101
LLM_API_BASE: ${{ secrets.LLM_API_BASE }}
103102
LLM_MODEL: ${{ secrets.LLM_MODEL }}

scripts/render.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,6 @@ def run():
154154
_write_json("monthly_posters.json", monthly_posters)
155155
print(f"[Render] 已生成 monthly_posters.json({len(monthly_posters)} 个月)")
156156

157-
# ── TMDB API 配置(前端搜索打分用) ──
158-
tmdb_key = os.environ.get('TMDB_API_KEY', '')
159-
if tmdb_key:
160-
_write_json("tmdb_config.json", {"api_key": tmdb_key})
161-
print("[Render] 已生成 tmdb_config.json")
162-
163157
# ── 画像 & 推荐数据 ──
164158
try:
165159
from scripts.render_profile import run as render_profile_run

web/src/config.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,11 @@
22
// 前端配置 — 按需修改
33
// ============================================
44

5-
// TMDB API Key(运行时从 data/tmdb_config.json 加载,无需硬编码
6-
let tmdbApiKey = ''
5+
// TMDB API Key(Vite 构建时通过 VITE_TMDB_API_KEY 注入
6+
const tmdbApiKey = import.meta.env?.VITE_TMDB_API_KEY || ''
77

8-
/** 从 tmdb_config.json 加载 API Key(构建时由 render.py 注入) */
9-
export async function loadTmdbConfig() {
10-
try {
11-
const resp = await fetch('data/tmdb_config.json')
12-
if (resp.ok) {
13-
const cfg = await resp.json()
14-
tmdbApiKey = cfg.api_key || ''
15-
}
16-
} catch { /* 静默 */ }
17-
// 也支持 Vite env 变量覆盖
18-
if (import.meta.env?.VITE_TMDB_API_KEY) {
19-
tmdbApiKey = import.meta.env.VITE_TMDB_API_KEY
20-
}
21-
}
8+
/** 兼容旧调用,无需异步加载 */
9+
export async function loadTmdbConfig() {}
2210

2311
export function getTmdbApiKey() {
2412
return tmdbApiKey

0 commit comments

Comments
 (0)