diff options
Diffstat (limited to 'server/controllers/client.ts')
-rw-r--r-- | server/controllers/client.ts | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/server/controllers/client.ts b/server/controllers/client.ts index 503eff750..e4d69eae7 100644 --- a/server/controllers/client.ts +++ b/server/controllers/client.ts | |||
@@ -1,8 +1,7 @@ | |||
1 | import { parallel } from 'async' | ||
2 | import * as express from 'express' | 1 | import * as express from 'express' |
3 | import * as fs from 'fs' | ||
4 | import { join } from 'path' | 2 | import { join } from 'path' |
5 | import * as validator from 'validator' | 3 | import * as validator from 'validator' |
4 | import * as Promise from 'bluebird' | ||
6 | 5 | ||
7 | import { database as db } from '../initializers/database' | 6 | import { database as db } from '../initializers/database' |
8 | import { | 7 | import { |
@@ -11,7 +10,7 @@ import { | |||
11 | STATIC_PATHS, | 10 | STATIC_PATHS, |
12 | STATIC_MAX_AGE | 11 | STATIC_MAX_AGE |
13 | } from '../initializers' | 12 | } from '../initializers' |
14 | import { root } from '../helpers' | 13 | import { root, readFileBufferPromise } from '../helpers' |
15 | import { VideoInstance } from '../models' | 14 | import { VideoInstance } from '../models' |
16 | 15 | ||
17 | const clientsRouter = express.Router() | 16 | const clientsRouter = express.Router() |
@@ -95,19 +94,15 @@ function generateWatchHtmlPage (req: express.Request, res: express.Response, nex | |||
95 | // Let Angular application handle errors | 94 | // Let Angular application handle errors |
96 | if (!validator.isUUID(videoId, 4)) return res.sendFile(indexPath) | 95 | if (!validator.isUUID(videoId, 4)) return res.sendFile(indexPath) |
97 | 96 | ||
98 | parallel({ | 97 | Promise.all([ |
99 | file: function (callback) { | 98 | readFileBufferPromise(indexPath), |
100 | fs.readFile(indexPath, callback) | 99 | db.Video.loadAndPopulateAuthorAndPodAndTags(videoId) |
101 | }, | 100 | ]) |
101 | .then(([ file, video ]) => { | ||
102 | file = file as Buffer | ||
103 | video = video as VideoInstance | ||
102 | 104 | ||
103 | video: function (callback) { | 105 | const html = file.toString() |
104 | db.Video.loadAndPopulateAuthorAndPodAndTags(videoId, callback) | ||
105 | } | ||
106 | }, function (err: Error, result: { file: Buffer, video: VideoInstance }) { | ||
107 | if (err) return next(err) | ||
108 | |||
109 | const html = result.file.toString() | ||
110 | const video = result.video | ||
111 | 106 | ||
112 | // Let Angular application handle errors | 107 | // Let Angular application handle errors |
113 | if (!video) return res.sendFile(indexPath) | 108 | if (!video) return res.sendFile(indexPath) |
@@ -115,4 +110,5 @@ function generateWatchHtmlPage (req: express.Request, res: express.Response, nex | |||
115 | const htmlStringPageWithTags = addOpenGraphTags(html, video) | 110 | const htmlStringPageWithTags = addOpenGraphTags(html, video) |
116 | res.set('Content-Type', 'text/html; charset=UTF-8').send(htmlStringPageWithTags) | 111 | res.set('Content-Type', 'text/html; charset=UTF-8').send(htmlStringPageWithTags) |
117 | }) | 112 | }) |
113 | .catch(err => next(err)) | ||
118 | } | 114 | } |