(req: Request, res: Response)
| 80 | * @param res |
| 81 | */ |
| 82 | export async function ApiBootstrap(req: Request, res: Response) { |
| 83 | try { |
| 84 | const taskType = req.body.data && req.body.data.name |
| 85 | const taskId = req.body.data && req.body.data.taskId; |
| 86 | const task: TaskProps = { |
| 87 | taskId, |
| 88 | name: taskType, |
| 89 | executor: async (dispatcher): Promise<boolean> => { |
| 90 | const newDispatcher = (event: PartialTaskEvent) => { |
| 91 | dispatcher(event); |
| 92 | comfyuiService.comfyuiProgressEvent.emit({ |
| 93 | type: "OUTPUT", |
| 94 | message: event.message || "" |
| 95 | }) |
| 96 | } |
| 97 | async function withTimeout(task: Promise<any>, timeout: number, errorMessage: string): Promise<boolean> { |
| 98 | const timeoutId = setTimeout(() => { |
| 99 | newDispatcher({ type: 'TIMEOUT', message: errorMessage }); |
| 100 | }, timeout); |
| 101 | const ret = await task; |
| 102 | clearTimeout(timeoutId); |
| 103 | return ret; |
| 104 | } |
| 105 | |
| 106 | const msgTemplate = (type: string, solution = "") => `${type} operation timed out.${solution} If you can't go through this issue. Please reach out to us on Discord or refer to our FAQ for assistance. We are open to offer 1v1 support.` |
| 107 | let task: Promise<any>; |
| 108 | |
| 109 | switch (taskType) { |
| 110 | case BootStrapTaskType.installConda: |
| 111 | const isCondaInstalled = await checkIfInstalled("conda"); |
| 112 | if (isCondaInstalled) { |
| 113 | return true; |
| 114 | } |
| 115 | return await withTimeout(installCondaTask(newDispatcher), 1000 * 60 * 20, msgTemplate("Install conda", "You can directly install conda from https://docs.anaconda.com/free/miniconda/miniconda-install/. After that, restart Comflowy.")); |
| 116 | case BootStrapTaskType.installPython: |
| 117 | const isPythonInstalled = await checkIfInstalled("python"); |
| 118 | if (isPythonInstalled) { |
| 119 | return true; |
| 120 | } |
| 121 | return await withTimeout(installPythonTask(newDispatcher), 1000 * 60 * 10, msgTemplate("Create python env", "You can directly create a python env from your terminal by running `conda create -n comflowy python=3.10.8`")); |
| 122 | case BootStrapTaskType.installTorch: |
| 123 | const isTorchInstalled = await verifyIsTorchInstalled(); |
| 124 | if (isTorchInstalled) { |
| 125 | return true; |
| 126 | } |
| 127 | const command = await getInstallPyTorchForGPUCommand(); |
| 128 | newDispatcher({ message: `Install command \`${command}\`, if it takes too long, you can directly copy this command and execute it in your termnial, after that, restart Comflowyspace.`}) |
| 129 | task = installPyTorchForGPU(newDispatcher); |
| 130 | return await withTimeout(task, 1000 * 60 * 20, msgTemplate("Install torch", `You can copy the command \`${command}\` and directly execute it in your terminal. After that, restart Comflowy.`)); |
| 131 | case BootStrapTaskType.installGit: |
| 132 | const isGitInstall = await checkIfInstalled("git --version"); |
| 133 | if (isGitInstall) { |
| 134 | return true; |
| 135 | } |
| 136 | task = installCondaPackageTask(newDispatcher, { |
| 137 | packageRequirment: "git" |
| 138 | }); |
| 139 | return await withTimeout(task, 1000 * 60 * 10, msgTemplate("Install git")); |
nothing calls this directly
no test coverage detected