diff --git a/next.config.js b/next.config.js index 9ad8806..ac74d31 100644 --- a/next.config.js +++ b/next.config.js @@ -5,14 +5,6 @@ const nextConfig = { images: { imageSizes: [300, 600, 1200], remotePatterns: [ - { - protocol: 'https', - hostname: `${ - process.env.AWS_BUCKET || 'me-blog' - }.s3.ap-southeast-1.wasabisys.com`, - port: '', - pathname: '/**', - }, { protocol: 'https', hostname: 'cdn.dumpsayamrat.com', diff --git a/src/app/(public)/gallery/grid/page.tsx b/src/app/(public)/gallery/grid/page.tsx index 65880b9..4a4bd3a 100644 --- a/src/app/(public)/gallery/grid/page.tsx +++ b/src/app/(public)/gallery/grid/page.tsx @@ -13,16 +13,16 @@ export const revalidate = 'force-cache' export default async function Gallery() { const photos = await getCachedPhotoList() return ( -
-
+
+
{photos.map(photo => - photo && photo.presignedURL ? ( + photo && photo.url ? (
{photo.title}{children} + return ( +
+ +
{children}
+
+ ) } diff --git a/src/app/(public)/gallery/page.tsx b/src/app/(public)/gallery/page.tsx index 1209752..da01811 100644 --- a/src/app/(public)/gallery/page.tsx +++ b/src/app/(public)/gallery/page.tsx @@ -15,25 +15,26 @@ export const revalidate = 'force-cache' export default async function Gallery() { const photos = await getCachedPhotoList() return ( -
+
{photos.map(photo => photo && photo.url ? (
-
+
{photo.title}
-
+

{photo.title}

diff --git a/src/components/PhotoLayoutSwitcher.tsx b/src/components/PhotoLayoutSwitcher.tsx new file mode 100644 index 0000000..d710fb3 --- /dev/null +++ b/src/components/PhotoLayoutSwitcher.tsx @@ -0,0 +1,72 @@ +'use client' +import clsx from 'clsx' +import Link from 'next/link' +import { usePathname } from 'next/navigation' + +const FullFrameIcon = () => ( + + Full Frame + + + + +) + +const GridIcon = () => ( + + Grid + + + + + +) + +const PhotoLayoutSwitcher = () => { + const pathname = usePathname() + const gridPage = pathname.includes('/grid'); + return ( +
+ + + + + + +
+ ) +} + +export default PhotoLayoutSwitcher; diff --git a/src/constants.ts b/src/constants.ts index 3821c01..b1f50ed 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -12,6 +12,6 @@ export const BLOB_PHOTO_PREFIX = 'photos' export const LARGE_PHOTO_SIZE = 1200 -export const SMALL_PHOTO_SIZE = 300 +export const SMALL_PHOTO_SIZE = 600 export const MEMO_CACHE_TIME = 12 * 60 * 60 * 1000 // 12 hours diff --git a/src/services/photo.ts b/src/services/photo.ts index e461991..9e1abb0 100644 --- a/src/services/photo.ts +++ b/src/services/photo.ts @@ -7,6 +7,7 @@ import { kv } from '@vercel/kv' import { cache } from 'react' import MemoryCache from '@/memory-cache' import { CACHE_GET_PRESIGNED_KEY, MEMO_CACHE_TIME } from '@/constants' +import { generateCdnUrl } from '@/utils/photo' const memoCache = MemoryCache.getInstance() @@ -46,12 +47,9 @@ export const getPhotoList = async () => { ) ) photos = photos.sort((a, b) => (b?.createdAt ?? 0) - (a?.createdAt ?? 0)) - const urls = await Promise.all( - photos.map(photo => (photo?.url ? getPresignedURL(photo?.url) : '')) - ) - return photos.map((photo, index) => ({ + return photos.map((photo) => ({ ...(photo as Photo), - presignedURL: urls[index], + url: photo?.url ? generateCdnUrl(photo.url) : '', })) } diff --git a/src/utils/photo.ts b/src/utils/photo.ts index c863126..2df2846 100644 --- a/src/utils/photo.ts +++ b/src/utils/photo.ts @@ -21,3 +21,5 @@ export const convertFormDataToPhoto = (data: PhotoFormData): Photo => { takenAt: new Date(data.takenAt).valueOf(), } } + +export const generateCdnUrl = (path: string) => `${process.env.NEXT_PUBLIC_CDN}/${path}`