(req: Request, res: Response)
| 45 | * @param res |
| 46 | */ |
| 47 | export async function ApiRouteInstallModel(req: Request, res: Response) { |
| 48 | try { |
| 49 | const { model, runId } = req.body; |
| 50 | |
| 51 | const modelPath = getModelPath(model.type, model.save_path, model.filename); |
| 52 | if (fs.existsSync(modelPath)) { |
| 53 | res.send({ |
| 54 | success: true, |
| 55 | status: "exist", |
| 56 | }) |
| 57 | return |
| 58 | } |
| 59 | |
| 60 | res.send({ |
| 61 | success: true, |
| 62 | status: "downloading" |
| 63 | }); |
| 64 | |
| 65 | const task: TaskProps = { |
| 66 | taskId: runId, |
| 67 | name: `download-model-${model.name}`, |
| 68 | params: model, |
| 69 | executor: async (dispatcher) => { |
| 70 | console.log('installing model', model); |
| 71 | const newDispatcher: TaskEventDispatcher = (event: PartialTaskEvent) => { |
| 72 | console.log('installing model message', event); |
| 73 | dispatcher(event); |
| 74 | let type = event.type || ModelDownloadChannelEvents.onModelDownloadProgress; |
| 75 | channelService.emit("main", { |
| 76 | type, |
| 77 | subChannel: runId, |
| 78 | payload: { |
| 79 | model, |
| 80 | ...event, |
| 81 | runId |
| 82 | } |
| 83 | }); |
| 84 | } |
| 85 | return await installModel(newDispatcher, model); |
| 86 | } |
| 87 | }; |
| 88 | taskQueue.addTask(task); |
| 89 | } catch (err) { |
| 90 | res.send({ |
| 91 | success: false, |
| 92 | error: err |
| 93 | }) |
| 94 | } |
| 95 | |
| 96 | } |
| 97 | |
| 98 | export async function ApiGetCivitaiModels(req: Request, res: Response) { |
| 99 | try { |
nothing calls this directly
no test coverage detected