fix: revert to server proxy logic and add resilient fallback for win32 to prevent 500 errors
This commit is contained in:
+18
-4
@@ -2473,9 +2473,7 @@ app.post('/api/tts/generate', express.json(), async (req, res) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
let proxyUrl = process.env.HTTP_PROXY || process.env.http_proxy || process.env.HTTPS_PROXY || process.env.https_proxy || process.env.ALL_PROXY || process.env.all_proxy;
|
let proxyUrl = process.env.HTTP_PROXY || process.env.http_proxy || process.env.HTTPS_PROXY || process.env.https_proxy || process.env.ALL_PROXY || process.env.all_proxy;
|
||||||
if (!proxyUrl && os.platform() === 'win32') {
|
|
||||||
proxyUrl = 'http://127.0.0.1:7890';
|
|
||||||
}
|
|
||||||
console.log(`[TTS] Sending request for text: "${text}" with model "${model}"${proxyUrl ? ` via proxy: ${proxyUrl}` : ''}`);
|
console.log(`[TTS] Sending request for text: "${text}" with model "${model}"${proxyUrl ? ` via proxy: ${proxyUrl}` : ''}`);
|
||||||
|
|
||||||
const requestBody = JSON.stringify({
|
const requestBody = JSON.stringify({
|
||||||
@@ -2495,9 +2493,25 @@ app.post('/api/tts/generate', express.json(), async (req, res) => {
|
|||||||
body: requestBody
|
body: requestBody
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = proxyUrl
|
// Always try to use local proxy first if we are on a Windows machine
|
||||||
|
if (!proxyUrl && os.platform() === 'win32') {
|
||||||
|
proxyUrl = 'http://127.0.0.1:7890';
|
||||||
|
}
|
||||||
|
|
||||||
|
let response;
|
||||||
|
try {
|
||||||
|
response = proxyUrl
|
||||||
? await requestViaProxy('https://fishaudio.fse-media.group/v1/tts', options, proxyUrl)
|
? await requestViaProxy('https://fishaudio.fse-media.group/v1/tts', options, proxyUrl)
|
||||||
: await requestDirect('https://fishaudio.fse-media.group/v1/tts', options);
|
: await requestDirect('https://fishaudio.fse-media.group/v1/tts', options);
|
||||||
|
} catch (e) {
|
||||||
|
// Fallback for Windows if local proxy fails
|
||||||
|
if (os.platform() === 'win32' && proxyUrl === 'http://127.0.0.1:7890') {
|
||||||
|
console.log(`[TTS] Local proxy failed, attempting direct connection...`);
|
||||||
|
response = await requestDirect('https://fishaudio.fse-media.group/v1/tts', options);
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const msg = (response.text && String(response.text).trim().length > 0)
|
const msg = (response.text && String(response.text).trim().length > 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user