feat: remove Tools dropdown and redirect inference requests to local Golang backend on http://0.0.0.0:7777
This commit is contained in:
@@ -83,8 +83,8 @@ export async function executeBackendTryIt(
|
||||
}
|
||||
}
|
||||
|
||||
// Allow overriding base host via env (e.g. if running FastAPI on localhost:6666)
|
||||
const envBackendUrl = process.env.API_BACKEND_URL;
|
||||
// Allow overriding base host via env (default to local Golang backend server at http://0.0.0.0:7777)
|
||||
const envBackendUrl = process.env.API_BACKEND_URL || 'http://0.0.0.0:7777';
|
||||
if (envBackendUrl) {
|
||||
try {
|
||||
const parsed = new URL(targetUrl);
|
||||
@@ -101,10 +101,10 @@ export async function executeBackendTryIt(
|
||||
const formData = new FormData();
|
||||
const blob = new Blob([new Uint8Array(imageBuffer)]);
|
||||
|
||||
// Find primary file parameter name (e.g. 'image', 'image0', 'original_image')
|
||||
// Find primary file parameter name (e.g. 'image0', 'image', 'original_image')
|
||||
const fileParam = endpoint.params.find(
|
||||
(p) => p.kind === 'file' && !p.name.toLowerCase().includes('mask') && !p.name.toLowerCase().includes('ref')
|
||||
) || { name: 'image' };
|
||||
) || { name: 'image0' };
|
||||
formData.append(fileParam.name, blob, filename);
|
||||
|
||||
// If mask buffer provided (Inpainting / Custom Mask / Auto Mask)
|
||||
@@ -172,10 +172,28 @@ export async function executeBackendTryIt(
|
||||
return await generateMockNeuralResult(imageBuffer, toolId, variantId);
|
||||
}
|
||||
|
||||
const contentType = response.headers.get('content-type') || endpoint.responseType || 'image/jpeg';
|
||||
const arrayBuf = await response.arrayBuffer();
|
||||
const resultBuffer = Buffer.from(arrayBuf);
|
||||
|
||||
// Validate if the response is actually an image or a JSON error
|
||||
const sig = checkFileSignature(resultBuffer);
|
||||
if (!sig.valid) {
|
||||
try {
|
||||
const textPayload = resultBuffer.toString('utf8');
|
||||
if (textPayload.startsWith('{') || textPayload.startsWith('[')) {
|
||||
const jsonResp = JSON.parse(textPayload);
|
||||
console.warn(`[Backend API] Non-image payload from ${targetUrl}:`, jsonResp);
|
||||
if (jsonResp.error || jsonResp.message || jsonResp.status === false || jsonResp.status === 'error') {
|
||||
return await generateMockNeuralResult(imageBuffer, toolId, variantId);
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Fallback
|
||||
}
|
||||
}
|
||||
|
||||
const contentType = sig.valid && sig.mime ? sig.mime : (response.headers.get('content-type') || endpoint.responseType || 'image/jpeg');
|
||||
|
||||
recordEndpointSuccess(endpoint.id);
|
||||
return {
|
||||
buffer: resultBuffer,
|
||||
|
||||
Reference in New Issue
Block a user