mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Support fowarding query params to oembed
For now only `start` for videos and `playlistPosition` for playlists are supported
This commit is contained in:
@@ -79,7 +79,11 @@ function buildPlayerURLQuery (inputQueryUrl: string) {
|
||||
'subtitle',
|
||||
'bigPlayBackgroundColor',
|
||||
'mode',
|
||||
'foregroundColor'
|
||||
'foregroundColor',
|
||||
'playbackRate',
|
||||
'api',
|
||||
'waitPasswordFromEmbedAPI',
|
||||
'playlistPosition'
|
||||
])
|
||||
|
||||
const params = new URLSearchParams()
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { escapeHTML } from '@peertube/peertube-core-utils'
|
||||
import { addQueryParams, escapeHTML } from '@peertube/peertube-core-utils'
|
||||
import { HttpStatusCode, VideoPlaylistPrivacy } from '@peertube/peertube-models'
|
||||
import { toCompleteUUID } from '@server/helpers/custom-validators/misc.js'
|
||||
import { Memoize } from '@server/helpers/memoize.js'
|
||||
import { VideoPlaylistModel } from '@server/models/video/video-playlist.js'
|
||||
import { MVideoPlaylist, MVideoPlaylistFull } from '@server/types/models/index.js'
|
||||
import express from 'express'
|
||||
import validator from 'validator'
|
||||
import { CONFIG } from '../../../initializers/config.js'
|
||||
import { MEMOIZE_TTL, WEBSERVER } from '../../../initializers/constants.js'
|
||||
import { Memoize } from '@server/helpers/memoize.js'
|
||||
import { VideoPlaylistModel } from '@server/models/video/video-playlist.js'
|
||||
import { MVideoPlaylistFull } from '@server/types/models/index.js'
|
||||
import { TagsHtml } from './tags-html.js'
|
||||
import { PageHtml } from './page-html.js'
|
||||
import { CommonEmbedHtml } from './common-embed-html.js'
|
||||
import { PageHtml } from './page-html.js'
|
||||
import { TagsHtml } from './tags-html.js'
|
||||
|
||||
export class PlaylistHtml {
|
||||
|
||||
@@ -39,7 +39,9 @@ export class PlaylistHtml {
|
||||
playlist: videoPlaylist,
|
||||
addEmbedInfo: true,
|
||||
addOG: true,
|
||||
addTwitterCard: true
|
||||
addTwitterCard: true,
|
||||
|
||||
currentQuery: req.query
|
||||
})
|
||||
}
|
||||
|
||||
@@ -62,7 +64,10 @@ export class PlaylistHtml {
|
||||
playlist,
|
||||
addEmbedInfo: true,
|
||||
addOG: false,
|
||||
addTwitterCard: false
|
||||
addTwitterCard: false,
|
||||
|
||||
// TODO: Implement it so we can send query params to oembed service
|
||||
currentQuery: {}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -77,8 +82,10 @@ export class PlaylistHtml {
|
||||
addOG: boolean
|
||||
addTwitterCard: boolean
|
||||
addEmbedInfo: boolean
|
||||
|
||||
currentQuery: Record<string, string>
|
||||
}) {
|
||||
const { html, playlist, addEmbedInfo, addOG, addTwitterCard } = options
|
||||
const { html, playlist, addEmbedInfo, addOG, addTwitterCard, currentQuery = {} } = options
|
||||
const escapedTruncatedDescription = TagsHtml.buildEscapedTruncatedDescription(playlist.description)
|
||||
|
||||
let htmlResult = TagsHtml.addTitleTag(html, playlist.name)
|
||||
@@ -117,7 +124,22 @@ export class PlaylistHtml {
|
||||
schemaType,
|
||||
ogType,
|
||||
twitterCard,
|
||||
embed
|
||||
|
||||
embed,
|
||||
oembedUrl: this.getOEmbedUrl(playlist, currentQuery)
|
||||
}, { playlist })
|
||||
}
|
||||
|
||||
private static getOEmbedUrl (playlist: MVideoPlaylist, currentQuery: Record<string, string>) {
|
||||
const base = WEBSERVER.URL + playlist.getWatchStaticPath()
|
||||
|
||||
const additionalQuery: Record<string, string> = {}
|
||||
const allowedParams = new Set([ 'playlistPosition' ])
|
||||
|
||||
for (const [ key, value ] of Object.entries(currentQuery)) {
|
||||
if (allowedParams.has(key)) additionalQuery[key] = value
|
||||
}
|
||||
|
||||
return addQueryParams(base, additionalQuery)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,8 @@ type Tags = {
|
||||
duration?: string
|
||||
views?: number
|
||||
}
|
||||
|
||||
oembedUrl?: string
|
||||
}
|
||||
|
||||
type HookContext = {
|
||||
@@ -74,14 +76,14 @@ export class TagsHtml {
|
||||
const twitterCardMetaTags = this.generateTwitterCardMetaTagsOptions(tagsValues)
|
||||
const schemaTags = await this.generateSchemaTagsOptions(tagsValues, context)
|
||||
|
||||
const { url, escapedTitle, embed, indexationPolicy } = tagsValues
|
||||
const { url, escapedTitle, oembedUrl, indexationPolicy } = tagsValues
|
||||
|
||||
const oembedLinkTags: { type: string, href: string, escapedTitle: string }[] = []
|
||||
|
||||
if (embed) {
|
||||
if (oembedUrl) {
|
||||
oembedLinkTags.push({
|
||||
type: 'application/json+oembed',
|
||||
href: WEBSERVER.URL + '/services/oembed?url=' + encodeURIComponent(url),
|
||||
href: WEBSERVER.URL + '/services/oembed?url=' + encodeURIComponent(oembedUrl),
|
||||
escapedTitle
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { escapeHTML } from '@peertube/peertube-core-utils'
|
||||
import { addQueryParams, escapeHTML } from '@peertube/peertube-core-utils'
|
||||
import { HttpStatusCode, VideoPrivacy } from '@peertube/peertube-models'
|
||||
import { toCompleteUUID } from '@server/helpers/custom-validators/misc.js'
|
||||
import { Memoize } from '@server/helpers/memoize.js'
|
||||
@@ -39,6 +39,7 @@ export class VideoHtml {
|
||||
return this.buildVideoHTML({
|
||||
html,
|
||||
video,
|
||||
currentQuery: req.query,
|
||||
addEmbedInfo: true,
|
||||
addOG: true,
|
||||
addTwitterCard: true
|
||||
@@ -64,7 +65,10 @@ export class VideoHtml {
|
||||
video,
|
||||
addEmbedInfo: true,
|
||||
addOG: false,
|
||||
addTwitterCard: false
|
||||
addTwitterCard: false,
|
||||
|
||||
// TODO: Implement it so we can send query params to oembed service
|
||||
currentQuery: {}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -79,8 +83,10 @@ export class VideoHtml {
|
||||
addOG: boolean
|
||||
addTwitterCard: boolean
|
||||
addEmbedInfo: boolean
|
||||
|
||||
currentQuery: Record<string, string>
|
||||
}) {
|
||||
const { html, video, addEmbedInfo, addOG, addTwitterCard } = options
|
||||
const { html, video, addEmbedInfo, addOG, addTwitterCard, currentQuery = {} } = options
|
||||
const escapedTruncatedDescription = TagsHtml.buildEscapedTruncatedDescription(video.description)
|
||||
|
||||
let customHTML = TagsHtml.addTitleTag(html, video.name)
|
||||
@@ -107,6 +113,7 @@ export class VideoHtml {
|
||||
|
||||
return TagsHtml.addTags(customHTML, {
|
||||
url: WEBSERVER.URL + video.getWatchStaticPath(),
|
||||
|
||||
escapedSiteName: escapeHTML(CONFIG.INSTANCE.NAME),
|
||||
escapedTitle: escapeHTML(video.name),
|
||||
escapedTruncatedDescription,
|
||||
@@ -118,9 +125,24 @@ export class VideoHtml {
|
||||
image: { url: WEBSERVER.URL + video.getPreviewStaticPath() },
|
||||
|
||||
embed,
|
||||
oembedUrl: this.getOEmbedUrl(video, currentQuery),
|
||||
|
||||
ogType,
|
||||
twitterCard,
|
||||
schemaType
|
||||
}, { video })
|
||||
}
|
||||
|
||||
private static getOEmbedUrl (video: MVideo, currentQuery: Record<string, string>) {
|
||||
const base = WEBSERVER.URL + video.getWatchStaticPath()
|
||||
|
||||
const additionalQuery: Record<string, string> = {}
|
||||
const allowedParams = new Set([ 'start' ])
|
||||
|
||||
for (const [ key, value ] of Object.entries(currentQuery)) {
|
||||
if (allowedParams.has(key)) additionalQuery[key] = value
|
||||
}
|
||||
|
||||
return addQueryParams(base, additionalQuery)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user