| 105 | | 105 | |
| 106 | router.post('/vaes', jsonParser, async (request, response) => { | 106 | router.post('/vaes', jsonParser, async (request, response) => { |
| 107 | try { | 107 | try { |
| 108 | const url = new URL(request.body.url); | 108 | const autoUrl = urlJoin(request.body.url, '/sdapi/v1/sd-vae'); |
| 109 | url.pathname = '/sdapi/v1/sd-vae'; | 109 | const forgeUrl = urlJoin(request.body.url, '/sdapi/v1/sd-modules'); |
| 110 | | 110 | |
| 111 | const result = await fetch(url, { | 111 | const requestInit = { |
| 112 | method: 'GET', | 112 | method: 'GET', |
| 113 | headers: { | 113 | headers: { |
| 114 | 'Authorization': getBasicAuthHeader(request.body.auth), | 114 | 'Authorization': getBasicAuthHeader(request.body.auth), |
| 115 | }, | 115 | }, |
| 116 | }); | 116 | }; |
| | 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 | ]); |
| 117 | | 121 | |
| 118 | if (!result.ok) { | 122 | const data = results.find(r => r.status === 'fulfilled')?.value; |
| | 123 | |
| | 124 | if (!Array.isArray(data)) { |
| 119 | throw new Error('SD WebUI returned an error.'); | 125 | throw new Error('SD WebUI returned an error.'); |
| 120 | } | 126 | } |
| 121 | | 127 | |
| 122 | /** @type {any} */ | | |
| 123 | const data = await result.json(); | | |
| 124 | const names = data.map(x => x.model_name); | 128 | const names = data.map(x => x.model_name); |
| 125 | return response.send(names); | 129 | return response.send(names); |
| 126 | } catch (error) { | 130 | } catch (error) { |