fred-dev/comfy_ui_ali
0
1import { api } from "../../scripts/api.js";2import { app } from "../../scripts/app.js";3import { sleep, customConfirm, customAlert } from "./common.js";4 5async function tryInstallCustomNode(event) {6 let msg = '-= [ComfyUI Manager] extension installation request =-\n\n';7 msg += `The '${event.detail.sender}' extension requires the installation of the '${event.detail.target.title}' extension. `;8 9 if(event.detail.target.installed == 'Disabled') {10 msg += 'However, the extension is currently disabled. Would you like to enable it and reboot?'11 }12 else if(event.detail.target.installed == 'True') {13 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.';14 }15 else {16 msg += `Would you like to install it and reboot?`;17 }18 19 msg += `\n\nRequest message:\n${event.detail.msg}`;20 21 if(event.detail.target.installed == 'True') {22 customAlert(msg);23 return;24 }25 const res = await customConfirm(msg);26 if(res) {27 if(event.detail.target.installed == 'Disabled') {28 const response = await api.fetchApi(`/customnode/toggle_active`, {29 method: 'POST',30 headers: { 'Content-Type': 'application/json' },31 body: JSON.stringify(event.detail.target)32 });33 }34 else {35 await sleep(300);36 app.ui.dialog.show(`Installing... '${event.detail.target.title}'`);37 38 const response = await api.fetchApi(`/customnode/install`, {39 method: 'POST',40 headers: { 'Content-Type': 'application/json' },41 body: JSON.stringify(event.detail.target)42 });43 44 if(response.status == 403) {45 show_message('This action is not allowed with this security level configuration.');46 return false;47 }48 else if(response.status == 400) {49 let msg = await res.text();50 show_message(msg);51 return false;52 }53 }54 55 let response = await api.fetchApi("/manager/reboot");56 if(response.status == 403) {57 show_message('This action is not allowed with this security level configuration.');58 return false;59 }60 61 await sleep(300);62 63 app.ui.dialog.show(`Rebooting...`);64 }65}66 67api.addEventListener("cm-api-try-install-customnode", tryInstallCustomNode);68 