server side validate title length

This commit is contained in:
keyan 2022-08-26 18:31:51 -05:00
parent 04d9c45156
commit 5b2cfd11cc
1 changed files with 9 additions and 1 deletions

View File

@ -4,7 +4,7 @@ import serialize from './serial'
import { decodeCursor, LIMIT, nextCursorEncoded } from '../../lib/cursor' import { decodeCursor, LIMIT, nextCursorEncoded } from '../../lib/cursor'
import { getMetadata, metadataRuleSets } from 'page-metadata-parser' import { getMetadata, metadataRuleSets } from 'page-metadata-parser'
import domino from 'domino' import domino from 'domino'
import { BOOST_MIN, ITEM_SPAM_INTERVAL, MAX_POLL_NUM_CHOICES } from '../../lib/constants' import { BOOST_MIN, ITEM_SPAM_INTERVAL, MAX_POLL_NUM_CHOICES, MAX_TITLE_LENGTH } from '../../lib/constants'
import { mdHas } from '../../lib/md' import { mdHas } from '../../lib/md'
async function comments (models, id, sort) { async function comments (models, id, sort) {
@ -877,6 +877,10 @@ export const updateItem = async (parent, { id, data: { title, url, text, boost,
throw new UserInputError(`boost must be at least ${BOOST_MIN}`, { argumentName: 'boost' }) throw new UserInputError(`boost must be at least ${BOOST_MIN}`, { argumentName: 'boost' })
} }
if (title.length > MAX_TITLE_LENGTH) {
throw new UserInputError('title too long')
}
let fwdUser let fwdUser
if (forward) { if (forward) {
fwdUser = await models.user.findUnique({ where: { name: forward } }) fwdUser = await models.user.findUnique({ where: { name: forward } })
@ -906,6 +910,10 @@ const createItem = async (parent, { title, url, text, boost, forward, parentId }
throw new UserInputError(`boost must be at least ${BOOST_MIN}`, { argumentName: 'boost' }) throw new UserInputError(`boost must be at least ${BOOST_MIN}`, { argumentName: 'boost' })
} }
if (title.length > MAX_TITLE_LENGTH) {
throw new UserInputError('title too long')
}
let fwdUser let fwdUser
if (forward) { if (forward) {
fwdUser = await models.user.findUnique({ where: { name: forward } }) fwdUser = await models.user.findUnique({ where: { name: forward } })