Skip to content

Commit beeb269

Browse files
fix: thumbnailURL hook, virtually populate from thumbnail size (#15232)
Removes beforeChange hook on thumbnailURL. Really should be a virtual field, but that would be a breaking change. Corrects the way the url is created by using the thumbnail url in the url generation.
1 parent 4f452ac commit beeb269

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

packages/payload/src/uploads/getBaseFields.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const getBaseUploadFields = ({ collection, config }: Options): Field[] =>
3333
},
3434
hooks: {
3535
afterRead: [
36-
({ originalDoc, req, value }) => {
36+
({ originalDoc, req }) => {
3737
const adminThumbnail =
3838
typeof collection.upload !== 'boolean' ? collection.upload?.adminThumbnail : undefined
3939

@@ -50,21 +50,13 @@ export const getBaseUploadFields = ({ collection, config }: Options): Field[] =>
5050
: undefined,
5151
relative: false,
5252
serverURL: req.payload.config.serverURL,
53-
urlOrPath: value,
53+
urlOrPath:
54+
typeof adminThumbnail === 'string'
55+
? (originalDoc.sizes?.[adminThumbnail].url as string)
56+
: undefined,
5457
})
5558
},
5659
],
57-
beforeChange: [
58-
({ collection, data, originalDoc, req, value }) =>
59-
generateFilePathOrURL({
60-
collectionSlug: collection?.slug as string,
61-
config,
62-
filename: data?.filename || originalDoc?.filename,
63-
relative: true,
64-
serverURL: req.payload.config.serverURL,
65-
urlOrPath: value,
66-
}),
67-
],
6860
},
6961
label: 'Thumbnail URL',
7062
}

0 commit comments

Comments
 (0)