feat: Add layer-wise texture editing using Gemini AI
Build and Deploy / build-and-push (push) Failing after 54s

This commit is contained in:
AI Bot
2026-09-17 09:56:37 +05:30
parent 6e182cf4ac
commit c4253022db
3 changed files with 170 additions and 292 deletions
+30
View File
@@ -79,3 +79,33 @@ export async function pollStatus<T>(
throw new Error("Polling timeout exceeded.");
}
export async function editUVLayer(prompt: string, imageBase64: string, token: string): Promise<string> {
// Extract mime type if present in the data URI
let mimeType = 'image/png';
if (imageBase64.startsWith('data:')) {
const match = imageBase64.match(/^data:([^;]+);/);
if (match) {
mimeType = match[1];
}
}
const response = await fetch('/api/sparkplug/edit-layer', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({ prompt, imageBase64, mimeType })
});
if (!response.ok) {
const errorData = await response.json().catch(() => ({}));
throw new Error(errorData.error || `HTTP error! status: ${response.status}`);
}
const data = await response.json();
if (data.error) throw new Error(data.error);
return data.imageUrl;
}