mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-06 23:12:22 +02:00
static/js/settings.js was 5,721 lines behind a four-name public surface. static/js/settings/ already existed with dom, registry, search, sidebar, navigation and lifecycle, so this continues that package rather than inventing a layout. Moved verbatim, 407 lines: settings/speech.js initTtsSettings, initSttSettings settings/writingStyle.js initDocumentWritingStyle settings/imageModels.js initImageSettings settings/agent.js initAgentSettings settings/api.js postSettings, lifted from _postSettings These five were chosen because their only dependencies outside themselves were el/byId, _postSettings and sortModelIds. Panels with wider reach stay put: initEmailAccountsSettings, for instance, pulls a 64-declaration closure covering most of the file, and splitting that is a design change rather than a move. settings.js keeps its public surface exactly: open, close, refreshAiModelEndpoints and the default export, verified in a browser. Three test updates the move required: - tests/helpers/test_settings_shell_coordinator.mjs allowlists the real modules the coordinator may import, and rejected the new ones. That guard working is the reason to trust the rest of this diff. - two source-introspection tests read settings.js for behaviour that now lives in a panel module. They read the whole settings surface now, so the next extraction does not break them again.
60 lines
2.9 KiB
JavaScript
60 lines
2.9 KiB
JavaScript
// Image-model settings panel.
|
|
// Extracted verbatim from static/js/settings.js. Behaviour is unchanged: the
|
|
// functions moved, their bodies did not. settings.js imports them and calls
|
|
// them from the same places, so load order and init sequence are untouched.
|
|
|
|
import { byId as el } from './dom.js';
|
|
import { postSettings as _postSettings } from './api.js';
|
|
import { sortModelIds } from '../modelSort.js';
|
|
|
|
export async function initImageSettings() {
|
|
const modelSel = el('set-imgModelSelect');
|
|
const qualSel = el('set-imgQualitySelect');
|
|
const msg = el('set-imgSettingsMsg');
|
|
const enabledToggle = el('set-imgEnabledToggle');
|
|
const configWrap = modelSel ? modelSel.closest('div[style*="flex-direction"]') : null;
|
|
try {
|
|
const endpointsRes = await fetch('/api/model-endpoints', { credentials: 'same-origin' });
|
|
const endpoints = await endpointsRes.json();
|
|
const imageModels = new Set();
|
|
(Array.isArray(endpoints) ? endpoints : []).forEach(endpoint => {
|
|
if (!endpoint.is_enabled || !endpoint.online || String(endpoint.model_type || '').toLowerCase() !== 'image') return;
|
|
(Array.isArray(endpoint.models) ? endpoint.models : []).forEach(modelId => {
|
|
if (modelId) imageModels.add(String(modelId));
|
|
});
|
|
});
|
|
sortModelIds(Array.from(imageModels)).forEach(mid => {
|
|
const opt = document.createElement('option');
|
|
opt.value = mid;
|
|
opt.textContent = mid;
|
|
modelSel.appendChild(opt);
|
|
});
|
|
} catch (e) { console.warn('Failed to load models for image settings', e); }
|
|
try {
|
|
const settingsRes = await fetch('/api/auth/settings', { credentials: 'same-origin' });
|
|
const settings = await settingsRes.json();
|
|
if (settings.image_model) modelSel.value = settings.image_model;
|
|
if (settings.image_quality) qualSel.value = settings.image_quality;
|
|
if (enabledToggle) enabledToggle.checked = settings.image_gen_enabled === true;
|
|
} catch (e) { console.warn('Failed to load settings', e); }
|
|
|
|
function syncImgDisabled() {
|
|
var off = enabledToggle && !enabledToggle.checked;
|
|
var card = enabledToggle ? enabledToggle.closest('.admin-card') : null;
|
|
if (card) card.style.opacity = off ? '0.45' : '';
|
|
if (configWrap) configWrap.style.pointerEvents = off ? 'none' : '';
|
|
}
|
|
syncImgDisabled();
|
|
|
|
async function saveSettings() {
|
|
try {
|
|
const res = await _postSettings({ image_gen_enabled: enabledToggle ? enabledToggle.checked : false, image_model: modelSel.value, image_quality: qualSel.value });
|
|
if (!res.ok) throw new Error(await res.text().catch(() => `HTTP ${res.status}`));
|
|
msg.textContent = 'Saved'; msg.style.color = 'var(--fg)'; setTimeout(() => { msg.textContent = ''; }, 2000);
|
|
} catch (e) { msg.textContent = 'Failed to save'; msg.style.color = 'var(--red)'; }
|
|
}
|
|
modelSel.addEventListener('change', saveSettings);
|
|
qualSel.addEventListener('change', saveSettings);
|
|
if (enabledToggle) enabledToggle.addEventListener('change', function() { syncImgDisabled(); saveSettings(); });
|
|
}
|