mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-14 23:47:00 +03:00
Add friendlier message for short userID
This commit is contained in:
@@ -338,11 +338,13 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
|
|||||||
});
|
});
|
||||||
|
|
||||||
const invalidFields = [];
|
const invalidFields = [];
|
||||||
|
const errors = [];
|
||||||
if (typeof videoID !== 'string') {
|
if (typeof videoID !== 'string') {
|
||||||
invalidFields.push('videoID');
|
invalidFields.push('videoID');
|
||||||
}
|
}
|
||||||
if (typeof userID !== 'string' || userID.length < 30) {
|
if (typeof userID !== 'string' || userID.length < 30) {
|
||||||
invalidFields.push('userID');
|
invalidFields.push('userID');
|
||||||
|
if (userID.length < 30) errors.push(`userID must be at least 30 characters long`);
|
||||||
}
|
}
|
||||||
if (!Array.isArray(segments) || segments.length < 1) {
|
if (!Array.isArray(segments) || segments.length < 1) {
|
||||||
invalidFields.push('segments');
|
invalidFields.push('segments');
|
||||||
@@ -350,8 +352,9 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
|
|||||||
|
|
||||||
if (invalidFields.length !== 0) {
|
if (invalidFields.length !== 0) {
|
||||||
// invalid request
|
// invalid request
|
||||||
const fields = invalidFields.reduce((p, c, i) => p + (i !== 0 ? ', ' : '') + c, '');
|
const formattedFields = invalidFields.reduce((p, c, i) => p + (i !== 0 ? ', ' : '') + c, '');
|
||||||
return res.status(400).send(`No valid ${fields} field(s) provided`);
|
const formattedErrors = errors.reduce((p, c, i) => p + (i !== 0 ? '. ' : ' ') + c, '');
|
||||||
|
return res.status(400).send(`No valid ${formattedFields} field(s) provided.${formattedErrors}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
//hash the userID
|
//hash the userID
|
||||||
|
|||||||
Reference in New Issue
Block a user