diff --git a/server.js b/server.js index 74eb10f..43618f3 100644 --- a/server.js +++ b/server.js @@ -7597,8 +7597,14 @@ async function fileSizeOrNull(targetPath) { } } -function resolveComfySubPath(comfyPath, relativePath) { +function resolveComfySubPath(comfyPath, relativePath, modelsPath) { const normalizedRelative = String(relativePath || '').replace(/^[/\\]+/, ''); + if (modelsPath) { + const afterModels = normalizedRelative.replace(/^models[/\\]?/, ''); + if (afterModels !== normalizedRelative) { + return path.join(modelsPath, afterModels); + } + } return path.join(comfyPath, normalizedRelative); } @@ -7638,7 +7644,7 @@ async function downloadFileWithProgress(url, destinationPath, onChunk) { return { receivedBytes, totalBytes }; } -async function runSetupDownloads(jobId, comfyPath, files) { +async function runSetupDownloads(jobId, comfyPath, files, modelsPath) { const totalExpectedBytes = files.reduce((sum, file) => sum + (Number(file.expectedBytes) || 0), 0); let cumulativeCompletedBytes = 0; @@ -7655,7 +7661,7 @@ async function runSetupDownloads(jobId, comfyPath, files) { for (let index = 0; index < files.length; index += 1) { const file = files[index]; - const destinationPath = resolveComfySubPath(comfyPath, path.join(file.relativeDir, file.fileName)); + const destinationPath = resolveComfySubPath(comfyPath, path.join(file.relativeDir, file.fileName), modelsPath); try { await fs.mkdir(path.dirname(destinationPath), { recursive: true }); @@ -7892,6 +7898,7 @@ app.get('/api/setup/config', async (req, res) => { app.post('/api/setup/check-comfy-path', async (req, res) => { try { const comfyPath = String(req.body?.path || '').trim(); + const modelsPath = String(req.body?.modelsPath || '').trim(); if (!comfyPath) { return res.status(400).json({ error: 'A ComfyUI folder path is required' }); } @@ -7901,23 +7908,30 @@ app.post('/api/setup/check-comfy-path', async (req, res) => { return res.status(400).json({ error: `Folder does not exist: ${comfyPath}` }); } - const modelsDir = path.join(comfyPath, 'models'); - const modelsExist = await pathExists(modelsDir); - if (!modelsExist) { - return res.status(400).json({ error: `This does not look like a ComfyUI folder (missing "models" subfolder): ${comfyPath}` }); + if (modelsPath) { + const modelsPathExists = await pathExists(modelsPath); + if (!modelsPathExists) { + return res.status(400).json({ error: `Models folder does not exist: ${modelsPath}` }); + } + } else { + const modelsDir = path.join(comfyPath, 'models'); + const modelsExist = await pathExists(modelsDir); + if (!modelsExist) { + return res.status(400).json({ error: `This does not look like a ComfyUI folder (missing "models" subfolder): ${comfyPath}` }); + } } const config = await loadSetupConfig(); const created = []; for (const relativePath of Object.values(config.ComfyUIPaths || {})) { - const target = resolveComfySubPath(comfyPath, relativePath); + const target = resolveComfySubPath(comfyPath, relativePath, modelsPath); if (!(await pathExists(target))) { await fs.mkdir(target, { recursive: true }); created.push(relativePath); } } - res.json({ ok: true, comfyPath, createdSubfolders: created }); + res.json({ ok: true, comfyPath, modelsPath, createdSubfolders: created }); } catch (err) { console.error('Failed to validate ComfyUI path:', err); res.status(500).json({ error: err.message || 'Failed to validate ComfyUI path' }); @@ -7927,6 +7941,7 @@ app.post('/api/setup/check-comfy-path', async (req, res) => { app.post('/api/setup/check-files', async (req, res) => { try { const comfyPath = String(req.body?.comfyPath || '').trim(); + const modelsPath = String(req.body?.modelsPath || '').trim(); const files = Array.isArray(req.body?.files) ? req.body.files : []; if (!comfyPath) { @@ -7935,7 +7950,7 @@ app.post('/api/setup/check-files', async (req, res) => { const results = []; for (const file of files) { - const absPath = resolveComfySubPath(comfyPath, path.join(file.relativeDir || '', file.fileName || '')); + const absPath = resolveComfySubPath(comfyPath, path.join(file.relativeDir || '', file.fileName || ''), modelsPath); const size = await fileSizeOrNull(absPath); results.push({ relativeDir: file.relativeDir || '', @@ -7955,6 +7970,7 @@ app.post('/api/setup/check-files', async (req, res) => { app.post('/api/setup/download', async (req, res) => { try { const comfyPath = String(req.body?.comfyPath || '').trim(); + const modelsPath = String(req.body?.modelsPath || '').trim(); const files = Array.isArray(req.body?.files) ? req.body.files : []; if (!comfyPath) { @@ -7970,7 +7986,7 @@ app.post('/api/setup/download', async (req, res) => { const jobId = randomUUID(); getSetupDownloadJob(jobId); - runSetupDownloads(jobId, comfyPath, files).catch(err => { + runSetupDownloads(jobId, comfyPath, files, modelsPath).catch(err => { console.error('[setup] download job crashed:', err); publishSetupDownloadProgress(jobId, { status: 'error', error: err.message || String(err) }); }); diff --git a/src/components/SettingsModal.jsx b/src/components/SettingsModal.jsx index f3eb852..550e3c9 100644 --- a/src/components/SettingsModal.jsx +++ b/src/components/SettingsModal.jsx @@ -1,5 +1,6 @@ import { useState, useEffect } from 'react' import { useSettings } from '../context/SettingsContext.shared' +import { API_BASE } from '../config' import './SettingsModal.css' const CUSTOM_API_TYPE_OPTIONS = [ @@ -182,6 +183,48 @@ function RiggingInstaller() { ) } +// Desktop-only-friendly folder browse button: calls the backend's native folder +// picker (Windows) and reports the chosen path back to the caller. +function BrowseFolderButton({ description, initialPath, onPick }) { + const [busy, setBusy] = useState(false) + const [error, setError] = useState('') + + const handleClick = async () => { + setError(''); setBusy(true) + try { + const res = await fetch(`${API_BASE}/setup/pick-folder`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ description, initialPath }) + }) + const data = await res.json() + if (!res.ok) throw new Error(data?.error || 'Folder picker failed') + if (data.path) onPick(data.path) + } catch (err) { + setError(err.message || String(err)) + } finally { + setBusy(false) + } + } + + return ( + <> + + {error &&

{error}

} + + ) +} + export default function SettingsModal({ onClose }) { const { settings, updateSettings, addCustomApi } = useSettings() const [localSettings, setLocalSettings] = useState(settings) @@ -536,21 +579,65 @@ export default function SettingsModal({ onClose }) {
- setLocalSettings(prev => ({ - ...prev, - apis: { - ...prev?.apis, - comfyui: { - ...prev?.apis?.comfyui, - path: e.target.value +
+ setLocalSettings(prev => ({ + ...prev, + apis: { + ...prev?.apis, + comfyui: { + ...prev?.apis?.comfyui, + path: e.target.value + } } - } - }))} - /> + }))} + /> + setLocalSettings(prev => ({ + ...prev, + apis: { ...prev?.apis, comfyui: { ...prev?.apis?.comfyui, path: picked } } + }))} + /> +
+
+ +
+ +
+ setLocalSettings(prev => ({ + ...prev, + apis: { + ...prev?.apis, + comfyui: { + ...prev?.apis?.comfyui, + modelsPath: e.target.value + } + } + }))} + /> + setLocalSettings(prev => ({ + ...prev, + apis: { ...prev?.apis, comfyui: { ...prev?.apis?.comfyui, modelsPath: picked } } + }))} + /> +
+

+ Set this only if your models live somewhere other than {'{ComfyUI path}'}\models (e.g. shared across multiple ComfyUI installs). +

diff --git a/src/components/SetupWizardModal.jsx b/src/components/SetupWizardModal.jsx index 338bc91..d490a48 100644 --- a/src/components/SetupWizardModal.jsx +++ b/src/components/SetupWizardModal.jsx @@ -74,9 +74,11 @@ export default function SetupWizardModal({ onComplete, onClose }) { const [loadError, setLoadError] = useState('') const [comfyPath, setComfyPath] = useState('') + const [modelsPath, setModelsPath] = useState('') const [pathBusy, setPathBusy] = useState(false) const [pathError, setPathError] = useState('') const [browseBusy, setBrowseBusy] = useState(false) + const [browseModelsBusy, setBrowseModelsBusy] = useState(false) const [selectionByName, setSelectionByName] = useState({}) const [existingFileKeys, setExistingFileKeys] = useState(new Set()) @@ -117,6 +119,10 @@ export default function SetupWizardModal({ onComplete, onClose }) { setComfyPath(settings?.apis?.comfyui?.path || '') }, [settings?.apis?.comfyui?.path]) + useEffect(() => { + setModelsPath(settings?.apis?.comfyui?.modelsPath || '') + }, [settings?.apis?.comfyui?.modelsPath]) + useEffect(() => () => { eventSourceRef.current?.close() }, []) @@ -131,9 +137,10 @@ export default function SetupWizardModal({ onComplete, onClose }) { return buildFileList(config, allSelections, paths) }, [config]) - const refreshFileExistence = useCallback(async (pathOverride) => { + const refreshFileExistence = useCallback(async (pathOverride, modelsPathOverride) => { if (!config) return const effectivePath = pathOverride ?? comfyPath + const effectiveModelsPath = modelsPathOverride ?? modelsPath if (!effectivePath) return setCheckingFiles(true) @@ -141,7 +148,7 @@ export default function SetupWizardModal({ onComplete, onClose }) { const res = await fetch(`${API_BASE}/setup/check-files`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ comfyPath: effectivePath, files: allCandidateFiles }) + body: JSON.stringify({ comfyPath: effectivePath, modelsPath: effectiveModelsPath, files: allCandidateFiles }) }) const data = await res.json() if (!res.ok) throw new Error(data?.error || 'Failed to check files') @@ -156,7 +163,7 @@ export default function SetupWizardModal({ onComplete, onClose }) { } finally { setCheckingFiles(false) } - }, [allCandidateFiles, comfyPath, config]) + }, [allCandidateFiles, comfyPath, modelsPath, config]) const selections = useMemo( () => Object.entries(selectionByName).map(([diffusionName, modelQuality]) => ({ diffusionName, modelQuality })), @@ -255,15 +262,35 @@ export default function SetupWizardModal({ onComplete, onClose }) { } } + const handleBrowseModelsFolder = async () => { + setPathError('') + setBrowseModelsBusy(true) + try { + const res = await fetch(`${API_BASE}/setup/pick-folder`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ description: 'Select your ComfyUI models folder', initialPath: modelsPath || comfyPath }) + }) + const data = await res.json() + if (!res.ok) throw new Error(data?.error || 'Folder picker failed') + if (data.path) setModelsPath(data.path) + } catch (err) { + setPathError(err.message || String(err)) + } finally { + setBrowseModelsBusy(false) + } + } + const handleValidatePath = async () => { setPathError('') setPathBusy(true) try { const trimmed = comfyPath.trim() + const trimmedModelsPath = modelsPath.trim() const res = await fetch(`${API_BASE}/setup/check-comfy-path`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ path: trimmed }) + body: JSON.stringify({ path: trimmed, modelsPath: trimmedModelsPath }) }) const data = await res.json() if (!res.ok) throw new Error(data?.error || 'Invalid ComfyUI path') @@ -272,11 +299,11 @@ export default function SetupWizardModal({ onComplete, onClose }) { ...settings, apis: { ...(settings?.apis || {}), - comfyui: { ...(settings?.apis?.comfyui || {}), path: trimmed } + comfyui: { ...(settings?.apis?.comfyui || {}), path: trimmed, modelsPath: trimmedModelsPath } } }) - await refreshFileExistence(trimmed) + await refreshFileExistence(trimmed, trimmedModelsPath) setStepId('models') } catch (err) { setPathError(err.message || String(err)) @@ -298,7 +325,7 @@ export default function SetupWizardModal({ onComplete, onClose }) { const res = await fetch(`${API_BASE}/setup/download`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ comfyPath, files: filesToDownload }) + body: JSON.stringify({ comfyPath, modelsPath, files: filesToDownload }) }) const data = await res.json() if (!res.ok) throw new Error(data?.error || 'Failed to start downloads') @@ -440,7 +467,36 @@ export default function SetupWizardModal({ onComplete, onClose }) {

- The folder must contain a models subfolder. Missing model-type subfolders will be created. + {modelsPath.trim() + ? 'Missing model-type subfolders will be created inside your models folder below.' + : <>The folder must contain a models subfolder. Missing model-type subfolders will be created.} +

+ + +
+ setModelsPath(e.target.value)} + /> + +
+

+ Set this only if your models live somewhere other than {'{ComfyUI folder}'}\models (e.g. shared across multiple ComfyUI installs).

{pathError &&
{pathError}
} diff --git a/src/context/SettingsContext.jsx b/src/context/SettingsContext.jsx index af4911c..92801f2 100644 --- a/src/context/SettingsContext.jsx +++ b/src/context/SettingsContext.jsx @@ -151,6 +151,7 @@ export function SettingsProvider({ children }) { }, comfyui: { path: '', + modelsPath: '', url: 'http://127.0.0.1', port: '8188' }, diff --git a/storage.js b/storage.js index e7702b8..fcac375 100644 --- a/storage.js +++ b/storage.js @@ -176,6 +176,9 @@ export const DEFAULT_SETTINGS = { }, comfyui: { path: '', + // Optional override for where models live, when it's not "{path}/models" + // (e.g. models are shared across ComfyUI installs via extra_model_paths.yaml). + modelsPath: '', url: 'http://127.0.0.1', port: '8188' },