+async function checkVideoFollowConstraints (req: express.Request, res: express.Response, next: express.NextFunction) {
+ const video = getVideoWithAttributes(res)
+
+ // Anybody can watch local videos
+ if (video.isOwned() === true) return next()
+
+ // Logged user
+ if (res.locals.oauth) {
+ // Users can search or watch remote videos
+ if (CONFIG.SEARCH.REMOTE_URI.USERS === true) return next()
+ }
+
+ // Anybody can search or watch remote videos
+ if (CONFIG.SEARCH.REMOTE_URI.ANONYMOUS === true) return next()
+
+ // Check our instance follows an actor that shared this video
+ const serverActor = await getServerActor()
+ if (await VideoModel.checkVideoHasInstanceFollow(video.id, serverActor.id) === true) return next()
+
+ return res.status(403)
+ .json({
+ error: 'Cannot get this video regarding follow constraints.'
+ })
+}
+
+const videosCustomGetValidator = (
+ fetchType: 'all' | 'only-video' | 'only-video-with-rights' | 'only-immutable-attributes',
+ authenticateInQuery = false
+) => {