feat(v1): add basic backend and frontend
This commit is contained in:
42
frontend/src/lib/api.js
Normal file
42
frontend/src/lib/api.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const API_BASE = import.meta.env.VITE_API_BASE || "";
|
||||
|
||||
async function parseResponse(response) {
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
throw new Error(payload.detail || "Request failed");
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
|
||||
export async function uploadImage(file) {
|
||||
const body = new FormData();
|
||||
body.append("image", file);
|
||||
const response = await fetch(`${API_BASE}/api/images/`, {
|
||||
method: "POST",
|
||||
body
|
||||
});
|
||||
return parseResponse(response);
|
||||
}
|
||||
|
||||
export async function processImage(sessionId, operation, params) {
|
||||
const response = await fetch(`${API_BASE}/api/process/`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ session_id: sessionId, operation, params })
|
||||
});
|
||||
return parseResponse(response);
|
||||
}
|
||||
|
||||
export async function createBatch(operation, sessionIds, params = {}) {
|
||||
const response = await fetch(`${API_BASE}/api/batch/`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ operation, session_ids: sessionIds, params })
|
||||
});
|
||||
return parseResponse(response);
|
||||
}
|
||||
|
||||
export async function getJob(jobId) {
|
||||
const response = await fetch(`${API_BASE}/api/jobs/${jobId}/`);
|
||||
return parseResponse(response);
|
||||
}
|
||||
Reference in New Issue
Block a user