(req: Request, res: Response)
| 202 | * @param res |
| 203 | */ |
| 204 | export async function ApiSetupConfig(req: Request, res: Response) { |
| 205 | try { |
| 206 | const { data, installedComfyUI } = req.body; |
| 207 | let comfyUIPath = data.comfyUIDir.trim(); |
| 208 | if (!comfyUIPath) { |
| 209 | throw new Error("ComfyUI path is empty"); |
| 210 | } |
| 211 | |
| 212 | // User select custom install comfyUI folder, comfyUI path will add the folder path |
| 213 | if (!installedComfyUI && comfyUIPath !== DEFAULT_COMFYUI_PATH) { |
| 214 | comfyUIPath = path.resolve(comfyUIPath, "ComfyUI"); |
| 215 | } |
| 216 | |
| 217 | let isComfyUIInstalled = await checkIfInstalledComfyUI(comfyUIPath); |
| 218 | |
| 219 | // user select pre installed comfyUI but it's not installed |
| 220 | if (comfyUIPath !== DEFAULT_COMFYUI_PATH && installedComfyUI && !isComfyUIInstalled) { |
| 221 | logger.info("isComfy isntall", isComfyUIInstalled, comfyUIPath, DEFAULT_COMFYUI_PATH); |
| 222 | throw new Error("Your custom ComfyUI path is not valid, check if it's a git repo clone from ComfyUI https://github.com/comfyanonymous/ComfyUI"); |
| 223 | } |
| 224 | |
| 225 | const stableDiffusionPath = (data.stableDiffusionDir || "").trim() |
| 226 | if (stableDiffusionPath !== "") { |
| 227 | if (!fsExtra.existsSync(path.resolve(stableDiffusionPath, "webui.py"))) { |
| 228 | throw new Error("Doesn't find webui.py in stable diffusion path, please check if it's a valid diffusion path"); |
| 229 | } |
| 230 | |
| 231 | if (!fsExtra.existsSync(path.resolve(stableDiffusionPath, "models"))) { |
| 232 | throw new Error("Doesn't find models in stable diffusion path, please check if it's a valid diffusion path"); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | if (data.pythonPath) { |
| 237 | console.log("python path", data.pythonPath) |
| 238 | await verifyPythonPath(data.pythonPath); |
| 239 | } |
| 240 | |
| 241 | const setupString = JSON.stringify({ |
| 242 | comfyUIDir: comfyUIPath, |
| 243 | pythonPath: data.pythonPath || undefined, |
| 244 | isCustomComfyEnv: !!data.pythonPath, |
| 245 | stableDiffusionDir: stableDiffusionPath |
| 246 | }); |
| 247 | |
| 248 | appConfigManager.set(CONFIG_KEYS.appSetupConfig, setupString); |
| 249 | |
| 250 | // if (data.pythonPath) { |
| 251 | // conda.updateCondaInfo(); |
| 252 | // } |
| 253 | |
| 254 | res.send({ |
| 255 | success: true, |
| 256 | isComfyUIInstalled, |
| 257 | }); |
| 258 | } catch (err: any) { |
| 259 | logger.error(err.message + ":" + err.stack); |
| 260 | res.send({ |
| 261 | success: false, |
nothing calls this directly
no test coverage detected