ComfyUI-Manager/js/cm-api.js
Dr.Lt.Data aaed1dc3d5
feat(security): Support System User Protection API with security migration (V3.38) (#2338)
- Migrate Manager data path: default/ComfyUI-Manager → __manager
- Force security_level=strong on outdated ComfyUI (block installations)
- Auto-migrate config.ini only; backup legacy files for manual verification
- Raise weak/normal- to normal during migration
- Add /manager/startup_alerts API for UI warnings
- Differentiate 403 responses: comfyui_outdated vs security_level
- Block startup scripts execution on old ComfyUI

Requires ComfyUI v0.3.76+ for full functionality.
Backward compatible with older versions (uses legacy path).
2025-12-03 00:42:12 +09:00

68 lines
2.1 KiB
JavaScript

import { api } from "../../scripts/api.js";
import { app } from "../../scripts/app.js";
import { sleep, customConfirm, customAlert, handle403Response, show_message } 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.target.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') {
customAlert(msg);
return;
}
const res = await customConfirm(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)
});
if(response.status == 403) {
await handle403Response(response);
return false;
}
else if(response.status == 400) {
let msg = await res.text();
show_message(msg);
return false;
}
}
let response = await api.fetchApi("/manager/reboot");
if(response.status == 403) {
await handle403Response(response);
return false;
}
await sleep(300);
app.ui.dialog.show(`Rebooting...`);
}
}
api.addEventListener("cm-api-try-install-customnode", tryInstallCustomNode);