chore(pcs): use proper getFilePrefix
This commit is contained in:
@@ -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) : ''
|
||||
}
|
||||
@@ -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) : ''
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user