]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/static.ts
Live views update
[github/Chocobozzz/PeerTube.git] / server / controllers / static.ts
index e04c27b11e174c0a51bb0332138d97def56d8af7..f12f00e1bba3fcbf72ecd89a4939c66018513ce7 100644 (file)
@@ -26,6 +26,8 @@ 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'
+import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
+import { serveIndexHTML } from '@server/lib/client-html'
 
 const staticRouter = express.Router()
 
@@ -118,10 +120,15 @@ staticRouter.get('/robots.txt',
   }
 )
 
+staticRouter.all('/teapot',
+  getCup,
+  asyncMiddleware(serveIndexHTML)
+)
+
 // security.txt service
 staticRouter.get('/security.txt',
   (_, res: express.Response) => {
-    return res.redirect(301, '/.well-known/security.txt')
+    return res.redirect(HttpStatusCode.MOVED_PERMANENTLY_301, '/.well-known/security.txt')
   }
 )
 
@@ -331,7 +338,7 @@ async function generateNodeinfo (req: express.Request, res: express.Response) {
     res.contentType('application/json; profile="http://nodeinfo.diaspora.software/ns/schema/2.0#"')
   } else {
     json = { error: 'Nodeinfo schema version not handled' }
-    res.status(404)
+    res.status(HttpStatusCode.NOT_FOUND_404)
   }
 
   return res.send(json).end()
@@ -341,7 +348,7 @@ 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()
+  if (!videoFile) return res.status(HttpStatusCode.NOT_FOUND_404).end()
 
   return res.download(getTorrentFilePath(video, videoFile), `${video.name}-${videoFile.resolution}p.torrent`)
 }
@@ -350,10 +357,10 @@ function downloadHLSVideoFileTorrent (req: express.Request, res: express.Respons
   const video = res.locals.videoAll
 
   const playlist = getHLSPlaylist(video)
-  if (!playlist) return res.status(404).end
+  if (!playlist) return res.status(HttpStatusCode.NOT_FOUND_404).end
 
   const videoFile = getVideoFile(req, playlist.VideoFiles)
-  if (!videoFile) return res.status(404).end()
+  if (!videoFile) return res.status(HttpStatusCode.NOT_FOUND_404).end()
 
   return res.download(getTorrentFilePath(playlist, videoFile), `${video.name}-${videoFile.resolution}p-hls.torrent`)
 }
@@ -362,7 +369,7 @@ 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()
+  if (!videoFile) return res.status(HttpStatusCode.NOT_FOUND_404).end()
 
   return res.download(getVideoFilePath(video, videoFile), `${video.name}-${videoFile.resolution}p${videoFile.extname}`)
 }
@@ -370,10 +377,10 @@ function downloadVideoFile (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
+  if (!playlist) return res.status(HttpStatusCode.NOT_FOUND_404).end
 
   const videoFile = getVideoFile(req, playlist.VideoFiles)
-  if (!videoFile) return res.status(404).end()
+  if (!videoFile) return res.status(HttpStatusCode.NOT_FOUND_404).end()
 
   const filename = `${video.name}-${videoFile.resolution}p-${playlist.getStringType()}${videoFile.extname}`
   return res.download(getVideoFilePath(playlist, videoFile), filename)
@@ -390,3 +397,11 @@ function getHLSPlaylist (video: MVideoFullLight) {
 
   return Object.assign(playlist, { Video: video })
 }
+
+function getCup (req: express.Request, res: express.Response, next: express.NextFunction) {
+  res.status(HttpStatusCode.I_AM_A_TEAPOT_418)
+  res.setHeader('Accept-Additions', 'Non-Dairy;1,Sugar;1')
+  res.setHeader('Safe', 'if-sepia-awake')
+
+  return next()
+}