mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-13 19:33:46 +00:00
29 lines
740 B
TypeScript
29 lines
740 B
TypeScript
import { isImportMap } from 'ontime-utils';
|
|
|
|
import { body, validationResult } from 'express-validator';
|
|
import type { NextFunction, Request, Response } from 'express';
|
|
|
|
export const validateFileExists = [
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
if (!req.file) {
|
|
return res.status(422).json({ errors: 'File not found' });
|
|
}
|
|
next();
|
|
},
|
|
];
|
|
|
|
export const validateImportMapOptions = [
|
|
body('options')
|
|
.exists()
|
|
.isObject()
|
|
.custom((content) => {
|
|
return isImportMap(content);
|
|
}),
|
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
const errors = validationResult(req);
|
|
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
|
|
next();
|
|
},
|
|
];
|