Logankunfall commited on
Commit
4ccfabc
·
verified ·
1 Parent(s): 08992d8

Upload 8 files

Browse files
Files changed (1) hide show
  1. public/script.js +24 -0
public/script.js CHANGED
@@ -11,6 +11,9 @@ document.addEventListener('DOMContentLoaded', function() {
11
  initializeTheme();
12
  initializeEventListeners();
13
  initializeRangeSliders();
 
 
 
14
  checkApiKeyStatus();
15
  loadVideoLibrary();
16
  console.log('初始化完成');
@@ -50,6 +53,24 @@ function toggleTheme() {
50
  setTheme(newTheme);
51
  }
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  // API Key 管理功能
54
  async function checkApiKeyStatus() {
55
  try {
@@ -327,6 +348,9 @@ async function saveApiKey() {
327
 
328
  if (result.success) {
329
  showNotification('API 密钥保存成功', 'success');
 
 
 
330
  checkApiKeyStatus();
331
  const apiKeyModal = document.getElementById('apiKeyModal');
332
  if (apiKeyModal) apiKeyModal.style.display = 'none';
 
11
  initializeTheme();
12
  initializeEventListeners();
13
  initializeRangeSliders();
14
+ // 先加载本地缓存的 API 密钥,避免未传 key 导致 401
15
+ loadLocalApiKey();
16
+ // 再检查后端密钥状态(环境变量/服务端存储)
17
  checkApiKeyStatus();
18
  loadVideoLibrary();
19
  console.log('初始化完成');
 
53
  setTheme(newTheme);
54
  }
55
 
56
+ // 从本地缓存读取 API 密钥并启用(不改后端)
57
+ function loadLocalApiKey() {
58
+ try {
59
+ const cached = localStorage.getItem('fal_api_key');
60
+ if (cached && cached.length >= 10) {
61
+ currentApiKey = cached;
62
+ const apiKeyStatus = document.getElementById('apiKeyStatus');
63
+ const apiKeyButton = document.getElementById('apiKeyButton');
64
+ const modalApiKeyStatus = document.getElementById('modalApiKeyStatus');
65
+ if (apiKeyStatus) apiKeyStatus.textContent = '本地缓存';
66
+ if (apiKeyButton) apiKeyButton.classList.add('configured');
67
+ if (modalApiKeyStatus) modalApiKeyStatus.textContent = '已配置(来源:本地缓存)';
68
+ }
69
+ } catch (e) {
70
+ console.warn('读取本地缓存的 API key 失败:', e);
71
+ }
72
+ }
73
+
74
  // API Key 管理功能
75
  async function checkApiKeyStatus() {
76
  try {
 
348
 
349
  if (result.success) {
350
  showNotification('API 密钥保存成功', 'success');
351
+ // 同步前端使用,避免未传 key 导致 401
352
+ currentApiKey = apiKey;
353
+ try { localStorage.setItem('fal_api_key', apiKey); } catch (e) {}
354
  checkApiKeyStatus();
355
  const apiKeyModal = document.getElementById('apiKeyModal');
356
  if (apiKeyModal) apiKeyModal.style.display = 'none';