Change tab when changing follow url
[oweals/peertube.git] / server / controllers / static.ts
index 8fbf9cc9741b209933472a7a21f0af526ef29f67..7425fd0973d5c3b9a1fdbb06f175129fafb52f0a 100644 (file)
@@ -7,11 +7,12 @@ import {
   STATIC_PATHS
 } from '../initializers'
 import { VideosPreviewCache } from '../lib'
+import { asyncMiddleware } from '../middlewares'
 
 const staticRouter = express.Router()
 
 /*
-  Cors is very important to let other pods access torrent and video files
+  Cors is very important to let other servers access torrent and video files
 */
 
 const torrentsPhysicalPath = CONFIG.STORAGE.TORRENTS_DIR
@@ -39,7 +40,7 @@ staticRouter.use(
 // Video previews path for express
 staticRouter.use(
   STATIC_PATHS.PREVIEWS + ':uuid.jpg',
-  getPreview
+  asyncMiddleware(getPreview)
 )
 
 // ---------------------------------------------------------------------------
@@ -50,11 +51,9 @@ export {
 
 // ---------------------------------------------------------------------------
 
-function getPreview (req: express.Request, res: express.Response, next: express.NextFunction) {
-  VideosPreviewCache.Instance.getPreviewPath(req.params.uuid)
-    .then(path => {
-      if (!path) return res.sendStatus(404)
+async function getPreview (req: express.Request, res: express.Response, next: express.NextFunction) {
+  const path = await VideosPreviewCache.Instance.getPreviewPath(req.params.uuid)
+  if (!path) return res.sendStatus(404)
 
-      return res.sendFile(path, { maxAge: STATIC_MAX_AGE })
-    })
+  return res.sendFile(path, { maxAge: STATIC_MAX_AGE })
 }