mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Fix ComfyUI generation for non-relative paths
This commit is contained in:
10
package-lock.json
generated
10
package-lock.json
generated
@ -65,6 +65,7 @@
|
|||||||
"simple-git": "^3.19.1",
|
"simple-git": "^3.19.1",
|
||||||
"slidetoggle": "^4.0.0",
|
"slidetoggle": "^4.0.0",
|
||||||
"tiktoken": "^1.0.16",
|
"tiktoken": "^1.0.16",
|
||||||
|
"url-join": "^5.0.0",
|
||||||
"vectra": "^0.2.2",
|
"vectra": "^0.2.2",
|
||||||
"wavefile": "^11.0.0",
|
"wavefile": "^11.0.0",
|
||||||
"webpack": "^5.95.0",
|
"webpack": "^5.95.0",
|
||||||
@ -7053,6 +7054,15 @@
|
|||||||
"punycode": "^2.1.0"
|
"punycode": "^2.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/url-join": {
|
||||||
|
"version": "5.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/url-join/-/url-join-5.0.0.tgz",
|
||||||
|
"integrity": "sha512-n2huDr9h9yzd6exQVnH/jU5mr+Pfx08LRXXZhkLLetAMESRj+anQsTAh940iMrIetKAmry9coFuZQ2jY8/p3WA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/utf8-byte-length": {
|
"node_modules/utf8-byte-length": {
|
||||||
"version": "1.0.4",
|
"version": "1.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz",
|
||||||
|
@ -55,6 +55,7 @@
|
|||||||
"simple-git": "^3.19.1",
|
"simple-git": "^3.19.1",
|
||||||
"slidetoggle": "^4.0.0",
|
"slidetoggle": "^4.0.0",
|
||||||
"tiktoken": "^1.0.16",
|
"tiktoken": "^1.0.16",
|
||||||
|
"url-join": "^5.0.0",
|
||||||
"vectra": "^0.2.2",
|
"vectra": "^0.2.2",
|
||||||
"wavefile": "^11.0.0",
|
"wavefile": "^11.0.0",
|
||||||
"webpack": "^5.95.0",
|
"webpack": "^5.95.0",
|
||||||
|
@ -1112,7 +1112,7 @@ function onHrSecondPassStepsInput() {
|
|||||||
|
|
||||||
function onComfyUrlInput() {
|
function onComfyUrlInput() {
|
||||||
// Remove trailing slashes
|
// Remove trailing slashes
|
||||||
extension_settings.sd.comfy_url = String($('#sd_comfy_url').val() ?? '').replace(/\/$/, '');
|
extension_settings.sd.comfy_url = String($('#sd_comfy_url').val());
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import fetch from 'node-fetch';
|
|||||||
import sanitize from 'sanitize-filename';
|
import sanitize from 'sanitize-filename';
|
||||||
import { sync as writeFileAtomicSync } from 'write-file-atomic';
|
import { sync as writeFileAtomicSync } from 'write-file-atomic';
|
||||||
import FormData from 'form-data';
|
import FormData from 'form-data';
|
||||||
|
import urlJoin from 'url-join';
|
||||||
|
|
||||||
import { delay, getBasicAuthHeader, tryParse } from '../util.js';
|
import { delay, getBasicAuthHeader, tryParse } from '../util.js';
|
||||||
import { jsonParser } from '../express-common.js';
|
import { jsonParser } from '../express-common.js';
|
||||||
@ -364,8 +365,7 @@ const comfy = express.Router();
|
|||||||
|
|
||||||
comfy.post('/ping', jsonParser, async (request, response) => {
|
comfy.post('/ping', jsonParser, async (request, response) => {
|
||||||
try {
|
try {
|
||||||
const url = new URL(request.body.url);
|
const url = new URL(urlJoin(request.body.url, '/system_stats'));
|
||||||
url.pathname += '/system_stats';
|
|
||||||
|
|
||||||
const result = await fetch(url);
|
const result = await fetch(url);
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
@ -381,8 +381,7 @@ comfy.post('/ping', jsonParser, async (request, response) => {
|
|||||||
|
|
||||||
comfy.post('/samplers', jsonParser, async (request, response) => {
|
comfy.post('/samplers', jsonParser, async (request, response) => {
|
||||||
try {
|
try {
|
||||||
const url = new URL(request.body.url);
|
const url = new URL(urlJoin(request.body.url, '/object_info'));
|
||||||
url.pathname += '/object_info';
|
|
||||||
|
|
||||||
const result = await fetch(url);
|
const result = await fetch(url);
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
@ -400,8 +399,7 @@ comfy.post('/samplers', jsonParser, async (request, response) => {
|
|||||||
|
|
||||||
comfy.post('/models', jsonParser, async (request, response) => {
|
comfy.post('/models', jsonParser, async (request, response) => {
|
||||||
try {
|
try {
|
||||||
const url = new URL(request.body.url);
|
const url = new URL(urlJoin(request.body.url, '/object_info'));
|
||||||
url.pathname += '/object_info';
|
|
||||||
|
|
||||||
const result = await fetch(url);
|
const result = await fetch(url);
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
@ -429,8 +427,7 @@ comfy.post('/models', jsonParser, async (request, response) => {
|
|||||||
|
|
||||||
comfy.post('/schedulers', jsonParser, async (request, response) => {
|
comfy.post('/schedulers', jsonParser, async (request, response) => {
|
||||||
try {
|
try {
|
||||||
const url = new URL(request.body.url);
|
const url = new URL(urlJoin(request.body.url, '/object_info'));
|
||||||
url.pathname += '/object_info';
|
|
||||||
|
|
||||||
const result = await fetch(url);
|
const result = await fetch(url);
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
@ -448,8 +445,7 @@ comfy.post('/schedulers', jsonParser, async (request, response) => {
|
|||||||
|
|
||||||
comfy.post('/vaes', jsonParser, async (request, response) => {
|
comfy.post('/vaes', jsonParser, async (request, response) => {
|
||||||
try {
|
try {
|
||||||
const url = new URL(request.body.url);
|
const url = new URL(urlJoin(request.body.url, '/object_info'));
|
||||||
url.pathname += '/object_info';
|
|
||||||
|
|
||||||
const result = await fetch(url);
|
const result = await fetch(url);
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
@ -516,15 +512,13 @@ comfy.post('/delete-workflow', jsonParser, async (request, response) => {
|
|||||||
|
|
||||||
comfy.post('/generate', jsonParser, async (request, response) => {
|
comfy.post('/generate', jsonParser, async (request, response) => {
|
||||||
try {
|
try {
|
||||||
const url = new URL(request.body.url);
|
const url = new URL(urlJoin(request.body.url, '/prompt'));
|
||||||
url.pathname += '/prompt';
|
|
||||||
|
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
request.socket.removeAllListeners('close');
|
request.socket.removeAllListeners('close');
|
||||||
request.socket.on('close', function () {
|
request.socket.on('close', function () {
|
||||||
if (!response.writableEnded && !item) {
|
if (!response.writableEnded && !item) {
|
||||||
const interruptUrl = new URL(request.body.url);
|
const interruptUrl = new URL(urlJoin(request.body.url, '/interrupt'));
|
||||||
interruptUrl.pathname += '/interrupt';
|
|
||||||
fetch(interruptUrl, { method: 'POST', headers: { 'Authorization': getBasicAuthHeader(request.body.auth) } });
|
fetch(interruptUrl, { method: 'POST', headers: { 'Authorization': getBasicAuthHeader(request.body.auth) } });
|
||||||
}
|
}
|
||||||
controller.abort();
|
controller.abort();
|
||||||
@ -543,8 +537,7 @@ comfy.post('/generate', jsonParser, async (request, response) => {
|
|||||||
const data = await promptResult.json();
|
const data = await promptResult.json();
|
||||||
const id = data.prompt_id;
|
const id = data.prompt_id;
|
||||||
let item;
|
let item;
|
||||||
const historyUrl = new URL(request.body.url);
|
const historyUrl = new URL(urlJoin(request.body.url, '/history'));
|
||||||
historyUrl.pathname += '/history';
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const result = await fetch(historyUrl);
|
const result = await fetch(historyUrl);
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
@ -568,8 +561,7 @@ comfy.post('/generate', jsonParser, async (request, response) => {
|
|||||||
throw new Error(`ComfyUI generation did not succeed.\n\n${errorMessages}`.trim());
|
throw new Error(`ComfyUI generation did not succeed.\n\n${errorMessages}`.trim());
|
||||||
}
|
}
|
||||||
const imgInfo = Object.keys(item.outputs).map(it => item.outputs[it].images).flat()[0];
|
const imgInfo = Object.keys(item.outputs).map(it => item.outputs[it].images).flat()[0];
|
||||||
const imgUrl = new URL(request.body.url);
|
const imgUrl = new URL(urlJoin(request.body.url, '/view'));
|
||||||
imgUrl.pathname += '/view';
|
|
||||||
imgUrl.search = `?filename=${imgInfo.filename}&subfolder=${imgInfo.subfolder}&type=${imgInfo.type}`;
|
imgUrl.search = `?filename=${imgInfo.filename}&subfolder=${imgInfo.subfolder}&type=${imgInfo.type}`;
|
||||||
const imgResponse = await fetch(imgUrl);
|
const imgResponse = await fetch(imgUrl);
|
||||||
if (!imgResponse.ok) {
|
if (!imgResponse.ok) {
|
||||||
|
Reference in New Issue
Block a user