MCPcopy Create free account
hub / github.com/6174/comflowyspace / ApiBootstrap

Function ApiBootstrap

apps/node/src/routes/api/bootstrap.ts:82–196  ·  view source on GitHub ↗
(req: Request, res: Response)

Source from the content-addressed store, hash-verified

80 * @param res
81 */
82export 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"));

Callers

nothing calls this directly

Calls 15

checkIfInstalledFunction · 0.90
installCondaTaskFunction · 0.90
installPythonTaskFunction · 0.90
verifyIsTorchInstalledFunction · 0.90
installPyTorchForGPUFunction · 0.90
installCondaPackageTaskFunction · 0.90
checkIfInstalledComfyUIFunction · 0.90
cloneComfyUIFunction · 0.90
withTimeoutFunction · 0.85
msgTemplateFunction · 0.85
isComfyUIAliveMethod · 0.80

Tested by

no test coverage detected