This commit is contained in:
2021-11-16 16:16:14 +01:00
parent 65919ef75d
commit bc71889ae2
14 changed files with 321 additions and 228 deletions

5
src/utils/errors.ts Normal file
View File

@@ -0,0 +1,5 @@
import { FastifyReply } from 'fastify'
export function ForbiddenError(reply: FastifyReply, message?: string) {
reply.code(403).send({ error: 'Forbidden', message })
}

View File

@@ -1,6 +1,7 @@
import { createHash } from 'crypto'
import { validateSync, ValidatorOptions, ValidationError as VE } from 'class-validator'
import { PassThrough, Readable } from 'stream'
import { NullableStringOrRegexpArray } from '../config'
export class ValidationError extends Error {
override message: string
@@ -37,3 +38,12 @@ export function splitter(from: NodeJS.ReadableStream, ...streams: NodeJS.Writabl
}
from.pipe(splitter)
}
export function testForPrefixOrRegexp(str: string, values: (string | RegExp)[]): boolean {
for (const value of values) {
if (typeof value === 'string') {
if (str.startsWith(value)) return true
} else if (value.test(str)) return true
}
return false
}