feat: Add layer-wise texture editing using Gemini AI
Build and Deploy / build-and-push (push) Failing after 54s
Build and Deploy / build-and-push (push) Failing after 54s
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user