feat: add admin image workflow
Quality / test (push) Canceled after 0s

This commit is contained in:
2026-09-08 22:13:47 -04:00
parent efeca42d0f
commit c382852924
3 changed files with 151 additions and 0 deletions
@@ -0,0 +1,56 @@
const apiBaseUrl = import.meta.env?.VITE_API_BASE_URL ?? '/api/v1';
async function request(path, options = {}) {
const response = await fetch(`${apiBaseUrl}${path}`, {
credentials: 'include',
...options,
headers: {
'content-type': 'application/json',
...options.headers,
},
});
if (!response.ok) {
const payload = await response.json().catch(() => null);
throw new Error(payload?.error?.message ?? 'Image update is unavailable.');
}
return response.status === 204 ? null : (await response.json()).data;
}
export function reorderImage(imageId, sortOrder, csrfToken) {
return request(`/admin/images/${encodeURIComponent(imageId)}/order`, {
method: 'PATCH',
headers: { 'x-csrf-token': csrfToken },
body: JSON.stringify({ sortOrder }),
});
}
export function setPrimaryImage(imageId, csrfToken) {
return request(`/admin/images/${encodeURIComponent(imageId)}/primary`, {
method: 'POST',
headers: { 'x-csrf-token': csrfToken },
});
}
export function updateImageAltText(imageId, altText, csrfToken) {
return request(`/admin/images/${encodeURIComponent(imageId)}/alt-text`, {
method: 'PATCH',
headers: { 'x-csrf-token': csrfToken },
body: JSON.stringify({ altText }),
});
}
export function retryImageProcessing(imageId, csrfToken) {
return request(`/admin/images/${encodeURIComponent(imageId)}/retry`, {
method: 'POST',
headers: { 'x-csrf-token': csrfToken },
});
}
export function deleteImage(imageId, csrfToken) {
return request(`/admin/images/${encodeURIComponent(imageId)}`, {
method: 'DELETE',
headers: { 'x-csrf-token': csrfToken },
});
}