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