+ 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 generateNodeinfo (req: express.Request, res: express.Response, next: express.NextFunction) {
+ const { totalVideos } = await VideoModel.getStats()
+ const { totalLocalVideoComments } = await VideoCommentModel.getStats()
+ const { totalUsers } = await UserModel.getStats()
+ let json = {}
+
+ if (req.params.version && (req.params.version === '2.0')) {
+ json = {
+ version: '2.0',
+ software: {
+ name: 'peertube',
+ version: packageJSON.version
+ },
+ protocols: [
+ 'activitypub'
+ ],
+ services: {
+ inbound: [],
+ outbound: [
+ 'atom1.0',
+ 'rss2.0'
+ ]
+ },
+ openRegistrations: CONFIG.SIGNUP.ENABLED,
+ usage: {
+ users: {
+ total: totalUsers
+ },
+ localPosts: totalVideos,
+ localComments: totalLocalVideoComments
+ },
+ metadata: {
+ taxonomy: {
+ postsName: 'Videos'
+ },
+ nodeName: CONFIG.INSTANCE.NAME,
+ nodeDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION
+ }
+ } as HttpNodeinfoDiasporaSoftwareNsSchema20
+ res.contentType('application/json; profile="http://nodeinfo.diaspora.software/ns/schema/2.0#"')
+ } else {
+ json = { error: 'Nodeinfo schema version not handled' }
+ res.status(404)
+ }
+
+ return res.send(json).end()
+}
+
+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
+
+ const videoFile = video.VideoFiles.find(f => f.resolution === resolution)
+
+ return { video, videoFile }