-
-// ---------------------------------------------------------------------------
-
-async function generateNodeinfo (req: express.Request, res: express.Response) {
- 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: PEERTUBE_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,
- nodeConfig: {
- search: {
- remoteUri: {
- users: CONFIG.SEARCH.REMOTE_URI.USERS,
- anonymous: CONFIG.SEARCH.REMOTE_URI.ANONYMOUS
- }
- },
- plugin: {
- registered: getRegisteredPlugins()
- },
- theme: {
- registered: getRegisteredThemes(),
- default: getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME)
- },
- email: {
- enabled: Emailer.isEnabled()
- },
- contactForm: {
- enabled: CONFIG.CONTACT_FORM.ENABLED
- },
- transcoding: {
- hls: {
- enabled: CONFIG.TRANSCODING.HLS.ENABLED
- },
- webtorrent: {
- enabled: CONFIG.TRANSCODING.WEBTORRENT.ENABLED
- },
- enabledResolutions: getEnabledResolutions()
- },
- import: {
- videos: {
- http: {
- enabled: CONFIG.IMPORT.VIDEOS.HTTP.ENABLED
- },
- torrent: {
- enabled: CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED
- }
- }
- },
- autoBlacklist: {
- videos: {
- ofUsers: {
- enabled: CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED
- }
- }
- },
- avatar: {
- file: {
- size: {
- max: CONSTRAINTS_FIELDS.ACTORS.AVATAR.FILE_SIZE.max
- },
- extensions: CONSTRAINTS_FIELDS.ACTORS.AVATAR.EXTNAME
- }
- },
- video: {
- image: {
- extensions: CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME,
- size: {
- max: CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max
- }
- },
- file: {
- extensions: CONSTRAINTS_FIELDS.VIDEOS.EXTNAME
- }
- },
- videoCaption: {
- file: {
- size: {
- max: CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max
- },
- extensions: CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.EXTNAME
- }
- },
- user: {
- videoQuota: CONFIG.USER.VIDEO_QUOTA,
- videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY
- },
- trending: {
- videos: {
- intervalDays: CONFIG.TRENDING.VIDEOS.INTERVAL_DAYS
- }
- },
- tracker: {
- enabled: CONFIG.TRACKER.ENABLED
- }
- }
- }
- } 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()
-}
-
-function downloadTorrent (req: express.Request, res: express.Response) {
- const video = res.locals.videoAll
-
- const videoFile = getVideoFile(req, video.VideoFiles)
- if (!videoFile) return res.status(404).end()
-
- return res.download(getTorrentFilePath(video, videoFile), `${video.name}-${videoFile.resolution}p.torrent`)
-}
-
-function downloadHLSVideoFileTorrent (req: express.Request, res: express.Response) {
- const video = res.locals.videoAll
-
- const playlist = getHLSPlaylist(video)
- if (!playlist) return res.status(404).end
-
- const videoFile = getVideoFile(req, playlist.VideoFiles)
- if (!videoFile) return res.status(404).end()
-
- return res.download(getTorrentFilePath(playlist, videoFile), `${video.name}-${videoFile.resolution}p-hls.torrent`)
-}
-
-function downloadVideoFile (req: express.Request, res: express.Response) {
- const video = res.locals.videoAll
-
- const videoFile = getVideoFile(req, video.VideoFiles)
- if (!videoFile) return res.status(404).end()
-
- return res.download(getVideoFilePath(video, videoFile), `${video.name}-${videoFile.resolution}p${videoFile.extname}`)
-}
-
-function downloadHLSVideoFile (req: express.Request, res: express.Response) {
- const video = res.locals.videoAll
- const playlist = getHLSPlaylist(video)
- if (!playlist) return res.status(404).end
-
- const videoFile = getVideoFile(req, playlist.VideoFiles)
- if (!videoFile) return res.status(404).end()
-
- const filename = `${video.name}-${videoFile.resolution}p-${playlist.getStringType()}${videoFile.extname}`
- return res.download(getVideoFilePath(playlist, videoFile), filename)
-}
-
-function getVideoFile (req: express.Request, files: MVideoFile[]) {
- const resolution = parseInt(req.params.resolution, 10)
- return files.find(f => f.resolution === resolution)
-}
-
-function getHLSPlaylist (video: MVideoFullLight) {
- const playlist = video.VideoStreamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
- if (!playlist) return undefined
-
- return Object.assign(playlist, { Video: video })
-}