Admin: one image picker everywhere, with paste and drag-and-drop
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
This commit is contained in:
parent
4b50067a4a
commit
93d4863cfc
8 changed files with 200 additions and 156 deletions
|
|
@ -1,10 +1,11 @@
|
|||
export { pbUrl, createPocketBase, getFileUrl } from '$shared/pb';
|
||||
|
||||
// App-specific: admin uploads go through the admin upload endpoint.
|
||||
export async function uploadMedia(file: File) {
|
||||
// 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', file.name.replace(/\.[^/.]+$/, '').replace(/[-_]/g, ' '));
|
||||
formData.append('alt', alt);
|
||||
|
||||
const res = await fetch('/api/upload', { method: 'POST', body: formData });
|
||||
if (!res.ok) {
|
||||
|
|
@ -13,3 +14,7 @@ export async function uploadMedia(file: File) {
|
|||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export function altFromFileName(name: string) {
|
||||
return name.replace(/\.[^/.]+$/, '').replace(/[-_]/g, ' ');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue