feat: real file upload to /opt/hotelsync/uploads + serve via /uploads/ on API

This commit is contained in:
2026-03-23 12:23:13 +03:00
parent 5540d0cdfa
commit 3ef7f8265a
5 changed files with 94 additions and 15 deletions

View File

@@ -344,6 +344,23 @@ export const api = {
req<void>('DELETE', `/api/hotels/${slug}/rental-bookings/${id}`),
},
// ── File Upload ───────────────────────────────────────────────────────────
upload: {
photo: async (file: File): Promise<string> => {
const token = localStorage.getItem('access_token')
const fd = new FormData()
fd.append('file', file)
const res = await fetch(`${BASE}/api/upload`, {
method: 'POST',
headers: token ? { Authorization: `Bearer ${token}` } : {},
body: fd,
})
if (!res.ok) throw new Error(`Upload failed: ${res.statusText}`)
const data = await res.json() as { url: string }
return data.url
},
},
// ── Categories ────────────────────────────────────────────────────────────
categories: {
list: (slug: string) =>