Improve guest photo downloads with preview/original variants
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-02-07 14:31:48 +01:00
parent 3ba4d11d92
commit ddbfa38db1
7 changed files with 356 additions and 14 deletions

View File

@@ -22,6 +22,8 @@ import { GUEST_AI_MAGIC_EDITS_ENABLED } from '../lib/featureFlags';
type LightboxPhoto = {
id: number;
imageUrl: string;
fullUrl?: string | null;
downloadUrl?: string | null;
likes: number;
createdAt?: string | null;
ingestSource?: string | null;
@@ -37,6 +39,9 @@ function normalizeImageUrl(src?: string | null) {
}
let cleanPath = src.replace(/^\/+/g, '').replace(/\/+/g, '/');
if (cleanPath.startsWith('api/')) {
return `/${cleanPath}`;
}
if (!cleanPath.startsWith('storage/')) {
cleanPath = `storage/${cleanPath}`;
}
@@ -47,18 +52,29 @@ function normalizeImageUrl(src?: string | null) {
function mapPhoto(photo: Record<string, unknown>): LightboxPhoto | null {
const id = Number(photo.id ?? 0);
if (!id) return null;
const imageUrl = normalizeImageUrl(
const fullUrl = normalizeImageUrl(
(photo.full_url as string | null | undefined)
?? (photo.file_path as string | null | undefined)
?? (photo.url as string | null | undefined)
?? (photo.image_url as string | null | undefined)
);
const imageUrl = normalizeImageUrl(
fullUrl
?? (photo.thumbnail_url as string | null | undefined)
?? (photo.thumbnail_path as string | null | undefined)
?? (photo.url as string | null | undefined)
?? (photo.image_url as string | null | undefined)
);
const downloadUrl = normalizeImageUrl(
(photo.download_url as string | null | undefined)
?? fullUrl
);
if (!imageUrl) return null;
return {
id,
imageUrl,
fullUrl: fullUrl || null,
downloadUrl: downloadUrl || null,
likes: typeof photo.likes_count === 'number' ? photo.likes_count : 0,
createdAt: typeof photo.created_at === 'string' ? photo.created_at : null,
ingestSource: typeof photo.ingest_source === 'string' ? photo.ingest_source : null,
@@ -617,7 +633,7 @@ export default function PhotoLightboxScreen() {
>
<Button
unstyled
onPress={() => downloadPhoto(selected?.imageUrl ?? null, selected?.id ?? null)}
onPress={() => downloadPhoto(selected?.downloadUrl ?? selected?.fullUrl ?? selected?.imageUrl ?? null, selected?.id ?? null)}
paddingHorizontal="$3"
paddingVertical="$2"
>