aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/static.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-25 11:55:06 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-26 09:11:38 +0200
commiteb08047657e739bcd9e592d76307befa3998482b (patch)
treefc309f51ece792fd4307c4af510710a853e1d6b2 /server/controllers/static.ts
parent5f04dd2f743961e0a06c29531cc3ccc9e4928d56 (diff)
downloadPeerTube-eb08047657e739bcd9e592d76307befa3998482b.tar.gz
PeerTube-eb08047657e739bcd9e592d76307befa3998482b.tar.zst
PeerTube-eb08047657e739bcd9e592d76307befa3998482b.zip
Use async/await in controllers
Diffstat (limited to 'server/controllers/static.ts')
-rw-r--r--server/controllers/static.ts13
1 files changed, 6 insertions, 7 deletions
diff --git a/server/controllers/static.ts b/server/controllers/static.ts
index 8fbf9cc97..c7c952d6f 100644
--- a/server/controllers/static.ts
+++ b/server/controllers/static.ts
@@ -7,6 +7,7 @@ import {
7 STATIC_PATHS 7 STATIC_PATHS
8} from '../initializers' 8} from '../initializers'
9import { VideosPreviewCache } from '../lib' 9import { VideosPreviewCache } from '../lib'
10import { asyncMiddleware } from '../middlewares'
10 11
11const staticRouter = express.Router() 12const staticRouter = express.Router()
12 13
@@ -39,7 +40,7 @@ staticRouter.use(
39// Video previews path for express 40// Video previews path for express
40staticRouter.use( 41staticRouter.use(
41 STATIC_PATHS.PREVIEWS + ':uuid.jpg', 42 STATIC_PATHS.PREVIEWS + ':uuid.jpg',
42 getPreview 43 asyncMiddleware(getPreview)
43) 44)
44 45
45// --------------------------------------------------------------------------- 46// ---------------------------------------------------------------------------
@@ -50,11 +51,9 @@ export {
50 51
51// --------------------------------------------------------------------------- 52// ---------------------------------------------------------------------------
52 53
53function getPreview (req: express.Request, res: express.Response, next: express.NextFunction) { 54async function getPreview (req: express.Request, res: express.Response, next: express.NextFunction) {
54 VideosPreviewCache.Instance.getPreviewPath(req.params.uuid) 55 const path = await VideosPreviewCache.Instance.getPreviewPath(req.params.uuid)
55 .then(path => { 56 if (!path) return res.sendStatus(404)
56 if (!path) return res.sendStatus(404)
57 57
58 return res.sendFile(path, { maxAge: STATIC_MAX_AGE }) 58 return res.sendFile(path, { maxAge: STATIC_MAX_AGE })
59 })
60} 59}