X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fclient.ts;h=e3c9620588f3ae368b9a8965ad8b037edf325646;hb=d8755eed1e452d2efbfc983af0e9d228d152bf6b;hp=d913f81b808faaed80e76f0fce76a334168fd580;hpb=075f16caac5236cb04c98ae7b3a989766d764bb3;p=github%2FChocobozzz%2FPeerTube.git
diff --git a/server/controllers/client.ts b/server/controllers/client.ts
index d913f81b8..e3c962058 100644
--- a/server/controllers/client.ts
+++ b/server/controllers/client.ts
@@ -6,10 +6,9 @@ import * as Promise from 'bluebird'
import { database as db } from '../initializers/database'
import {
CONFIG,
- REMOTE_SCHEME,
STATIC_PATHS,
STATIC_MAX_AGE,
- OPENGRAPH_COMMENT
+ OPENGRAPH_AND_OEMBED_COMMENT
} from '../initializers'
import { root, readFileBufferPromise } from '../helpers'
import { VideoInstance } from '../models'
@@ -20,7 +19,7 @@ const distPath = join(root(), 'client', 'dist')
const embedPath = join(distPath, 'standalone', 'videos', 'embed.html')
const indexPath = join(distPath, 'index.html')
-// Special route that add OpenGraph tags
+// Special route that add OpenGraph and oEmbed tags
// Do not use a template engine for a so little thing
clientsRouter.use('/videos/watch/:id', generateWatchHtmlPage)
@@ -44,22 +43,11 @@ export {
// ---------------------------------------------------------------------------
-function addOpenGraphTags (htmlStringPage: string, video: VideoInstance) {
- let basePreviewUrlHttp
+function addOpenGraphAndOEmbedTags (htmlStringPage: string, video: VideoInstance) {
+ const previewUrl = CONFIG.WEBSERVER.URL + STATIC_PATHS.PREVIEWS + video.getPreviewName()
+ const videoUrl = CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid
- if (video.isOwned()) {
- basePreviewUrlHttp = CONFIG.WEBSERVER.URL
- } else {
- basePreviewUrlHttp = REMOTE_SCHEME.HTTP + '://' + video.Author.Pod.host
- }
-
- // We fetch the remote preview (bigger than the thumbnail)
- // This should not overhead the remote server since social websites put in a cache the OpenGraph tags
- // We can't use the thumbnail because these social websites want bigger images (> 200x200 for Facebook for example)
- const previewUrl = basePreviewUrlHttp + STATIC_PATHS.PREVIEWS + video.getPreviewName()
- const videoUrl = CONFIG.WEBSERVER.URL + '/videos/watch/' + video.id
-
- const metaTags = {
+ const openGraphMetaTags = {
'og:type': 'video',
'og:title': video.name,
'og:image': previewUrl,
@@ -77,14 +65,26 @@ function addOpenGraphTags (htmlStringPage: string, video: VideoInstance) {
'twitter:image': previewUrl
}
+ const oembedLinkTags = [
+ {
+ type: 'application/json+oembed',
+ href: CONFIG.WEBSERVER.URL + '/services/oembed?url=' + encodeURIComponent(videoUrl),
+ title: video.name
+ }
+ ]
+
let tagsString = ''
- Object.keys(metaTags).forEach(tagName => {
- const tagValue = metaTags[tagName]
+ Object.keys(openGraphMetaTags).forEach(tagName => {
+ const tagValue = openGraphMetaTags[tagName]
- tagsString += ''
+ tagsString += ``
})
- return htmlStringPage.replace(OPENGRAPH_COMMENT, tagsString)
+ for (const oembedLinkTag of oembedLinkTags) {
+ tagsString += ``
+ }
+
+ return htmlStringPage.replace(OPENGRAPH_AND_OEMBED_COMMENT, tagsString)
}
function generateWatchHtmlPage (req: express.Request, res: express.Response, next: express.NextFunction) {
@@ -113,7 +113,7 @@ function generateWatchHtmlPage (req: express.Request, res: express.Response, nex
// Let Angular application handle errors
if (!video) return res.sendFile(indexPath)
- const htmlStringPageWithTags = addOpenGraphTags(html, video)
+ const htmlStringPageWithTags = addOpenGraphAndOEmbedTags(html, video)
res.set('Content-Type', 'text/html; charset=UTF-8').send(htmlStringPageWithTags)
})
.catch(err => next(err))