-async function getPreview (req: express.Request, res: express.Response, next: express.NextFunction) {
- const path = await VideosPreviewCache.Instance.getFilePath(req.params.uuid)
- if (!path) return res.sendStatus(404)
-
- return res.sendFile(path, { maxAge: STATIC_MAX_AGE })
-}
-
-async function getVideoCaption (req: express.Request, res: express.Response) {
- const path = await VideosCaptionCache.Instance.getFilePath({
- videoId: req.params.videoId,
- language: req.params.captionLanguage
- })
- if (!path) return res.sendStatus(404)
-
- return res.sendFile(path, { maxAge: STATIC_MAX_AGE })
-}
-
-async function downloadTorrent (req: express.Request, res: express.Response, next: express.NextFunction) {
- const { video, videoFile } = getVideoAndFile(req, res)
- if (!videoFile) return res.status(404).end()
-
- return res.download(video.getTorrentFilePath(videoFile), `${video.name}-${videoFile.resolution}p.torrent`)
-}
-
-async function downloadVideoFile (req: express.Request, res: express.Response, next: express.NextFunction) {
- const { video, videoFile } = getVideoAndFile(req, res)
- if (!videoFile) return res.status(404).end()
-
- return res.download(video.getVideoFilePath(videoFile), `${video.name}-${videoFile.resolution}p${videoFile.extname}`)
-}
-
-function getVideoAndFile (req: express.Request, res: express.Response) {
- const resolution = parseInt(req.params.resolution, 10)
- const video: VideoModel = res.locals.video