fix(tools): correct toolpage archetypes across all tools and ensure robust form field mapping

This commit is contained in:
2026-11-11 17:27:23 +05:30
parent 8f4e7913fb
commit 690398f715
22 changed files with 165 additions and 55 deletions
+55 -5
View File
@@ -62,11 +62,61 @@ export async function POST(req: NextRequest, { params }: { params: { toolId: str
try {
const formData = await req.formData();
const file = formData.get('image') as File | null;
const maskFile = formData.get('mask') as File | null;
const secondaryFile = (formData.get('reference_image') as File | null) || (formData.get('image2') as File | null);
const prompt = (formData.get('prompt') as string) || (formData.get('text') as string) || '';
const style = (formData.get('style') as string) || '';
// Primary image extraction: check 'image' first, then common aliases
let file = formData.get('image') as File | null;
if (!file || typeof file === 'string') {
const candidateKeys = ['image0', 'file', 'source', 'original_image', 'source1', 'input_image'];
for (const key of candidateKeys) {
const val = formData.get(key) as File | null;
if (val && typeof val !== 'string' && val.size > 0) {
file = val;
break;
}
}
}
// Mask image extraction: check 'mask' first, then common aliases
let maskFile = formData.get('mask') as File | null;
if (!maskFile || typeof maskFile === 'string') {
const candidateMaskKeys = ['mask_image', 'mask0', 'eye_mask', 'mask_hair'];
for (const key of candidateMaskKeys) {
const val = formData.get(key) as File | null;
if (val && typeof val !== 'string' && val.size > 0) {
maskFile = val;
break;
}
}
}
// Secondary / Reference image extraction
let secondaryFile =
(formData.get('reference_image') as File | null) ||
(formData.get('reference') as File | null) ||
(formData.get('image2') as File | null) ||
(formData.get('source2') as File | null) ||
(formData.get('target') as File | null) ||
(formData.get('bg_image') as File | null) ||
(formData.get('face_segmented_image') as File | null) ||
(formData.get('secondImage') as File | null);
if (secondaryFile && typeof secondaryFile === 'string') {
secondaryFile = null;
}
const prompt =
(formData.get('prompt') as string) ||
(formData.get('text') as string) ||
(formData.get('userPrompt') as string) ||
(formData.get('custom_prompt') as string) ||
'';
const style =
(formData.get('style') as string) ||
(formData.get('effectId') as string) ||
(formData.get('colorId') as string) ||
(formData.get('effect_id') as string) ||
(formData.get('dress') as string) ||
(formData.get('expression') as string) ||
'';
const variantId = (formData.get('variant') as string) || tool.tryIt.endpointRef?.defaultVariant;
const optionsRaw = formData.get('options') as string | null;
let options: Record<string, any> = {};