Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ export const normalizeForwards = (forward) => {
if (!Array.isArray(forward)) {
return undefined
}
return forward.filter(fwd => fwd.nym || fwd.user?.name).map(fwd => ({ nym: fwd.nym ?? fwd.user?.name, pct: Number(fwd.pct) }))
// Convert to normalized objects and filter out entries with no recipient
// and entries with a zero/invalid percentage. Users sometimes type '0'
// to mean blank; treat those as empty and drop them before sending to the server.
return forward
.map(fwd => ({ nym: fwd.nym ?? fwd.user?.name, pct: Number(fwd.pct) }))
.filter(fwd => fwd.nym && fwd.pct > 0)
}

export const toastUpsertSuccessMessages = (toaster, upsertResponseData, dataKey, itemText) => {
Expand Down
11 changes: 7 additions & 4 deletions lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
MIN_POLL_NUM_CHOICES, MAX_FORWARDS, BOOST_MULT, MAX_TERRITORY_DESC_LENGTH, POST_TYPES,
TERRITORY_BILLING_TYPES, MAX_COMMENT_TEXT_LENGTH, MAX_POST_TEXT_LENGTH, MIN_TITLE_LENGTH, BOUNTY_MIN, BOUNTY_MAX,
RESERVED_SUB_NAMES,
BOOST_MAX
BOOST_MAX,
SSR
} from './constants'
import { SUPPORTED_CURRENCIES } from './currency'
import { NOSTR_MAX_RELAY_NUM, NOSTR_PUBKEY_BECH32, NOSTR_PUBKEY_HEX } from './nostr'
Expand All @@ -16,7 +17,7 @@ import { datePivot } from './time'
export async function validateSchema (schema, data, args) {
try {
if (typeof schema === 'function') {
return await schema(args).validate(data)
return await schema({ server: SSR, ...args }).validate(data)
} else {
return await schema.validate(data)
}
Expand Down Expand Up @@ -120,7 +121,7 @@ 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, server, ...args }) {
const boostMin = existingBoost || BOOST_MIN
return {
boost: intValidator
Expand Down Expand Up @@ -150,7 +151,9 @@ export function advPostSchemaMembers ({ me, existingBoost = 0, ...args }) {
},
message: 'cannot forward to yourself'
}),
pct: intValidator.required('must specify a percentage').min(1, 'percentage must be at least 1').max(100, 'percentage must not exceed 100')
pct: server
? intValidator.required('must specify a percentage').min(1, 'percentage must be at least 1').max(100, 'percentage must not exceed 100')
: intValidator.required('must specify a percentage').max(100, 'percentage must not exceed 100')
}))
.compact((v) => !v.nym && !v.pct)
.test({
Expand Down