limit search query length
This commit is contained in:
parent
4d4ce66404
commit
560be165ee
@ -2,6 +2,7 @@ import { decodeCursor, LIMIT, nextCursorEncoded } from '@/lib/cursor'
|
||||
import { whenToFrom } from '@/lib/time'
|
||||
import { getItem, itemQueryWithMeta, SELECT } from './item'
|
||||
import { parse } from 'tldts'
|
||||
import { searchSchema, validateSchema } from '@/lib/validate'
|
||||
|
||||
function queryParts (q) {
|
||||
const regex = /"([^"]*)"/gm
|
||||
@ -173,6 +174,7 @@ export default {
|
||||
}
|
||||
},
|
||||
search: async (parent, { q, cursor, sort, what, when, from: whenFrom, to: whenTo }, { me, models, search }) => {
|
||||
await validateSchema(searchSchema, { q })
|
||||
const decodedCursor = decodeCursor(cursor)
|
||||
let sitems = null
|
||||
|
||||
|
@ -15,6 +15,7 @@ import { useRouter } from 'next/router'
|
||||
import { whenToFrom } from '@/lib/time'
|
||||
import { useMe } from './me'
|
||||
import { useField } from 'formik'
|
||||
import { searchSchema } from '@/lib/validate'
|
||||
|
||||
export default function Search ({ sub }) {
|
||||
const router = useRouter()
|
||||
@ -65,6 +66,7 @@ export default function Search ({ sub }) {
|
||||
<Form
|
||||
initial={{ q, what, sort, when, from: '', to: '' }}
|
||||
onSubmit={values => search({ ...values })}
|
||||
schema={searchSchema}
|
||||
>
|
||||
<div className={`${styles.active} mb-3`}>
|
||||
<SearchInput
|
||||
|
@ -22,10 +22,6 @@
|
||||
form>.active {
|
||||
display: flex;
|
||||
pointer-events: auto;
|
||||
flex-flow: row nowrap;
|
||||
flex-flow: row;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
form>.active :global(.input-group) {
|
||||
flex-flow: nowrap;
|
||||
}
|
@ -116,6 +116,10 @@ async function subHasPostType (name, type, { client, models }) {
|
||||
return !!(sub?.postTypes?.includes(type))
|
||||
}
|
||||
|
||||
export const searchSchema = object({
|
||||
q: string().trim().max(100, 'must be at most 100 characters')
|
||||
})
|
||||
|
||||
export function advPostSchemaMembers ({ me, existingBoost = 0, ...args }) {
|
||||
const boostMin = existingBoost || BOOST_MIN
|
||||
return {
|
||||
|
Loading…
x
Reference in New Issue
Block a user