mirror of
https://github.com/cupcakearmy/morphus.git
synced 2025-12-15 19:04:59 +00:00
progress
This commit is contained in:
5
src/utils/errors.ts
Normal file
5
src/utils/errors.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { FastifyReply } from 'fastify'
|
||||
|
||||
export function ForbiddenError(reply: FastifyReply, message?: string) {
|
||||
reply.code(403).send({ error: 'Forbidden', message })
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user