aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/client.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/client.ts')
-rw-r--r--server/controllers/client.ts26
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 @@
1import { parallel } from 'async'
2import * as express from 'express' 1import * as express from 'express'
3import * as fs from 'fs'
4import { join } from 'path' 2import { join } from 'path'
5import * as validator from 'validator' 3import * as validator from 'validator'
4import * as Promise from 'bluebird'
6 5
7import { database as db } from '../initializers/database' 6import { database as db } from '../initializers/database'
8import { 7import {
@@ -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'
14import { root } from '../helpers' 13import { root, readFileBufferPromise } from '../helpers'
15import { VideoInstance } from '../models' 14import { VideoInstance } from '../models'
16 15
17const clientsRouter = express.Router() 16const 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}