@@ -276,8 +276,8 @@
< div id = "cacheOptions" style = "display: none;" class = "space-y-4 pt-4 border-t border-border" >
< div >
< label class = "text-sm font-medium mb-2 block" > 缓存超时时间(秒)< / label >
< input id = "cfgCacheTimeout" type = "number" class = "flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm" placeholder = "7200" min = "6 0" max = "86400" >
< p class = "text-xs text-muted-foreground mt-1" > 文件缓存超时时间,范围:6 0-86400 秒( 1分钟-24小时) < / p >
< input id = "cfgCacheTimeout" type = "number" class = "flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm" placeholder = "7200" min = "0" max = "86400" >
< p class = "text-xs text-muted-foreground mt-1" > 文件缓存超时时间, 范围: 0-86400 秒,其中 0 表示永不过期,不自动删除缓存文件 < / p >
< / div >
< div >
< label class = "text-sm font-medium mb-2 block" > 缓存文件访问域名< / label >
@@ -805,9 +805,9 @@
testProxyConfig = async ( ) => { const tests = [ ] ; const requestProxyUrl = $ ( 'cfgProxyUrl' ) . value . trim ( ) ; const mediaProxyUrl = $ ( 'cfgMediaProxyUrl' ) . value . trim ( ) ; const testUrl = 'https://labs.google/' ; if ( requestProxyUrl ) tests . push ( { name : '请求代理' , proxy _url : requestProxyUrl } ) ; if ( mediaProxyUrl && mediaProxyUrl !== requestProxyUrl ) tests . push ( { name : '媒体代理' , proxy _url : mediaProxyUrl } ) ; if ( tests . length === 0 ) { updateProxyTestResult ( '请先填写至少一个代理地址' , false ) ; showToast ( '请先填写代理地址' , 'error' ) ; return } const btn = $ ( 'btnTestProxy' ) ; if ( btn ) { btn . disabled = true ; btn . textContent = '测试中...' } try { const results = [ ] ; for ( const item of tests ) { const r = await apiRequest ( '/api/proxy/test' , { method : 'POST' , body : JSON . stringify ( { proxy _url : item . proxy _url , test _url : testUrl } ) } ) ; if ( ! r ) { results . push ( { name : item . name , success : false , message : '请求失败' } ) ; continue } const d = await r . json ( ) ; results . push ( { name : item . name , success : ! ! d . success , message : d . message || '未知结果' , status _code : d . status _code , elapsed _ms : d . elapsed _ms , final _url : d . final _url } ) } const allPass = results . every ( x => x . success ) ; const summary = results . map ( x => ` ${ x . name } : ${ x . success ? '✅' : '❌' } ${ x . message } ${ x . status _code ? ` (HTTP ${ x . status _code } ) ` : '' } ${ x . elapsed _ms !== undefined ? ` ${ x . elapsed _ms } ms ` : '' } ` ) . join ( ' | ' ) ; updateProxyTestResult ( summary , allPass ) ; showToast ( allPass ? '代理测试通过' : '代理测试未全部通过' , allPass ? 'success' : 'error' ) } catch ( e ) { updateProxyTestResult ( '代理测试失败: ' + e . message , false ) ; showToast ( '代理测试失败: ' + e . message , 'error' ) } finally { if ( btn ) { btn . disabled = false ; btn . textContent = '测试代理' } } } ,
toggleMediaProxyInput = ( ) => { const enabled = $ ( 'cfgMediaProxyEnabled' ) . checked ; $ ( 'mediaProxyUrlInput' ) . classList . toggle ( 'hidden' , ! enabled ) } ,
toggleCacheOptions = ( ) => { const enabled = $ ( 'cfgCacheEnabled' ) . checked ; $ ( 'cacheOptions' ) . style . display = enabled ? 'block' : 'none' } ,
loadCacheConfig = async ( ) => { try { console . log ( '开始加载缓存配置...' ) ; const r = await apiRequest ( '/api/cache/config' ) ; if ( ! r ) { console . error ( 'API请求失败' ) ; return } const d = await r . json ( ) ; console . log ( '缓存配置数据:' , d ) ; if ( d . success && d . config ) { const enabled = d . config . enabled !== false ; const timeout = d . config . timeout || 7200 ; const baseUrl = d . config . base _url || '' ; const effectiveUrl = d . config . effective _base _url || '' ; console . log ( '设置缓存启用:' , enabled ) ; console . log ( '设置超时时间:' , timeout ) ; console . log ( '设置域名:' , baseUrl ) ; console . log ( '生效URL:' , effectiveUrl ) ; $ ( 'cfgCacheEnabled' ) . checked = enabled ; $ ( 'cfgCacheTimeout' ) . value = timeout ; $ ( 'cfgCacheBaseUrl' ) . value = baseUrl ; if ( effectiveUrl ) { $ ( 'cacheEffectiveUrlValue' ) . textContent = effectiveUrl ; $ ( 'cacheEffectiveUrl' ) . classList . remove ( 'hidden' ) } else { $ ( 'cacheEffectiveUrl' ) . classList . add ( 'hidden' ) } toggleCacheOptions ( ) ; console . log ( '缓存配置加载成功' ) } else { console . error ( '缓存配置数据格式错误:' , d ) } } catch ( e ) { console . error ( '加载缓存配置失败:' , e ) ; showToast ( '加载缓存配置失败: ' + e . message , 'error' ) } } ,
loadCacheConfig = async ( ) => { try { console . log ( '开始加载缓存配置...' ) ; const r = await apiRequest ( '/api/cache/config' ) ; if ( ! r ) { console . error ( 'API请求失败' ) ; return } const d = await r . json ( ) ; console . log ( '缓存配置数据:' , d ) ; if ( d . success && d . config ) { const enabled = d . config . enabled !== false ; const timeout = d . config . timeout ? ? 7200 ; const baseUrl = d . config . base _url || '' ; const effectiveUrl = d . config . effective _base _url || '' ; console . log ( '设置缓存启用:' , enabled ) ; console . log ( '设置超时时间:' , timeout ) ; console . log ( '设置域名:' , baseUrl ) ; console . log ( '生效URL:' , effectiveUrl ) ; $ ( 'cfgCacheEnabled' ) . checked = enabled ; $ ( 'cfgCacheTimeout' ) . value = timeout ; $ ( 'cfgCacheBaseUrl' ) . value = baseUrl ; if ( effectiveUrl ) { $ ( 'cacheEffectiveUrlValue' ) . textContent = effectiveUrl ; $ ( 'cacheEffectiveUrl' ) . classList . remove ( 'hidden' ) } else { $ ( 'cacheEffectiveUrl' ) . classList . add ( 'hidden' ) } toggleCacheOptions ( ) ; console . log ( '缓存配置加载成功' ) } else { console . error ( '缓存配置数据格式错误:' , d ) } } catch ( e ) { console . error ( '加载缓存配置失败:' , e ) ; showToast ( '加载缓存配置失败: ' + e . message , 'error' ) } } ,
loadGenerationTimeout = async ( ) => { try { console . log ( '开始加载生成超时配置...' ) ; const r = await apiRequest ( '/api/generation/timeout' ) ; if ( ! r ) { console . error ( 'API请求失败' ) ; return } const d = await r . json ( ) ; console . log ( '生成超时配置数据:' , d ) ; if ( d . success && d . config ) { const imageTimeout = d . config . image _timeout || 300 ; const videoTimeout = d . config . video _timeout || 1500 ; console . log ( '设置图片超时:' , imageTimeout ) ; console . log ( '设置视频超时:' , videoTimeout ) ; $ ( 'cfgImageTimeout' ) . value = imageTimeout ; $ ( 'cfgVideoTimeout' ) . value = videoTimeout ; console . log ( '生成超时配置加载成功' ) } else { console . error ( '生成超时配置数据格式错误:' , d ) } } catch ( e ) { console . error ( '加载生成超时配置失败:' , e ) ; showToast ( '加载生成超时配置失败: ' + e . message , 'error' ) } } ,
saveCacheConfig = async ( ) => { const enabled = $ ( 'cfgCacheEnabled' ) . checked , timeout =parseInt ( $ ( 'cfgCacheTimeout' ) . value ) || 7200 , baseUrl = $ ( 'cfgCacheBaseUrl' ) . value . trim ( ) ; console . log ( '保存缓存配置:' , { enabled , timeout , baseUrl } ) ; if ( timeout < 6 0|| timeout > 86400 ) return showToast ( '缓存超时时间必须在 6 0-86400 秒之间' , 'error' ) ; if ( baseUrl && ! baseUrl . startsWith ( 'http://' ) && ! baseUrl . startsWith ( 'https://' ) ) return showToast ( '域名必须以 http:// 或 https:// 开头' , 'error' ) ; try { console . log ( '保存缓存启用状态...' ) ; const r0 = await apiRequest ( '/api/cache/enabled' , { method : 'POST' , body : JSON . stringify ( { enabled : enabled } ) } ) ; if ( ! r0 ) { console . error ( '保存缓存启用状态请求失败' ) ; return } const d0 = await r0 . json ( ) ; console . log ( '缓存启用状态保存结果:' , d0 ) ; if ( ! d0 . success ) { console . error ( '保存缓存启用状态失败:' , d0 ) ; return showToast ( '保存缓存启用状态失败' , 'error' ) } console . log ( '保存超时时间...' ) ; const r1 = await apiRequest ( '/api/cache/config' , { method : 'POST' , body : JSON . stringify ( { timeout : timeout } ) } ) ; if ( ! r1 ) { console . error ( '保存超时时间请求失败' ) ; return } const d1 = await r1 . json ( ) ; console . log ( '超时时间保存结果:' , d1 ) ; if ( ! d1 . success ) { console . error ( '保存超时时间失败:' , d1 ) ; return showToast ( '保存超时时间失败' , 'error' ) } console . log ( '保存域名...' ) ; const r2 = await apiRequest ( '/api/cache/base-url' , { method : 'POST' , body : JSON . stringify ( { base _url : baseUrl } ) } ) ; if ( ! r2 ) { console . error ( '保存域名请求失败' ) ; return } const d2 = await r2 . json ( ) ; console . log ( '域名保存结果:' , d2 ) ; if ( d2 . success ) { showToast ( '缓存配置保存成功' , 'success' ) ; console . log ( '等待配置文件写入完成...' ) ; await new Promise ( r => setTimeout ( r , 200 ) ) ; console . log ( '重新加载配置...' ) ; await loadCacheConfig ( ) } else { console . error ( '保存域名失败:' , d2 ) ; showToast ( '保存域名失败' , 'error' ) } } catch ( e ) { console . error ( '保存失败:' , e ) ; showToast ( '保存失败: ' + e . message , 'error' ) } } ,
saveCacheConfig = async ( ) => { const enabled = $ ( 'cfgCacheEnabled' ) . checked , timeoutInput = $ ( 'cfgCacheTimeout' ) . value . trim ( ) , timeout = timeoutInput === '' ? 7200 : parseInt ( timeoutInput , 10 ) , baseUrl = $ ( 'cfgCacheBaseUrl' ) . value . trim ( ) ; console . log ( '保存缓存配置:' , { enabled , timeout , baseUrl } ) ; if ( Number . isNaN ( timeout ) || timeout < 0 || timeout > 86400 ) return showToast ( '缓存超时时间必须在 0-86400 秒之间, 0 表示不删除 ' , 'error' ) ; if ( baseUrl && ! baseUrl . startsWith ( 'http://' ) && ! baseUrl . startsWith ( 'https://' ) ) return showToast ( '域名必须以 http:// 或 https:// 开头' , 'error' ) ; try { console . log ( '保存缓存启用状态...' ) ; const r0 = await apiRequest ( '/api/cache/enabled' , { method : 'POST' , body : JSON . stringify ( { enabled : enabled } ) } ) ; if ( ! r0 ) { console . error ( '保存缓存启用状态请求失败' ) ; return } const d0 = await r0 . json ( ) ; console . log ( '缓存启用状态保存结果:' , d0 ) ; if ( ! d0 . success ) { console . error ( '保存缓存启用状态失败:' , d0 ) ; return showToast ( '保存缓存启用状态失败' , 'error' ) } console . log ( '保存超时时间...' ) ; const r1 = await apiRequest ( '/api/cache/config' , { method : 'POST' , body : JSON . stringify ( { timeout : timeout } ) } ) ; if ( ! r1 ) { console . error ( '保存超时时间请求失败' ) ; return } const d1 = await r1 . json ( ) ; console . log ( '超时时间保存结果:' , d1 ) ; if ( ! d1 . success ) { console . error ( '保存超时时间失败:' , d1 ) ; return showToast ( '保存超时时间失败' , 'error' ) } console . log ( '保存域名...' ) ; const r2 = await apiRequest ( '/api/cache/base-url' , { method : 'POST' , body : JSON . stringify ( { base _url : baseUrl } ) } ) ; if ( ! r2 ) { console . error ( '保存域名请求失败' ) ; return } const d2 = await r2 . json ( ) ; console . log ( '域名保存结果:' , d2 ) ; if ( d2 . success ) { showToast ( '缓存配置保存成功' , 'success' ) ; console . log ( '等待配置文件写入完成...' ) ; await new Promise ( r => setTimeout ( r , 200 ) ) ; console . log ( '重新加载配置...' ) ; await loadCacheConfig ( ) } else { console . error ( '保存域名失败:' , d2 ) ; showToast ( '保存域名失败' , 'error' ) } } catch ( e ) { console . error ( '保存失败:' , e ) ; showToast ( '保存失败: ' + e . message , 'error' ) } } ,
saveGenerationTimeout = async ( ) => { const imageTimeout = parseInt ( $ ( 'cfgImageTimeout' ) . value ) || 300 , videoTimeout = parseInt ( $ ( 'cfgVideoTimeout' ) . value ) || 1500 ; console . log ( '保存生成超时配置:' , { imageTimeout , videoTimeout } ) ; if ( imageTimeout < 60 || imageTimeout > 3600 ) return showToast ( '图片超时时间必须在 60-3600 秒之间' , 'error' ) ; if ( videoTimeout < 60 || videoTimeout > 7200 ) return showToast ( '视频超时时间必须在 60-7200 秒之间' , 'error' ) ; try { const r = await apiRequest ( '/api/generation/timeout' , { method : 'POST' , body : JSON . stringify ( { image _timeout : imageTimeout , video _timeout : videoTimeout } ) } ) ; if ( ! r ) { console . error ( '保存请求失败' ) ; return } const d = await r . json ( ) ; console . log ( '保存结果:' , d ) ; if ( d . success ) { showToast ( '生成超时配置保存成功' , 'success' ) ; await new Promise ( r => setTimeout ( r , 200 ) ) ; await loadGenerationTimeout ( ) } else { console . error ( '保存失败:' , d ) ; showToast ( '保存失败' , 'error' ) } } catch ( e ) { console . error ( '保存失败:' , e ) ; showToast ( '保存失败: ' + e . message , 'error' ) } } ,
toggleCaptchaOptions = ( ) => { const method = $ ( 'cfgCaptchaMethod' ) . value ; $ ( 'yescaptchaOptions' ) . style . display = method === 'yescaptcha' ? 'block' : 'none' ; $ ( 'capmonsterOptions' ) . classList . toggle ( 'hidden' , method !== 'capmonster' ) ; $ ( 'ezcaptchaOptions' ) . classList . toggle ( 'hidden' , method !== 'ezcaptcha' ) ; $ ( 'capsolverOptions' ) . classList . toggle ( 'hidden' , method !== 'capsolver' ) ; $ ( 'browserCaptchaOptions' ) . classList . toggle ( 'hidden' , method !== 'browser' ) ; $ ( 'remoteBrowserOptions' ) . classList . toggle ( 'hidden' , method !== 'remote_browser' ) } ,
toggleBrowserProxyInput = ( ) => { const enabled = $ ( 'cfgBrowserProxyEnabled' ) . checked ; $ ( 'browserProxyUrlInput' ) . classList . toggle ( 'hidden' , ! enabled ) } ,