]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/controllers/client.js
3 const parallel
= require('async/parallel')
4 const express
= require('express')
5 const fs
= require('fs')
6 const mongoose
= require('mongoose')
7 const path
= require('path')
9 const constants
= require('../initializers/constants')
10 const middlewares
= require('../middlewares')
11 const validators
= middlewares
.validators
12 const validatorsVideos
= validators
.videos
14 const Video
= mongoose
.model('Video')
15 const router
= express
.Router()
17 const opengraphComment
= '<!-- opengraph tags -->'
18 const embedPath
= path
.join(__dirname
, '../../client/dist/standalone/videos/embed.html')
19 const indexPath
= path
.join(__dirname
, '../../client/dist/index.html')
21 // Special route that add OpenGraph tags
22 // Do not use a template engine for a so little thing
23 router
.use('/videos/watch/:id', validatorsVideos
.videosGet
, generateWatchHtmlPage
)
25 router
.use('/videos/embed', function (req
, res
, next
) {
26 res
.sendFile(embedPath
)
29 // ---------------------------------------------------------------------------
31 module
.exports
= router
33 // ---------------------------------------------------------------------------
35 function addOpenGraphTags (htmlStringPage
, video
) {
36 const thumbnailUrl
= constants
.CONFIG
.WEBSERVER
.URL
+ video
.thumbnailPath
37 const videoUrl
= constants
.CONFIG
.WEBSERVER
.URL
+ '/videos/watch/'
41 'og:title': video
.name
,
42 'og:image': thumbnailUrl
,
44 'og:description': video
.description
,
47 'description': video
.description
,
48 'image': thumbnailUrl
,
50 'twitter:card': 'summary_large_image',
51 'twitter:site': '@Chocobozzz',
52 'twitter:title': video
.name
,
53 'twitter:description': video
.description
,
54 'twitter:image': thumbnailUrl
58 Object
.keys(metaTags
).forEach(function (tagName
) {
59 const tagValue
= metaTags
[tagName
]
61 tagsString
+= '<meta property="' + tagName
+ '" content="' + tagValue
+ '" />'
64 return htmlStringPage
.replace(opengraphComment
, tagsString
)
67 function generateWatchHtmlPage (req
, res
, next
) {
69 file: function (callback
) {
70 fs
.readFile(indexPath
, callback
)
73 video: function (callback
) {
74 Video
.load(req
.params
.id
, callback
)
76 }, function (err
, results
) {
77 if (err
) return next(err
)
79 const html
= results
.file
.toString()
80 const video
= results
.video
.toFormatedJSON()
82 const htmlStringPageWithTags
= addOpenGraphTags(html
, video
)
83 res
.set('Content-Type', 'text/html; charset=UTF-8').send(htmlStringPageWithTags
)