Reintroduce og url check with presigned urls
This commit is contained in:
parent
51f9d4300d
commit
4570104dd7
@ -3,7 +3,10 @@
|
||||
import { Photo } from '@/photo';
|
||||
import { NextImageSize } from '@/platforms/next-image';
|
||||
import { IS_PREVIEW } from '@/app/config';
|
||||
import { getOptimizedPhotoUrl } from '@/photo/storage';
|
||||
import {
|
||||
doAllPhotosHaveOptimizedFiles,
|
||||
getOptimizedPhotoUrl,
|
||||
} from '@/photo/storage';
|
||||
import { fetchBase64ImageFromUrl } from '@/utility/image';
|
||||
import { getSignedUrlForUrl } from '@/platforms/storage';
|
||||
|
||||
@ -50,11 +53,14 @@ export default async function ImagePhotoGrid({
|
||||
const cellHeight= height / rows -
|
||||
(rows - 1) * gap / rows;
|
||||
|
||||
const doOptimizedFilesExist = await doAllPhotosHaveOptimizedFiles(photos);
|
||||
|
||||
const photoDataUrls = await Promise.all(photos.map(async({ id, url }) => {
|
||||
const optimizedUrl = getOptimizedPhotoUrl({
|
||||
imageUrl: url,
|
||||
size: nextImageWidth,
|
||||
addBypassSecret: IS_PREVIEW,
|
||||
compatibilityMode: !doOptimizedFilesExist,
|
||||
});
|
||||
const presignedUrl = await getSignedUrlForUrl(optimizedUrl, 'GET');
|
||||
const data = await fetchBase64ImageFromUrl(presignedUrl);
|
||||
|
||||
@ -5,6 +5,7 @@ import {
|
||||
import {
|
||||
generateFileNameWithId,
|
||||
getFileNamePartsFromStorageUrl,
|
||||
getSignedUrlForUrl,
|
||||
getStorageUrlsForPrefix,
|
||||
uploadFileFromClient,
|
||||
} from '@/platforms/storage';
|
||||
@ -139,7 +140,9 @@ export const doesPhotoUrlHaveOptimizedFiles = async (url: string) =>
|
||||
fetch(getTestOptimizedPhotoUrl(url)).then(res => res.ok);
|
||||
|
||||
export const doAllPhotosHaveOptimizedFiles = async (photos: Photo[]) =>
|
||||
Promise.all(photos.map(({ url }) => fetch(getTestOptimizedPhotoUrl(url))))
|
||||
Promise.all(photos.map(async ({ url }) => fetch(
|
||||
await getSignedUrlForUrl(getTestOptimizedPhotoUrl(url), 'GET'),
|
||||
)))
|
||||
.then(urls => urls.every(url => url.ok))
|
||||
.catch(() => false);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user