@@ -32,18 +32,24 @@ export async function getLockReason(req: Request, res: Response): Promise<Respon
32
32
return res . status ( 400 ) . send ( "No videoID provided" ) ;
33
33
}
34
34
let categories : Category [ ] = [ ] ;
35
- const actionTypes : ActionType [ ] = req . query . actionTypes
36
- ? JSON . parse ( req . query . actionTypes as string )
37
- : req . query . actionType
38
- ? Array . isArray ( req . query . actionType )
39
- ? req . query . actionType
40
- : [ req . query . actionType ]
41
- : [ ActionType . Skip , ActionType . Mute ] ;
42
- const possibleCategories = filterActionType ( actionTypes ) ;
43
- if ( ! Array . isArray ( actionTypes ) ) {
44
- //invalid request
45
- return res . status ( 400 ) . send ( "actionTypes parameter does not match format requirements" ) ;
35
+ let actionTypes : ActionType [ ] = [ ] ;
36
+ try {
37
+ actionTypes = req . query . actionTypes
38
+ ? JSON . parse ( req . query . actionTypes as string )
39
+ : req . query . actionType
40
+ ? Array . isArray ( req . query . actionType )
41
+ ? req . query . actionType
42
+ : [ req . query . actionType ]
43
+ : [ ActionType . Skip , ActionType . Mute ] ;
44
+ if ( ! Array . isArray ( actionTypes ) ) {
45
+ //invalid request
46
+ return res . status ( 400 ) . send ( "actionTypes parameter does not match format requirements" ) ;
47
+ }
48
+ } catch ( error ) {
49
+ return res . status ( 400 ) . send ( "Bad parameter: actionTypes (invalid JSON)" ) ;
46
50
}
51
+ const possibleCategories = filterActionType ( actionTypes ) ;
52
+
47
53
try {
48
54
categories = req . query . categories
49
55
? JSON . parse ( req . query . categories as string )
@@ -64,11 +70,6 @@ export async function getLockReason(req: Request, res: Response): Promise<Respon
64
70
: categories . filter ( x =>
65
71
possibleCategories . includes ( x ) ) ;
66
72
67
- if ( ! videoID || ! Array . isArray ( actionTypes ) ) {
68
- //invalid request
69
- return res . sendStatus ( 400 ) ;
70
- }
71
-
72
73
try {
73
74
// Get existing lock categories markers
74
75
const row = await db . prepare ( "all" , 'SELECT "category", "reason", "actionType", "userID" from "lockCategories" where "videoID" = ?' , [ videoID ] ) as { category : Category , reason : string , actionType : ActionType , userID : string } [ ] ;
@@ -115,7 +116,7 @@ export async function getLockReason(req: Request, res: Response): Promise<Respon
115
116
}
116
117
117
118
return res . send ( results ) ;
118
- } catch ( err ) {
119
+ } catch ( err ) /* istanbul ignore next */ {
119
120
Logger . error ( err as string ) ;
120
121
return res . sendStatus ( 500 ) ;
121
122
}
0 commit comments