(req: SetAppConfigRequest)
| 168 | |
| 169 | # API implementations |
| 170 | def set_app_config_internal(req: SetAppConfigRequest): |
| 171 | config = app.getConfig() |
| 172 | if req.update_branch is not None: |
| 173 | config["update_branch"] = req.update_branch |
| 174 | if req.render_devices is not None: |
| 175 | update_render_devices_in_config(config, req.render_devices) |
| 176 | if req.ui_open_browser_on_start is not None: |
| 177 | if "ui" not in config: |
| 178 | config["ui"] = {} |
| 179 | config["ui"]["open_browser_on_start"] = req.ui_open_browser_on_start |
| 180 | if req.listen_to_network is not None: |
| 181 | if "net" not in config: |
| 182 | config["net"] = {} |
| 183 | config["net"]["listen_to_network"] = bool(req.listen_to_network) |
| 184 | if req.listen_port is not None: |
| 185 | if "net" not in config: |
| 186 | config["net"] = {} |
| 187 | config["net"]["listen_port"] = int(req.listen_port) |
| 188 | |
| 189 | config["use_v3_engine"] = req.backend == "ed_diffusers" |
| 190 | config["backend"] = req.backend |
| 191 | config["models_dir"] = req.models_dir |
| 192 | config["vram_usage_level"] = req.vram_usage_level |
| 193 | |
| 194 | for property, property_value in req.dict().items(): |
| 195 | if property_value is not None and property not in req.__fields__ and property not in PROTECTED_CONFIG_KEYS: |
| 196 | config[property] = property_value |
| 197 | |
| 198 | try: |
| 199 | app.setConfig(config) |
| 200 | |
| 201 | if req.render_devices: |
| 202 | app.update_render_threads() |
| 203 | |
| 204 | return JSONResponse({"status": "OK"}, headers=NOCACHE_HEADERS) |
| 205 | except Exception as e: |
| 206 | log.error(traceback.format_exc()) |
| 207 | raise HTTPException(status_code=500, detail=str(e)) |
| 208 | |
| 209 | |
| 210 | def update_render_devices_in_config(config, render_devices): |
no test coverage detected