Fix getting VAEs for SD forge

ad19a800ce72bdf64724daa3b5cc4f55d07f38c0

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +11 -7Showing whitespace changes
src/endpoints/stable-diffusion.js+11 -7
@@ -105,22 +105,26 @@ router.post('/upscalers', jsonParser, async (request, response) => {
105105
106106router.post('/vaes', jsonParser, async (request, response) => {
107107 try {
108108 const urlautoUrl = new URLurlJoin(request.body.url, '/sdapi/v1/sd-vae');
109109 url.pathnameconst forgeUrl = urlJoin(request.body.url, '/sdapi/v1/sd-vaemodules');
110110
111111 const resultrequestInit = await fetch(url, {
112112 method: 'GET',
113113 headers: {
114114 'Authorization': getBasicAuthHeader(request.body.auth),
115115 },
116116 });
117+ const results = await Promise.allSettled([
118+ fetch(autoUrl, requestInit).then(r => r.ok ? r.json() : Promise.reject(r.statusText)),
119+ fetch(forgeUrl, requestInit).then(r => r.ok ? r.json() : Promise.reject(r.statusText)),
120+ ]);
117121
118- if (!result.ok) {
122+ const data = results.find(r => r.status === 'fulfilled')?.value;
123+
124+ if (!Array.isArray(data)) {
119125 throw new Error('SD WebUI returned an error.');
120126 }
121127
122- /** @type {any} */
123- const data = await result.json();
124128 const names = data.map(x => x.model_name);
125129 return response.send(names);
126130 } catch (error) {