mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-19 14:14:17 +00:00
fix: duplicate validation
This commit is contained in:
committed by
Carlos Valente
parent
cbf3d566b9
commit
1b448835cd
@@ -18,6 +18,7 @@ import {
|
|||||||
validatePatchProject,
|
validatePatchProject,
|
||||||
validateFilenameBody,
|
validateFilenameBody,
|
||||||
validateFilenameParam,
|
validateFilenameParam,
|
||||||
|
validateNewFilenameBody,
|
||||||
} from './db.validation.js';
|
} from './db.validation.js';
|
||||||
|
|
||||||
export const router = express.Router();
|
export const router = express.Router();
|
||||||
@@ -31,7 +32,7 @@ router.post('/new', validateFilenameBody, validateNewProject, createProjectFile)
|
|||||||
router.get('/all', listProjects);
|
router.get('/all', listProjects);
|
||||||
|
|
||||||
router.post('/load', validateFilenameBody, loadProject);
|
router.post('/load', validateFilenameBody, loadProject);
|
||||||
router.post('/:filename/duplicate', validateFilenameParam, validateFilenameBody, duplicateProjectFile);
|
router.post('/:filename/duplicate', validateFilenameParam, validateNewFilenameBody, duplicateProjectFile);
|
||||||
router.put('/:filename/rename', validateFilenameParam, validateFilenameBody, renameProjectFile);
|
router.put('/:filename/rename', validateFilenameParam, validateFilenameBody, renameProjectFile);
|
||||||
router.delete('/:filename', validateFilenameParam, deleteProjectFile);
|
router.delete('/:filename', validateFilenameParam, deleteProjectFile);
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,30 @@ export const validatePatchProject = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Validates request with newFilename in the body.
|
||||||
|
*/
|
||||||
|
export const validateNewFilenameBody = [
|
||||||
|
body('newFilename')
|
||||||
|
.exists()
|
||||||
|
.isString()
|
||||||
|
.trim()
|
||||||
|
.customSanitizer((input: string) => sanitize(input))
|
||||||
|
.withMessage('Failed to sanitize the filename')
|
||||||
|
.notEmpty()
|
||||||
|
.withMessage('Filename was empty or contained only invalid characters')
|
||||||
|
.customSanitizer((input: string) => ensureJsonExtension(input)),
|
||||||
|
|
||||||
|
(req: Request, res: Response, next: NextFunction) => {
|
||||||
|
const errors = validationResult(req);
|
||||||
|
if (!errors.isEmpty()) {
|
||||||
|
return res.status(422).json({ errors: errors.array() });
|
||||||
|
}
|
||||||
|
|
||||||
|
next();
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Validates request with filename in the body.
|
* @description Validates request with filename in the body.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user