@@ -22,6 +22,7 @@ import axios from "axios";
22
22
import { vote } from "./voteOnSponsorTime" ;
23
23
import { canSubmit } from "../utils/permissions" ;
24
24
import { getVideoDetails , videoDetails } from "../utils/getVideoDetails" ;
25
+ import * as youtubeID from "../utils/youtubeID" ;
25
26
26
27
type CheckResult = {
27
28
pass : boolean ,
@@ -185,15 +186,23 @@ async function checkUserActiveWarning(userID: string): Promise<CheckResult> {
185
186
}
186
187
187
188
async function checkInvalidFields ( videoID : VideoID , userID : UserID , hashedUserID : HashedUserID
188
- , segments : IncomingSegment [ ] , videoDurationParam : number , userAgent : string ) : Promise < CheckResult > {
189
+ , segments : IncomingSegment [ ] , videoDurationParam : number , userAgent : string , service : Service ) : Promise < CheckResult > {
189
190
const invalidFields = [ ] ;
190
191
const errors = [ ] ;
191
192
if ( typeof videoID !== "string" || videoID ?. length == 0 ) {
192
193
invalidFields . push ( "videoID" ) ;
193
194
}
194
- if ( typeof userID !== "string" || userID ?. length < 30 ) {
195
+ if ( service === Service . YouTube && config . mode !== "test" ) {
196
+ const sanitizedVideoID = youtubeID . validate ( videoID ) ? videoID : youtubeID . sanitize ( videoID ) ;
197
+ if ( ! youtubeID . validate ( sanitizedVideoID ) ) {
198
+ invalidFields . push ( "videoID" ) ;
199
+ errors . push ( "YouTube videoID could not be extracted" ) ;
200
+ }
201
+ }
202
+ const minLength = config . minUserIDLength ;
203
+ if ( typeof userID !== "string" || userID ?. length < minLength ) {
195
204
invalidFields . push ( "userID" ) ;
196
- if ( userID ?. length < 30 ) errors . push ( `userID must be at least 30 characters long` ) ;
205
+ if ( userID ?. length < minLength ) errors . push ( `userID must be at least ${ minLength } characters long` ) ;
197
206
}
198
207
if ( ! Array . isArray ( segments ) || segments . length == 0 ) {
199
208
invalidFields . push ( "segments" ) ;
@@ -484,7 +493,7 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
484
493
//hash the userID
485
494
const userID = await getHashCache ( paramUserID || "" ) ;
486
495
487
- const invalidCheckResult = await checkInvalidFields ( videoID , paramUserID , userID , segments , videoDurationParam , userAgent ) ;
496
+ const invalidCheckResult = await checkInvalidFields ( videoID , paramUserID , userID , segments , videoDurationParam , userAgent , service ) ;
488
497
if ( ! invalidCheckResult . pass ) {
489
498
return res . status ( invalidCheckResult . errorCode ) . send ( invalidCheckResult . errorMessage ) ;
490
499
}
0 commit comments