feat(trips): download chosen Unsplash covers into uploads (#1277)

Previously a selected Unsplash photo was stored as a remote
images.unsplash.com hot-link, so covers broke offline and on link
rot. The trip PUT handler now fetches the picked image through the
SSRF guard and saves it under uploads/covers, rewriting cover_image
to the local path (502 if the download fails). Also debounces the
cover search so a slow earlier request can no longer overwrite newer
results, drops a dead userId parameter, and reverts an unrelated
vite proxy change.
This commit is contained in:
Maurice
2026-06-28 20:06:34 +02:00
committed by Maurice
parent af90ba0911
commit f24d44b4a3
7 changed files with 89 additions and 20 deletions
@@ -34,6 +34,7 @@ interface CoverSearchPhoto {
export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUpdate }: TripFormModalProps) {
const isEditing = !!trip
const fileRef = useRef(null)
const coverSearchSeq = useRef(0)
const toast = useToast()
const { t } = useTranslation()
const currentUser = useAuthStore(s => s.user)
@@ -216,17 +217,22 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
setCoverSearchError(t('dashboard.unsplashQueryRequired'))
return
}
// Guard against out-of-order responses: only the latest search applies its
// results, so a slow earlier query can't overwrite a newer one. #1277 review
const seq = ++coverSearchSeq.current
setSearchingCover(true)
setCoverSearchError('')
try {
const data = await tripsApi.searchCoverImages(query)
if (seq !== coverSearchSeq.current) return
const photos = data.photos || []
setCoverSearchResults(photos)
if (photos.length === 0) setCoverSearchError(t('dashboard.unsplashNoResults'))
} catch (err: unknown) {
if (seq !== coverSearchSeq.current) return
setCoverSearchError(getApiErrorMessage(err, t('dashboard.coverSearchError')))
} finally {
setSearchingCover(false)
if (seq === coverSearchSeq.current) setSearchingCover(false)
}
}