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

Function ApiRouteInstallExtension

apps/node/src/routes/api/extension.ts:16–80  ·  view source on GitHub ↗
(req: Request, res: Response)

Source from the content-addressed store, hash-verified

14 * @param res
15 */
16export async function ApiRouteInstallExtension(req: Request, res: Response) {
17 try {
18 const {data} = req.body;
19 const taskParams = data as TaskProps;
20 const task: TaskProps = {
21 taskId: taskParams.taskId,
22 name: taskParams.name,
23 params: taskParams.params,
24 executor: async (dispatcher: TaskEventDispatcher) => {
25 const newDispatcher = (event: PartialTaskEvent) => {
26 dispatcher(event);
27 comfyuiService.comfyuiProgressEvent.emit({
28 type: "OUTPUT",
29 message: event.message || event.error
30 })
31 }
32 const extensions = taskParams.params as Extension[];
33 let updated = false;
34
35 newDispatcher({
36 message: `\n Start to install ${extensions.map(e => e.title).join(", ")}\n`
37 });
38
39 for (const extension of extensions) {
40 await checkAExtensionInstalled(extension)
41 if (extension.installed) {
42 newDispatcher({
43 message: `\nExtension ${extension.title} installed`
44 });
45 continue;
46 }
47 const ret = await installExtension(newDispatcher, extension);
48 if (ret) {
49 updated = true
50 } else {
51 newDispatcher({
52 error: `\nExtension ${extension.title} install failed`
53 });
54 }
55 }
56
57 if (updated) {
58 await comfyuiService.restartComfyUI();
59 return true;
60 }
61
62 return false;
63 }
64 };
65 taskQueue.addTask(task);
66 res.send({
67 success: true,
68 data: {
69 taskId: task.taskId
70 }
71 });
72 } catch (err: any) {
73 logger.error("error", err);

Callers

nothing calls this directly

Calls 5

checkAExtensionInstalledFunction · 0.90
installExtensionFunction · 0.90
restartComfyUIMethod · 0.80
addTaskMethod · 0.80
newDispatcherFunction · 0.70

Tested by

no test coverage detected