feat: custom node install api

This commit is contained in:
Dr.Lt.Data
2023-12-23 16:16:11 +09:00
parent ef1632d21d
commit 60386b569e
5 changed files with 106 additions and 2 deletions

54
js/cm-api.js Normal file
View File

@@ -0,0 +1,54 @@
import { api } from "../../scripts/api.js";
import { app } from "../../scripts/app.js";
import { sleep } from "./common.js";
async function tryInstallCustomNode(event) {
let msg = '-= [ComfyUI Manager] extension installation request =-\n\n';
msg += `The '${event.detail.sender}' extension requires the installation of the '${event.detail.title}' extension. `;
if(event.detail.target.installed == 'Disabled') {
msg += 'However, the extension is currently disabled. Would you like to enable it and reboot?'
}
else if(event.detail.target.installed == 'True') {
msg += 'However, it seems that the extension is in an import-fail state or is not compatible with the current version. Please address this issue.';
}
else {
msg += `Would you like to install it and reboot?`;
}
msg += `\n\nRequest message:\n${event.detail.msg}`;
if(event.detail.target.installed == 'True') {
alert(msg);
return;
}
let res = confirm(msg);
if(res) {
if(event.detail.target.installed == 'Disabled') {
const response = await api.fetchApi(`/customnode/toggle_active`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(event.detail.target)
});
}
else {
await sleep(300);
app.ui.dialog.show(`Installing... '${event.detail.target.title}'`);
const response = await api.fetchApi(`/customnode/install`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(event.detail.target)
});
}
api.fetchApi("/manager/reboot");
await sleep(300);
app.ui.dialog.show(`Rebooting...`);
}
}
api.addEventListener("cm-api-try-install-customnode", tryInstallCustomNode);

View File

@@ -1,5 +1,5 @@
import { app } from "../../scripts/app.js";
import { api } from "../../scripts/api.js"
import { api } from "../../scripts/api.js";
import { ComfyDialog, $el } from "../../scripts/ui.js";
import { OpenArtShareDialog } from "./comfyui-share-openart.js";

View File

@@ -1,6 +1,10 @@
import { app } from "../../scripts/app.js";
import { api } from "../../scripts/api.js"
export async function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export function rebootAPI() {
if (confirm("Are you sure you'd like to reboot the server?")) {
try {