diff --git a/packages/plugin-cloud-storage/src/adapters/vercelBlob/getFilePrefix.ts b/packages/plugin-cloud-storage/src/adapters/vercelBlob/getFilePrefix.ts deleted file mode 100644 index dfbbd7b066..0000000000 --- a/packages/plugin-cloud-storage/src/adapters/vercelBlob/getFilePrefix.ts +++ /dev/null @@ -1,32 +0,0 @@ -import type { CollectionConfig, PayloadRequest, UploadConfig } from 'payload/types' - -export async function getFilePrefix({ - collection, - req, -}: { - collection: CollectionConfig - req: PayloadRequest -}): Promise { - const imageSizes = (collection?.upload as UploadConfig)?.imageSizes || [] - const { routeParams } = req - const filename = routeParams?.['filename'] - - const files = await req.payload.find({ - collection: collection.slug, - depth: 0, - limit: 1, - pagination: false, - where: { - or: [ - { - filename: { equals: filename }, - }, - ...imageSizes.map((imageSize) => ({ - [`sizes.${imageSize.name}.filename`]: { equals: filename }, - })), - ], - }, - }) - const prefix = files?.docs?.[0]?.prefix - return prefix ? (prefix as string) : '' -} diff --git a/packages/plugin-cloud-storage/src/adapters/vercelBlob/staticHandler.ts b/packages/plugin-cloud-storage/src/adapters/vercelBlob/staticHandler.ts index 67bc29a9ed..48037a5dce 100644 --- a/packages/plugin-cloud-storage/src/adapters/vercelBlob/staticHandler.ts +++ b/packages/plugin-cloud-storage/src/adapters/vercelBlob/staticHandler.ts @@ -4,6 +4,8 @@ import type { CollectionConfig, PayloadRequest, UploadConfig } from 'payload/typ import { head } from '@vercel/blob' import path from 'path' +import { getFilePrefix } from '../../utilities/getFilePrefix.js' + type StaticHandlerArgs = { baseUrl: string token: string @@ -48,34 +50,3 @@ export const getStaticHandler = ( } } } - -async function getFilePrefix({ - collection, - req, -}: { - collection: CollectionConfig - req: PayloadRequest -}): Promise { - const imageSizes = (collection?.upload as UploadConfig)?.imageSizes || [] - const { routeParams } = req - const filename = routeParams?.['filename'] - - const files = await req.payload.find({ - collection: collection.slug, - depth: 0, - limit: 1, - pagination: false, - where: { - or: [ - { - filename: { equals: filename }, - }, - ...imageSizes.map((imageSize) => ({ - [`sizes.${imageSize.name}.filename`]: { equals: filename }, - })), - ], - }, - }) - const prefix = files?.docs?.[0]?.prefix - return prefix ? (prefix as string) : '' -}