chore(pcs): use proper getFilePrefix

This commit is contained in:
Elliot DeNolf
2024-04-12 09:28:32 -04:00
parent 5db2863d08
commit d98d0fd5bd
2 changed files with 2 additions and 63 deletions

View File

@@ -1,32 +0,0 @@
import type { CollectionConfig, PayloadRequest, UploadConfig } from 'payload/types'
export async function getFilePrefix({
collection,
req,
}: {
collection: CollectionConfig
req: PayloadRequest
}): Promise<string> {
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) : ''
}

View File

@@ -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<string> {
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) : ''
}