+
+ const url = WEBSERVER.URL + video.getWatchStaticPath()
+ const originUrl = video.url
+ const title = escapeHTML(video.name)
+ const siteName = escapeHTML(CONFIG.INSTANCE.NAME)
+ const description = escapeHTML(video.description)
+
+ const image = {
+ url: WEBSERVER.URL + video.getPreviewStaticPath()
+ }
+
+ const embed = {
+ url: WEBSERVER.URL + video.getEmbedStaticPath(),
+ createdAt: video.createdAt.toISOString(),
+ duration: getActivityStreamDuration(video.duration),
+ views: video.views
+ }
+
+ const ogType = 'video'
+ const twitterCard = CONFIG.SERVICES.TWITTER.WHITELISTED ? 'player' : 'summary_large_image'
+ const schemaType = 'VideoObject'
+
+ customHtml = ClientHtml.addTags(customHtml, {
+ url,
+ originUrl,
+ siteName,
+ title,
+ description,
+ image,
+ embed,
+ ogType,
+ twitterCard,
+ schemaType
+ })
+
+ return customHtml
+ }
+
+ static async getWatchPlaylistHTMLPage (videoPlaylistId: string, req: express.Request, res: express.Response) {
+ // Let Angular application handle errors
+ if (!validator.isInt(videoPlaylistId) && !validator.isUUID(videoPlaylistId, 4)) {
+ res.status(HttpStatusCode.NOT_FOUND_404)
+ return ClientHtml.getIndexHTML(req, res)
+ }
+
+ const [ html, videoPlaylist ] = await Promise.all([
+ ClientHtml.getIndexHTML(req, res),
+ VideoPlaylistModel.loadWithAccountAndChannel(videoPlaylistId, null)
+ ])
+
+ // Let Angular application handle errors
+ if (!videoPlaylist || videoPlaylist.privacy === VideoPlaylistPrivacy.PRIVATE) {
+ res.status(HttpStatusCode.NOT_FOUND_404)
+ return html
+ }
+
+ let customHtml = ClientHtml.addTitleTag(html, escapeHTML(videoPlaylist.name))
+ customHtml = ClientHtml.addDescriptionTag(customHtml, escapeHTML(videoPlaylist.description))
+
+ const url = videoPlaylist.getWatchUrl()
+ const originUrl = videoPlaylist.url
+ const title = escapeHTML(videoPlaylist.name)
+ const siteName = escapeHTML(CONFIG.INSTANCE.NAME)
+ const description = escapeHTML(videoPlaylist.description)
+
+ const image = {
+ url: videoPlaylist.getThumbnailUrl()
+ }
+
+ const embed = {
+ url: WEBSERVER.URL + videoPlaylist.getEmbedStaticPath(),
+ createdAt: videoPlaylist.createdAt.toISOString()
+ }
+
+ const list = {
+ numberOfItems: videoPlaylist.get('videosLength') as number
+ }
+
+ const ogType = 'video'
+ const twitterCard = CONFIG.SERVICES.TWITTER.WHITELISTED ? 'player' : 'summary'
+ const schemaType = 'ItemList'
+
+ customHtml = ClientHtml.addTags(customHtml, {
+ url,
+ originUrl,
+ siteName,
+ embed,
+ title,
+ description,
+ image,
+ list,
+ ogType,
+ twitterCard,
+ schemaType
+ })
+
+ return customHtml
+ }
+
+ static async getAccountHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
+ return this.getAccountOrChannelHTMLPage(() => AccountModel.loadByNameWithHost(nameWithHost), req, res)
+ }
+
+ static async getVideoChannelHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
+ return this.getAccountOrChannelHTMLPage(() => VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithHost), req, res)
+ }
+
+ static async getEmbedHTML () {
+ const path = ClientHtml.getEmbedPath()
+
+ if (!isTestInstance() && ClientHtml.htmlCache[path]) return ClientHtml.htmlCache[path]
+
+ const buffer = await readFile(path)
+
+ let html = buffer.toString()
+ html = await ClientHtml.addAsyncPluginCSS(html)
+ html = ClientHtml.addCustomCSS(html)
+ html = ClientHtml.addTitleTag(html)
+
+ ClientHtml.htmlCache[path] = html
+
+ return html
+ }
+
+ private static async getAccountOrChannelHTMLPage (
+ loader: () => Promise<MAccountActor | MChannelActor>,
+ req: express.Request,
+ res: express.Response
+ ) {
+ const [ html, entity ] = await Promise.all([
+ ClientHtml.getIndexHTML(req, res),
+ loader()
+ ])
+
+ // Let Angular application handle errors
+ if (!entity) {
+ res.status(HttpStatusCode.NOT_FOUND_404)
+ return ClientHtml.getIndexHTML(req, res)
+ }
+
+ let customHtml = ClientHtml.addTitleTag(html, escapeHTML(entity.getDisplayName()))
+ customHtml = ClientHtml.addDescriptionTag(customHtml, escapeHTML(entity.description))
+
+ const url = entity.getLocalUrl()
+ const originUrl = entity.Actor.url
+ const siteName = escapeHTML(CONFIG.INSTANCE.NAME)
+ const title = escapeHTML(entity.getDisplayName())
+ const description = escapeHTML(entity.description)
+
+ const image = {
+ url: entity.Actor.getAvatarUrl(),
+ width: AVATARS_SIZE.width,
+ height: AVATARS_SIZE.height
+ }
+
+ const ogType = 'website'
+ const twitterCard = 'summary'
+ const schemaType = 'ProfilePage'
+
+ customHtml = ClientHtml.addTags(customHtml, {
+ url,
+ originUrl,
+ title,
+ siteName,
+ description,
+ image,
+ ogType,
+ twitterCard,
+ schemaType
+ })