reworked the guest pwa, modernized start and gallery page. added share link functionality.
This commit is contained in:
@@ -134,3 +134,43 @@ export async function uploadPhoto(eventToken: string, file: File, taskId?: numbe
|
||||
const json = await res.json();
|
||||
return json.photo_id ?? json.id ?? json.data?.id ?? 0;
|
||||
}
|
||||
|
||||
export async function createPhotoShareLink(eventToken: string, photoId: number): Promise<{ slug: string; url: string; expires_at?: string }> {
|
||||
const headers = getCsrfHeaders();
|
||||
|
||||
const res = await fetch(`/api/v1/events/${encodeURIComponent(eventToken)}/photos/${photoId}/share`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers,
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
let payload: any = null;
|
||||
try {
|
||||
payload = await res.clone().json();
|
||||
} catch {}
|
||||
|
||||
const error: UploadError = new Error(payload?.error?.message ?? 'Share link creation failed');
|
||||
error.code = payload?.error?.code ?? 'share_failed';
|
||||
error.status = res.status;
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function fetchPhotoShare(slug: string) {
|
||||
const res = await fetch(`/api/v1/photo-shares/${encodeURIComponent(slug)}`, {
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const payload = await res.json().catch(() => null);
|
||||
const error: UploadError = new Error(payload?.error?.message ?? 'Share link unavailable');
|
||||
error.code = payload?.error?.code ?? 'share_unavailable';
|
||||
error.status = res.status;
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res.json();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user