fix image upload

visual improvements
This commit is contained in:
Jakub Dorfman 2026-05-19 17:11:52 +02:00
parent 94c1e0b679
commit fe5d77443d
7 changed files with 134 additions and 24 deletions

View file

@ -28,9 +28,10 @@ export async function uploadMedia(file: File) {
formData.append('file', file);
formData.append('alt', file.name.replace(/\.[^/.]+$/, '').replace(/[-_]/g, ' '));
const record = await pb.collection('media').create(formData);
return {
record,
url: getFileUrl(record.collectionId, record.id, record.file)
};
const res = await fetch('/admin/api/upload', { method: 'POST', body: formData });
if (!res.ok) {
const err = await res.json().catch(() => ({}));
throw new Error(err?.message || `Upload failed (${res.status})`);
}
return res.json();
}