aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/services.ts
diff options
context:
space:
mode:
authorDurgaraj Karki <raazkarkee405@gmail.com>2022-06-21 18:23:15 +0545
committerGitHub <noreply@github.com>2022-06-21 14:38:15 +0200
commitc8bac5396c4ed9ee82e0ef97b9051e9065d6a147 (patch)
treed3960b41819a260268a9f9dd097a2a36e510dcca /server/controllers/services.ts
parent6e391224d48e76bb2b26267dc3a8adeb27c99122 (diff)
downloadPeerTube-c8bac5396c4ed9ee82e0ef97b9051e9065d6a147.tar.gz
PeerTube-c8bac5396c4ed9ee82e0ef97b9051e9065d6a147.tar.zst
PeerTube-c8bac5396c4ed9ee82e0ef97b9051e9065d6a147.zip
fixes video not played from defined parameters in embed service (#5023)
* fixes video not played from defined parameters in embed service * adds parameters to the oembed services * Styling Co-authored-by: Chocobozzz <me@florianbigard.com>
Diffstat (limited to 'server/controllers/services.ts')
-rw-r--r--server/controllers/services.ts44
1 files changed, 39 insertions, 5 deletions
diff --git a/server/controllers/services.ts b/server/controllers/services.ts
index 9151e1b04..70d08ab69 100644
--- a/server/controllers/services.ts
+++ b/server/controllers/services.ts
@@ -1,9 +1,9 @@
1import express from 'express' 1import express from 'express'
2import { EMBED_SIZE, PREVIEWS_SIZE, WEBSERVER, THUMBNAILS_SIZE } from '../initializers/constants'
3import { asyncMiddleware, oembedValidator } from '../middlewares'
4import { accountNameWithHostGetValidator } from '../middlewares/validators'
5import { MChannelSummary } from '@server/types/models' 2import { MChannelSummary } from '@server/types/models'
6import { escapeHTML } from '@shared/core-utils/renderer' 3import { escapeHTML } from '@shared/core-utils/renderer'
4import { EMBED_SIZE, PREVIEWS_SIZE, THUMBNAILS_SIZE, WEBSERVER } from '../initializers/constants'
5import { asyncMiddleware, oembedValidator } from '../middlewares'
6import { accountNameWithHostGetValidator } from '../middlewares/validators'
7 7
8const servicesRouter = express.Router() 8const servicesRouter = express.Router()
9 9
@@ -36,7 +36,7 @@ function generatePlaylistOEmbed (req: express.Request, res: express.Response) {
36 const json = buildOEmbed({ 36 const json = buildOEmbed({
37 channel: playlist.VideoChannel, 37 channel: playlist.VideoChannel,
38 title: playlist.name, 38 title: playlist.name,
39 embedPath: playlist.getEmbedStaticPath(), 39 embedPath: playlist.getEmbedStaticPath() + buildPlayerURLQuery(req.query.url),
40 previewPath: playlist.getThumbnailStaticPath(), 40 previewPath: playlist.getThumbnailStaticPath(),
41 previewSize: THUMBNAILS_SIZE, 41 previewSize: THUMBNAILS_SIZE,
42 req 42 req
@@ -51,7 +51,7 @@ function generateVideoOEmbed (req: express.Request, res: express.Response) {
51 const json = buildOEmbed({ 51 const json = buildOEmbed({
52 channel: video.VideoChannel, 52 channel: video.VideoChannel,
53 title: video.name, 53 title: video.name,
54 embedPath: video.getEmbedStaticPath(), 54 embedPath: video.getEmbedStaticPath() + buildPlayerURLQuery(req.query.url),
55 previewPath: video.getPreviewStaticPath(), 55 previewPath: video.getPreviewStaticPath(),
56 previewSize: PREVIEWS_SIZE, 56 previewSize: PREVIEWS_SIZE,
57 req 57 req
@@ -60,6 +60,40 @@ function generateVideoOEmbed (req: express.Request, res: express.Response) {
60 return res.json(json) 60 return res.json(json)
61} 61}
62 62
63function buildPlayerURLQuery (inputQueryUrl: string) {
64 const allowedParameters = new Set([
65 'start',
66 'stop',
67 'loop',
68 'autoplay',
69 'muted',
70 'controls',
71 'controlBar',
72 'title',
73 'api',
74 'warningTitle',
75 'peertubeLink',
76 'p2p',
77 'subtitle',
78 'bigPlayBackgroundColor',
79 'mode',
80 'foregroundColor'
81 ])
82
83 const params = new URLSearchParams()
84
85 new URL(inputQueryUrl).searchParams.forEach((v, k) => {
86 if (allowedParameters.has(k)) {
87 params.append(k, v)
88 }
89 })
90
91 const stringQuery = params.toString()
92 if (!stringQuery) return ''
93
94 return '?' + stringQuery
95}
96
63function buildOEmbed (options: { 97function buildOEmbed (options: {
64 req: express.Request 98 req: express.Request
65 title: string 99 title: string