Bumped to version v0.0.14-alpha
[oweals/peertube.git] / server / controllers / client.ts
index f474c4282006c65ed0b8e2f772b56cfb5518e2ed..bb02f5075e1a6af3b8bc5147988c2e2ea82b461f 100644 (file)
@@ -1,24 +1,16 @@
+import * as Bluebird from 'bluebird'
 import * as express from 'express'
 import { join } from 'path'
 import * as validator from 'validator'
-import * as Bluebird from 'bluebird'
-
-import { database as db } from '../initializers/database'
-import {
-  CONFIG,
-  STATIC_PATHS,
-  STATIC_MAX_AGE,
-  OPENGRAPH_AND_OEMBED_COMMENT,
-  EMBED_SIZE
-} from '../initializers'
-import { root, readFileBufferPromise, escapeHTML } from '../helpers'
+import { escapeHTML, readFileBufferPromise, root } from '../helpers/core-utils'
+import { CONFIG, EMBED_SIZE, OPENGRAPH_AND_OEMBED_COMMENT, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers'
 import { asyncMiddleware } from '../middlewares'
-import { VideoInstance } from '../models'
+import { VideoModel } from '../models/video/video'
 
 const clientsRouter = express.Router()
 
 const distPath = join(root(), 'client', 'dist')
-const assetsImagesPath = join(root(), 'client', 'dist', 'assets', 'images')
+const assetsImagesPath = join(root(), 'client', 'dist', 'client', 'assets', 'images')
 const embedPath = join(distPath, 'standalone', 'videos', 'embed.html')
 const indexPath = join(distPath, 'index.html')
 
@@ -49,7 +41,7 @@ export {
 
 // ---------------------------------------------------------------------------
 
-function addOpenGraphAndOEmbedTags (htmlStringPage: string, video: VideoInstance) {
+function addOpenGraphAndOEmbedTags (htmlStringPage: string, video: VideoModel) {
   const previewUrl = CONFIG.WEBSERVER.URL + STATIC_PATHS.PREVIEWS + video.getPreviewName()
   const videoUrl = CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid
 
@@ -92,6 +84,16 @@ function addOpenGraphAndOEmbedTags (htmlStringPage: string, video: VideoInstance
     }
   ]
 
+  const schemaTags = {
+    name: videoNameEscaped,
+    description: videoDescriptionEscaped,
+    duration: video.getActivityStreamDuration(),
+    thumbnailURL: previewUrl,
+    contentURL: videoUrl,
+    embedURL: embedUrl,
+    uploadDate: video.createdAt
+  }
+
   let tagsString = ''
   Object.keys(openGraphMetaTags).forEach(tagName => {
     const tagValue = openGraphMetaTags[tagName]
@@ -103,18 +105,28 @@ function addOpenGraphAndOEmbedTags (htmlStringPage: string, video: VideoInstance
     tagsString += `<link rel="alternate" type="${oembedLinkTag.type}" href="${oembedLinkTag.href}" title="${oembedLinkTag.title}" />`
   }
 
+  tagsString += '<div itemprop="video" itemscope itemtype="http://schema.org/VideoObject">'
+  tagsString += '<h2>Video: <span itemprop="name">' + schemaTags.name + '</span></h2>'
+
+  Object.keys(schemaTags).forEach(tagName => {
+    const tagValue = schemaTags[tagName]
+    tagsString += `<meta itemprop="${tagName}" content="${tagValue}" />`
+  })
+
+  tagsString += '</div>'
+
   return htmlStringPage.replace(OPENGRAPH_AND_OEMBED_COMMENT, tagsString)
 }
 
 async function generateWatchHtmlPage (req: express.Request, res: express.Response, next: express.NextFunction) {
   const videoId = '' + req.params.id
-  let videoPromise: Bluebird<VideoInstance>
+  let videoPromise: Bluebird<VideoModel>
 
   // Let Angular application handle errors
   if (validator.isUUID(videoId, 4)) {
-    videoPromise = db.Video.loadByUUIDAndPopulateAccountAndServerAndTags(videoId)
+    videoPromise = VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(videoId)
   } else if (validator.isInt(videoId)) {
-    videoPromise = db.Video.loadAndPopulateAccountAndServerAndTags(+videoId)
+    videoPromise = VideoModel.loadAndPopulateAccountAndServerAndTags(+videoId)
   } else {
     return res.sendFile(indexPath)
   }