diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-25 11:55:06 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-26 09:11:38 +0200 |
commit | eb08047657e739bcd9e592d76307befa3998482b (patch) | |
tree | fc309f51ece792fd4307c4af510710a853e1d6b2 /server/controllers/static.ts | |
parent | 5f04dd2f743961e0a06c29531cc3ccc9e4928d56 (diff) | |
download | PeerTube-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.ts | 13 |
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' |
9 | import { VideosPreviewCache } from '../lib' | 9 | import { VideosPreviewCache } from '../lib' |
10 | import { asyncMiddleware } from '../middlewares' | ||
10 | 11 | ||
11 | const staticRouter = express.Router() | 12 | const staticRouter = express.Router() |
12 | 13 | ||
@@ -39,7 +40,7 @@ staticRouter.use( | |||
39 | // Video previews path for express | 40 | // Video previews path for express |
40 | staticRouter.use( | 41 | staticRouter.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 | ||
53 | function getPreview (req: express.Request, res: express.Response, next: express.NextFunction) { | 54 | async 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 | } |