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

Function ApiRouteInstallModel

apps/node/src/routes/api/models.ts:47–96  ·  view source on GitHub ↗
(req: Request, res: Response)

Source from the content-addressed store, hash-verified

45 * @param res
46 */
47export 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
98export async function ApiGetCivitaiModels(req: Request, res: Response) {
99 try {

Callers

nothing calls this directly

Calls 4

getModelPathFunction · 0.90
installModelFunction · 0.90
logMethod · 0.80
addTaskMethod · 0.80

Tested by

no test coverage detected