diff --git a/src/endpoints/stable-diffusion.js b/src/endpoints/stable-diffusion.js
index 1054d2d6b..e2168cd80 100644
--- a/src/endpoints/stable-diffusion.js
+++ b/src/endpoints/stable-diffusion.js
@@ -638,7 +638,80 @@ together.post('/generate', jsonParser, async (request, response) => {
}
});
+const drawthings = express.Router();
+
+drawthings.post('/ping', jsonParser, async (request, response) => {
+ try {
+ const url = new URL(request.body.url);
+ url.pathname = '/';
+
+ const result = await fetch(url, {
+ method: 'HEAD',
+ });
+
+ if (!result.ok) {
+ throw new Error('SD DrawThings API returned an error.');
+ }
+
+ return response.sendStatus(200);
+ } catch (error) {
+ console.log(error);
+ return response.sendStatus(500);
+ }
+});
+
+drawthings.post('/get-model', jsonParser, async (request, response) => {
+ try {
+ const url = new URL(request.body.url);
+ url.pathname = '/';
+
+ const result = await fetch(url, {
+ method: 'GET',
+ });
+ const data = await result.json();
+
+ return response.send(data['model']);
+ } catch (error) {
+ console.log(error);
+ return response.sendStatus(500);
+ }
+});
+
+drawthings.post('/generate', jsonParser, async (request, response) => {
+ try {
+ console.log('SD DrawThings API request:', request.body);
+
+ const url = new URL(request.body.url);
+ url.pathname = '/sdapi/v1/txt2img';
+
+ const body = {...request.body};
+ delete body.url;
+
+ const result = await fetch(url, {
+ method: 'POST',
+ body: JSON.stringify(body),
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': getBasicAuthHeader(request.body.auth),
+ },
+ timeout: 0,
+ });
+
+ if (!result.ok) {
+ const text = await result.text();
+ throw new Error('SD DrawThings API returned an error.', { cause: text });
+ }
+
+ const data = await result.json();
+ return response.send(data);
+ } catch (error) {
+ console.log(error);
+ return response.sendStatus(500);
+ }
+});
+
router.use('/comfy', comfy);
router.use('/together', together);
+router.use('/drawthings', drawthings);
module.exports = { router };
From 652987ae0195a644aed055c5cd5a2df2d4e95ddd Mon Sep 17 00:00:00 2001
From: Cohee <18619528+Cohee1207@users.noreply.github.com>
Date: Sat, 30 Mar 2024 14:23:50 +0200
Subject: [PATCH 7/7] Add missing auth header
---
public/scripts/extensions/stable-diffusion/index.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/public/scripts/extensions/stable-diffusion/index.js b/public/scripts/extensions/stable-diffusion/index.js
index 7fd51ddc5..5f1a561c9 100644
--- a/public/scripts/extensions/stable-diffusion/index.js
+++ b/public/scripts/extensions/stable-diffusion/index.js
@@ -317,7 +317,7 @@ function getSdRequestBody() {
case sources.auto:
return { url: extension_settings.sd.auto_url, auth: extension_settings.sd.auto_auth };
case sources.drawthings:
- return { url: extension_settings.sd.drawthings_url };
+ return { url: extension_settings.sd.drawthings_url, auth: extension_settings.sd.drawthings_auth };
default:
throw new Error('Invalid SD source.');
}