Skip to content

Commit b7ff353

Browse files
committed
feat(dub-integration): attach read-only dubLink field with afterRead hook to fetch shortLink; chore(deps): bump eslint to ^9.39.0 and @semantic-release/github to ^12.0.1
1 parent 8d53f8c commit b7ff353

File tree

3 files changed

+79
-64
lines changed

3 files changed

+79
-64
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@
6161
"@payloadcms/eslint-config": "3.28.0",
6262
"@semantic-release/changelog": "^6.0.3",
6363
"@semantic-release/git": "^10.0.1",
64-
"@semantic-release/github": "^12.0.0",
64+
"@semantic-release/github": "^12.0.1",
6565
"@semantic-release/npm": "^13.1.1",
6666
"@swc/cli": "^0.7.8",
6767
"@swc/core": "^1.14.0",
6868
"@types/react": "19.2.2",
69-
"eslint": "^9.38.0",
69+
"eslint": "^9.39.0",
7070
"payload": "3.62.0",
7171
"prettier": "^3.6.2",
7272
"rimraf": "6.1.0",

pnpm-lock.yaml

Lines changed: 42 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,41 @@ export const payloadDub =
158158

159159
const attachFields = [...(collection.fields || [])]
160160

161+
if (!attachFields.some((field) => 'name' in field && field.name === 'dubLink')) {
162+
attachFields.push({
163+
name: 'dubLink',
164+
type: 'text',
165+
admin: {
166+
position: 'sidebar',
167+
readOnly: true,
168+
},
169+
hooks: {
170+
afterRead: [
171+
async ({ originalDoc, req }) => {
172+
try {
173+
if (!originalDoc?.id) {
174+
return ''
175+
}
176+
177+
const dubDoc = await req.payload.find({
178+
collection: 'dubLinks',
179+
limit: 1,
180+
overrideAccess: true,
181+
where: {
182+
'source.value': { equals: originalDoc.id },
183+
},
184+
})
185+
186+
return dubDoc?.docs?.[0]?.shortLink || ''
187+
} catch {
188+
return ''
189+
}
190+
},
191+
],
192+
},
193+
})
194+
}
195+
161196
if (!attachFields.some((field) => 'name' in field && field.name === 'dubTags')) {
162197
attachFields.push({
163198
name: 'dubTags',

0 commit comments

Comments
 (0)