max length on text
This commit is contained in:
parent
f31598d08d
commit
aeb3ab40fa
|
@ -19,6 +19,8 @@ export const UPLOAD_TYPES_ALLOW = [
|
|||
]
|
||||
export const COMMENT_DEPTH_LIMIT = 8
|
||||
export const MAX_TITLE_LENGTH = 80
|
||||
export const MAX_POST_TEXT_LENGTH = 100000 // 100k
|
||||
export const MAX_COMMENT_TEXT_LENGTH = 10000 // 10k
|
||||
export const MAX_POLL_CHOICE_LENGTH = 40
|
||||
export const ITEM_SPAM_INTERVAL = '10m'
|
||||
export const ANON_ITEM_SPAM_INTERVAL = '0'
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { string, ValidationError, number, object, array, addMethod, boolean } from 'yup'
|
||||
import { BOOST_MIN, MAX_POLL_CHOICE_LENGTH, MAX_TITLE_LENGTH, MAX_POLL_NUM_CHOICES, MIN_POLL_NUM_CHOICES, SUBS_NO_JOBS, MAX_FORWARDS, BOOST_MULT } from './constants'
|
||||
import { BOOST_MIN, MAX_POLL_CHOICE_LENGTH, MAX_TITLE_LENGTH, MAX_POLL_NUM_CHOICES, MIN_POLL_NUM_CHOICES, SUBS_NO_JOBS, MAX_FORWARDS, BOOST_MULT, MAX_COMMENT_TEXT_LENGTH, MAX_POST_TEXT_LENGTH } from './constants'
|
||||
import { URL_REGEXP, WS_REGEXP } from './url'
|
||||
import { SUPPORTED_CURRENCIES } from './currency'
|
||||
import { NOSTR_MAX_RELAY_NUM, NOSTR_PUBKEY_BECH32, NOSTR_PUBKEY_HEX } from './nostr'
|
||||
|
@ -42,6 +42,11 @@ const titleValidator = string().required('required').trim().max(
|
|||
({ max, value }) => `-${Math.abs(max - value.length)} characters remaining`
|
||||
)
|
||||
|
||||
const textValidator = (max) => string().trim().max(
|
||||
max,
|
||||
({ max, value }) => `-${Math.abs(max - value.length)} characters remaining`
|
||||
)
|
||||
|
||||
const intValidator = number().typeError('must be a number').integer('must be whole')
|
||||
|
||||
async function usernameExists (name, { client, models }) {
|
||||
|
@ -118,6 +123,7 @@ export function advSchema (args) {
|
|||
export function bountySchema (args) {
|
||||
return object({
|
||||
title: titleValidator,
|
||||
text: textValidator(MAX_POST_TEXT_LENGTH),
|
||||
bounty: intValidator
|
||||
.min(1000, 'must be at least 1000')
|
||||
.max(1000000, 'must be at most 1m'),
|
||||
|
@ -129,6 +135,7 @@ export function bountySchema (args) {
|
|||
export function discussionSchema (args) {
|
||||
return object({
|
||||
title: titleValidator,
|
||||
text: textValidator(MAX_POST_TEXT_LENGTH),
|
||||
...advPostSchemaMembers(args),
|
||||
...subSelectSchemaMembers()
|
||||
})
|
||||
|
@ -137,6 +144,7 @@ export function discussionSchema (args) {
|
|||
export function linkSchema (args) {
|
||||
return object({
|
||||
title: titleValidator,
|
||||
text: textValidator(MAX_POST_TEXT_LENGTH),
|
||||
url: string().matches(URL_REGEXP, 'invalid url').required('required'),
|
||||
...advPostSchemaMembers(args),
|
||||
...subSelectSchemaMembers()
|
||||
|
@ -146,6 +154,7 @@ export function linkSchema (args) {
|
|||
export function pollSchema ({ numExistingChoices = 0, ...args }) {
|
||||
return object({
|
||||
title: titleValidator,
|
||||
text: textValidator(MAX_POST_TEXT_LENGTH),
|
||||
options: array().of(
|
||||
string().trim().test('my-test', 'required', function (value) {
|
||||
return (this.path !== 'options[0]' && this.path !== 'options[1]') || value
|
||||
|
@ -182,13 +191,13 @@ export function userSchema (args) {
|
|||
}
|
||||
|
||||
export const commentSchema = object({
|
||||
text: string().required('required').trim()
|
||||
text: textValidator(MAX_COMMENT_TEXT_LENGTH).required('required')
|
||||
})
|
||||
|
||||
export const jobSchema = object({
|
||||
title: titleValidator,
|
||||
company: string().required('required').trim(),
|
||||
text: string().required('required').trim(),
|
||||
text: textValidator(MAX_POST_TEXT_LENGTH).required('required'),
|
||||
url: string()
|
||||
.or([string().email(), string().url()], 'invalid url or email')
|
||||
.required('required'),
|
||||
|
|
Loading…
Reference in New Issue