diff --git a/src/modules/auth-files.js b/src/modules/auth-files.js index cc47b3f..60e4ab8 100644 --- a/src/modules/auth-files.js +++ b/src/modules/auth-files.js @@ -1049,6 +1049,50 @@ export const authFilesModule = { return normalized; }, + resolveOauthExcludedFromConfig(config = null) { + const sources = []; + if (config && typeof config === 'object') { + sources.push(config); + } + if (this.configCache && typeof this.configCache === 'object') { + if (this.configCache['oauth-excluded-models'] !== undefined) { + sources.push({ 'oauth-excluded-models': this.configCache['oauth-excluded-models'] }); + } + if (this.configCache['__full__']) { + sources.push(this.configCache['__full__']); + } + } + + for (const source of sources) { + if (!source || typeof source !== 'object') continue; + if (Object.prototype.hasOwnProperty.call(source, 'oauth-excluded-models')) { + return { + map: this.normalizeOauthExcludedMap(source), + found: true + }; + } + } + + return { map: {}, found: false }; + }, + + applyOauthExcludedFromConfig(config = null, options = {}) { + const { render = true } = options || {}; + const { map, found } = this.resolveOauthExcludedFromConfig(config); + if (!found) { + return false; + } + + this.oauthExcludedModels = map; + this._oauthExcludedLoading = false; + this.setOauthExcludedStatus(''); + this.updateOauthExcludedButtonsState(false); + if (render) { + this.renderOauthExcludedModels(); + } + return true; + }, + getFilteredOauthExcludedMap(filterType = this.currentAuthFileFilter) { const map = this.oauthExcludedModels || {}; if (!map || typeof map !== 'object') { @@ -1407,9 +1451,36 @@ export const authFilesModule = { this.renderOauthExcludedModels(); try { - const data = await this.makeRequest('/oauth-excluded-models'); - this.oauthExcludedModels = this.normalizeOauthExcludedMap(data); - this.refreshOauthProviderOptions(); + let targetMap = {}; + let hasData = false; + + if (!forceRefresh) { + const { map, found } = this.resolveOauthExcludedFromConfig(); + if (found) { + targetMap = map; + hasData = true; + } + } + + if (!hasData) { + try { + const configSection = await this.getConfig('oauth-excluded-models', forceRefresh); + if (configSection !== undefined) { + targetMap = this.normalizeOauthExcludedMap(configSection); + hasData = true; + } + } catch (configError) { + console.warn('从配置获取 OAuth 排除列表失败,尝试回退接口:', configError); + } + } + + if (!hasData) { + const data = await this.makeRequest('/oauth-excluded-models'); + targetMap = this.normalizeOauthExcludedMap(data); + hasData = true; + } + + this.oauthExcludedModels = targetMap; this.setOauthExcludedStatus(''); } catch (error) { console.error('加载 OAuth 排除列表失败:', error); @@ -1501,6 +1572,7 @@ export const authFilesModule = { } this.events.on('data:config-loaded', async (event) => { const detail = event?.detail || {}; + const config = detail.config || {}; const keyStats = detail.keyStats || null; try { await this.loadAuthFiles(keyStats); @@ -1508,7 +1580,10 @@ export const authFilesModule = { console.error('加载认证文件失败:', error); } try { - await this.loadOauthExcludedModels(true); + const applied = this.applyOauthExcludedFromConfig(config, { render: true }); + if (!applied) { + await this.loadOauthExcludedModels(true); + } } catch (error) { console.error('加载 OAuth 排除列表失败:', error); } @@ -1518,7 +1593,9 @@ export const authFilesModule = { const detail = event?.detail || {}; this.updateOauthExcludedButtonsState(false); if (detail.isConnected) { - this.loadOauthExcludedModels(true); + if (!this.applyOauthExcludedFromConfig(null, { render: true })) { + this.renderOauthExcludedModels(); + } } else { this.renderOauthExcludedModels(); }