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 { whenToFrom } from '@/lib/time'
|
||||||
import { getItem, itemQueryWithMeta, SELECT } from './item'
|
import { getItem, itemQueryWithMeta, SELECT } from './item'
|
||||||
import { parse } from 'tldts'
|
import { parse } from 'tldts'
|
||||||
|
import { searchSchema, validateSchema } from '@/lib/validate'
|
||||||
|
|
||||||
function queryParts (q) {
|
function queryParts (q) {
|
||||||
const regex = /"([^"]*)"/gm
|
const regex = /"([^"]*)"/gm
|
||||||
@ -173,6 +174,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
search: async (parent, { q, cursor, sort, what, when, from: whenFrom, to: whenTo }, { me, models, search }) => {
|
search: async (parent, { q, cursor, sort, what, when, from: whenFrom, to: whenTo }, { me, models, search }) => {
|
||||||
|
await validateSchema(searchSchema, { q })
|
||||||
const decodedCursor = decodeCursor(cursor)
|
const decodedCursor = decodeCursor(cursor)
|
||||||
let sitems = null
|
let sitems = null
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ import { useRouter } from 'next/router'
|
|||||||
import { whenToFrom } from '@/lib/time'
|
import { whenToFrom } from '@/lib/time'
|
||||||
import { useMe } from './me'
|
import { useMe } from './me'
|
||||||
import { useField } from 'formik'
|
import { useField } from 'formik'
|
||||||
|
import { searchSchema } from '@/lib/validate'
|
||||||
|
|
||||||
export default function Search ({ sub }) {
|
export default function Search ({ sub }) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@ -65,6 +66,7 @@ export default function Search ({ sub }) {
|
|||||||
<Form
|
<Form
|
||||||
initial={{ q, what, sort, when, from: '', to: '' }}
|
initial={{ q, what, sort, when, from: '', to: '' }}
|
||||||
onSubmit={values => search({ ...values })}
|
onSubmit={values => search({ ...values })}
|
||||||
|
schema={searchSchema}
|
||||||
>
|
>
|
||||||
<div className={`${styles.active} mb-3`}>
|
<div className={`${styles.active} mb-3`}>
|
||||||
<SearchInput
|
<SearchInput
|
||||||
|
@ -22,10 +22,6 @@
|
|||||||
form>.active {
|
form>.active {
|
||||||
display: flex;
|
display: flex;
|
||||||
pointer-events: auto;
|
pointer-events: auto;
|
||||||
flex-flow: row nowrap;
|
flex-flow: row;
|
||||||
align-items: center;
|
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))
|
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 }) {
|
export function advPostSchemaMembers ({ me, existingBoost = 0, ...args }) {
|
||||||
const boostMin = existingBoost || BOOST_MIN
|
const boostMin = existingBoost || BOOST_MIN
|
||||||
return {
|
return {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user