We only want logged in users to view the video with any privacy type and for not logged in users we want to show the NOT_AUTHORIZED page, which is implemented for ‹ PRIVATE and INTERNAL › videos by default in Peertube.
Trying to filter a video using the following hook (‹ filter:api.video.get.result ›),
if we do not return a video using this hook, the error is always ‹ video.isOutdated() is not a function › and no further execution is possible.
Is there any way to achieve what we are trying to implement (is this particular hook not the way to go?)
How can we not return a video and not get the error?
target: 'filter:api.video.get.result',
handler: async (video, userInfo) => {
if (!video) return video
if (!userInfo.userId) return { data: [] }
return video
}
})```
I have a similar scenario where I have only allowed authenticated user to view the video using plugin. Here, what actually happening is that if a user is not logged in and he/she tries to view the video he is redirected to 404 page.
If I modify the main code base then I am able to show the 401 unauthorized.
Here, I have installed auth-openid-connect plugin for authentication.
What I actually want to do here is that when a user tries to view the video without login he/she should be directly redirected to the auth-openid-connect for authentication rather then showing 401.
For example:
async function getVideo (req: express.Request, res: express.Response) {
const videoId = res.locals.videoAPI.id
const userId = res.locals.oauth?.token.User.id
// if (!userId && videoId) return res.sendStatus(HttpStatusCode.UNAUTHORIZED_401)
if (!userId && videoId) return res.redirect('/plugins/auth-openid-connect/0.1.3/auth/openid-connect')
const video = await Hooks.wrapObject(res.locals.videoAPI, 'filter:api.video.get.result', { req, id: videoId, userId })
// Filter may return null/undefined value to forbid video access
if (!video) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
if (video.isOutdated()) {
JobQueue.Instance.createJobAsync({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } })
}
return res.json(video.toFormattedDetailsJSON())
}