X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fstatic.ts;h=3f7bbdbae2f79f71d8ae0c447fb23f50d60d4a37;hb=7b3909644dd7cb8be1caad537bb40605e5f059d4;hp=f86a0cb5b0a12c45f11cc478f30b4809be8a96b7;hpb=174e0855873d7086ad8240599101c2f717ebbd59;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/static.ts b/server/controllers/static.ts index f86a0cb5b..3f7bbdbae 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts @@ -1,15 +1,15 @@ import * as cors from 'cors' import * as express from 'express' import { + CONSTRAINTS_FIELDS, + DEFAULT_THEME_NAME, HLS_STREAMING_PLAYLIST_DIRECTORY, PEERTUBE_VERSION, ROUTE_CACHE_LIFETIME, STATIC_DOWNLOAD_PATHS, STATIC_MAX_AGE, STATIC_PATHS, - WEBSERVER, - CONSTRAINTS_FIELDS, - DEFAULT_THEME_NAME + WEBSERVER } from '../initializers/constants' import { cacheRoute } from '../middlewares/cache' import { asyncMiddleware, videosDownloadValidator } from '../middlewares' @@ -19,11 +19,10 @@ import { VideoCommentModel } from '../models/video/video-comment' import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/nodeinfo' import { join } from 'path' import { root } from '../helpers/core-utils' -import { CONFIG } from '../initializers/config' -import { Emailer } from '../lib/emailer' +import { CONFIG, isEmailEnabled } from '../initializers/config' import { getPreview, getVideoCaption } from './lazy-static' import { VideoStreamingPlaylistType } from '@shared/models/videos/video-streaming-playlist.type' -import { MVideoFile, MVideoFullLight } from '@server/typings/models' +import { MVideoFile, MVideoFullLight } from '@server/types/models' import { getTorrentFilePath, getVideoFilePath } from '@server/lib/video-paths' import { getThemeOrDefault } from '../lib/plugins/theme-utils' import { getEnabledResolutions, getRegisteredPlugins, getRegisteredThemes } from '@server/controllers/api/config' @@ -45,12 +44,12 @@ staticRouter.use( staticRouter.use( STATIC_DOWNLOAD_PATHS.TORRENTS + ':id-:resolution([0-9]+).torrent', asyncMiddleware(videosDownloadValidator), - asyncMiddleware(downloadTorrent) + downloadTorrent ) staticRouter.use( STATIC_DOWNLOAD_PATHS.TORRENTS + ':id-:resolution([0-9]+)-hls.torrent', asyncMiddleware(videosDownloadValidator), - asyncMiddleware(downloadHLSVideoFileTorrent) + downloadHLSVideoFileTorrent ) // Videos path for webseeding @@ -68,13 +67,13 @@ staticRouter.use( staticRouter.use( STATIC_DOWNLOAD_PATHS.VIDEOS + ':id-:resolution([0-9]+).:extension', asyncMiddleware(videosDownloadValidator), - asyncMiddleware(downloadVideoFile) + downloadVideoFile ) staticRouter.use( STATIC_DOWNLOAD_PATHS.HLS_VIDEOS + ':id-:resolution([0-9]+)-fragmented.:extension', asyncMiddleware(videosDownloadValidator), - asyncMiddleware(downloadHLSVideoFile) + downloadHLSVideoFile ) // HLS @@ -112,7 +111,7 @@ staticRouter.use( // robots.txt service staticRouter.get('/robots.txt', - asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.ROBOTS)), + asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.ROBOTS)), (_, res: express.Response) => { res.type('text/plain') return res.send(CONFIG.INSTANCE.ROBOTS) @@ -127,7 +126,7 @@ staticRouter.get('/security.txt', ) staticRouter.get('/.well-known/security.txt', - asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.SECURITYTXT)), + asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.SECURITYTXT)), (_, res: express.Response) => { res.type('text/plain') return res.send(CONFIG.INSTANCE.SECURITYTXT + CONFIG.INSTANCE.SECURITYTXT_CONTACT) @@ -136,7 +135,7 @@ staticRouter.get('/.well-known/security.txt', // nodeinfo service staticRouter.use('/.well-known/nodeinfo', - asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.NODEINFO)), + asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.NODEINFO)), (_, res: express.Response) => { return res.json({ links: [ @@ -149,13 +148,13 @@ staticRouter.use('/.well-known/nodeinfo', } ) staticRouter.use('/nodeinfo/:version.json', - asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.NODEINFO)), + asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.NODEINFO)), asyncMiddleware(generateNodeinfo) ) // dnt-policy.txt service (see https://www.eff.org/dnt-policy) staticRouter.use('/.well-known/dnt-policy.txt', - asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.DNT_POLICY)), + asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.DNT_POLICY)), (_, res: express.Response) => { res.type('text/plain') @@ -235,6 +234,12 @@ async function generateNodeinfo (req: express.Request, res: express.Response) { 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() }, @@ -243,7 +248,7 @@ async function generateNodeinfo (req: express.Request, res: express.Response) { default: getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME) }, email: { - enabled: Emailer.isEnabled() + enabled: isEmailEnabled() }, contactForm: { enabled: CONFIG.CONTACT_FORM.ENABLED @@ -325,7 +330,7 @@ async function generateNodeinfo (req: express.Request, res: express.Response) { return res.send(json).end() } -async function downloadTorrent (req: express.Request, res: express.Response) { +function downloadTorrent (req: express.Request, res: express.Response) { const video = res.locals.videoAll const videoFile = getVideoFile(req, video.VideoFiles) @@ -334,7 +339,7 @@ async function downloadTorrent (req: express.Request, res: express.Response) { return res.download(getTorrentFilePath(video, videoFile), `${video.name}-${videoFile.resolution}p.torrent`) } -async function downloadHLSVideoFileTorrent (req: express.Request, res: express.Response) { +function downloadHLSVideoFileTorrent (req: express.Request, res: express.Response) { const video = res.locals.videoAll const playlist = getHLSPlaylist(video) @@ -346,7 +351,7 @@ async function downloadHLSVideoFileTorrent (req: express.Request, res: express.R return res.download(getTorrentFilePath(playlist, videoFile), `${video.name}-${videoFile.resolution}p-hls.torrent`) } -async function downloadVideoFile (req: express.Request, res: express.Response) { +function downloadVideoFile (req: express.Request, res: express.Response) { const video = res.locals.videoAll const videoFile = getVideoFile(req, video.VideoFiles) @@ -355,7 +360,7 @@ async function downloadVideoFile (req: express.Request, res: express.Response) { return res.download(getVideoFilePath(video, videoFile), `${video.name}-${videoFile.resolution}p${videoFile.extname}`) } -async function downloadHLSVideoFile (req: express.Request, res: express.Response) { +function downloadHLSVideoFile (req: express.Request, res: express.Response) { const video = res.locals.videoAll const playlist = getHLSPlaylist(video) if (!playlist) return res.status(404).end