ImageUploader becomes ImagePicker and replaces the separate image field on Services & products, so every image (blocks, card images, block backgrounds, emails, the logo, services) is picked the same way. Besides choosing a file it takes an image dragged onto the box or pasted (Ctrl+V while the picker has focus, or the Paste button where the browser allows reading the clipboard). Pasted images get a dated file name and no alt text made from "image.png"; files the media collection won't take are refused with a message before uploading. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
20 lines
758 B
TypeScript
20 lines
758 B
TypeScript
export { pbUrl, createPocketBase, getFileUrl } from '$shared/pb';
|
|
|
|
// App-specific: admin uploads go through the admin upload endpoint.
|
|
// Without an alt text, the media record gets one made from the file name.
|
|
export async function uploadMedia(file: File, alt = altFromFileName(file.name)) {
|
|
const formData = new FormData();
|
|
formData.append('file', file);
|
|
formData.append('alt', alt);
|
|
|
|
const res = await fetch('/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();
|
|
}
|
|
|
|
export function altFromFileName(name: string) {
|
|
return name.replace(/\.[^/.]+$/, '').replace(/[-_]/g, ' ');
|
|
}
|