Skip to content

Commit 80942e7

Browse files
authored
chore: fix compoute issue from tags (#2396)
1 parent dda9fa6 commit 80942e7

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/server/api/user/validators.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,23 @@ export const hasApiKeySchema = Joi.object({
2828
userId: Joi.number().required(),
2929
})
3030

31+
const singleTagSchema = Joi.string()
32+
.pattern(/^[A-Za-z0-9-_]+$/)
33+
.max(25)
34+
3135
const tagSchema = Joi.array()
3236
.max(MAX_NUM_TAGS_PER_LINK)
3337
.optional()
38+
// letters, numbers, hyphens, underscores, 25 digits
3439
.items(
35-
Joi.string().custom((tag: string, helpers) => {
36-
if (!isValidTag(tag)) {
37-
return helpers.message({ custom: `tag: ${tag} format is invalid` })
38-
}
39-
return tag
40-
}),
40+
singleTagSchema
41+
.custom((tag: string, helpers) => {
42+
if (!isValidTag(tag)) {
43+
return helpers.error('tag:invalid')
44+
}
45+
return tag
46+
})
47+
.messages({ 'tag:invalid': 'Tag format is invalid.' }),
4148
)
4249
.unique((a, b) => a === b)
4350

@@ -60,13 +67,13 @@ export const userTagsQueryConditions = Joi.object({
6067
.min(3)
6168
.custom((tag: string, helpers) => {
6269
if (!isValidTag(tag)) {
63-
return helpers.message({
64-
custom: `tag: ${tag} query format is invalid.`,
65-
})
70+
return helpers.error('tag:invalid')
6671
}
6772
return tag
6873
})
74+
.messages({ 'tag:invalid': 'Tag format is invalid.' })
6975
.required(),
76+
7077
limit: Joi.number().required(),
7178
})
7279

0 commit comments

Comments
 (0)