-async function checkCanSeePrivateVideo (req: Request, res: Response, video: MVideoWithRights, authenticateInQuery = false) {
- await authenticatePromiseIfNeeded(req, res, authenticateInQuery)
+async function checkCanSeeAuthVideo (req: Request, res: Response, video: MVideoId | MVideoWithRights) {
+ const fail = () => {
+ res.fail({
+ status: HttpStatusCode.FORBIDDEN_403,
+ message: 'Cannot fetch information of private/internal/blocked video'
+ })
+
+ return false
+ }
+
+ await authenticatePromise(req, res)
+
+ const user = res.locals.oauth?.token.User
+ if (!user) return fail()
+
+ const videoWithRights = (video as MVideoWithRights).VideoChannel?.Account?.userId
+ ? video as MVideoWithRights
+ : await VideoModel.loadFull(video.id)
+
+ const privacy = videoWithRights.privacy
+
+ if (privacy === VideoPrivacy.INTERNAL) {
+ // We know we have a user
+ return true
+ }
+
+ const isOwnedByUser = videoWithRights.VideoChannel.Account.userId === user.id
+
+ if (videoWithRights.isBlacklisted()) {
+ if (isOwnedByUser || user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)) return true
+
+ return fail()
+ }