+ const elementId = toCompleteUUID(parts.pop())
+ if (isIdOrUUIDValid(elementId) === false) {
+ return res.fail({ message: 'Invalid video or playlist id.' })
+ }
+
+ if (isVideo) {
+ const video = await loadVideo(elementId, 'all')
+
+ if (!video) {
+ return res.fail({
+ status: HttpStatusCode.NOT_FOUND_404,
+ message: 'Video not found'
+ })
+ }
+
+ if (
+ video.privacy === VideoPrivacy.PUBLIC ||
+ (video.privacy === VideoPrivacy.UNLISTED && isUUIDValid(elementId) === true)
+ ) {
+ res.locals.videoAll = video
+ return next()
+ }
+
+ return res.fail({
+ status: HttpStatusCode.FORBIDDEN_403,
+ message: 'Video is not publicly available'
+ })
+ }