aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/services.ts44
-rw-r--r--server/tests/api/server/services.ts34
2 files changed, 64 insertions, 14 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
diff --git a/server/tests/api/server/services.ts b/server/tests/api/server/services.ts
index 5fd2abda4..2f95f953b 100644
--- a/server/tests/api/server/services.ts
+++ b/server/tests/api/server/services.ts
@@ -13,6 +13,21 @@ describe('Test services', function () {
13 let playlistDisplayName: string 13 let playlistDisplayName: string
14 let video: Video 14 let video: Video
15 15
16 const urlSuffixes = [
17 {
18 input: '',
19 output: ''
20 },
21 {
22 input: '?param=1',
23 output: ''
24 },
25 {
26 input: '?muted=1&warningTitle=0&toto=1',
27 output: '?muted=1&warningTitle=0'
28 }
29 ]
30
16 before(async function () { 31 before(async function () {
17 this.timeout(30000) 32 this.timeout(30000)
18 33
@@ -52,14 +67,15 @@ describe('Test services', function () {
52 67
53 it('Should have a valid oEmbed video response', async function () { 68 it('Should have a valid oEmbed video response', async function () {
54 for (const basePath of [ '/videos/watch/', '/w/' ]) { 69 for (const basePath of [ '/videos/watch/', '/w/' ]) {
55 for (const suffix of [ '', '?param=1' ]) { 70 for (const suffix of urlSuffixes) {
56 const oembedUrl = server.url + basePath + video.uuid + suffix 71 const oembedUrl = server.url + basePath + video.uuid + suffix.input
57 72
58 const res = await server.services.getOEmbed({ oembedUrl }) 73 const res = await server.services.getOEmbed({ oembedUrl })
59 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" ' + 74 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" ' +
60 `title="${video.name}" src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` + 75 `title="${video.name}" src="http://${server.host}/videos/embed/${video.uuid}${suffix.output}" ` +
61 'frameborder="0" allowfullscreen></iframe>' 76 'frameborder="0" allowfullscreen></iframe>'
62 const expectedThumbnailUrl = 'http://localhost:' + server.port + video.previewPath 77
78 const expectedThumbnailUrl = 'http://' + server.host + video.previewPath
63 79
64 expect(res.body.html).to.equal(expectedHtml) 80 expect(res.body.html).to.equal(expectedHtml)
65 expect(res.body.title).to.equal(video.name) 81 expect(res.body.title).to.equal(video.name)
@@ -75,12 +91,12 @@ describe('Test services', function () {
75 91
76 it('Should have a valid playlist oEmbed response', async function () { 92 it('Should have a valid playlist oEmbed response', async function () {
77 for (const basePath of [ '/videos/watch/playlist/', '/w/p/' ]) { 93 for (const basePath of [ '/videos/watch/playlist/', '/w/p/' ]) {
78 for (const suffix of [ '', '?param=1' ]) { 94 for (const suffix of urlSuffixes) {
79 const oembedUrl = server.url + basePath + playlistUUID + suffix 95 const oembedUrl = server.url + basePath + playlistUUID + suffix.input
80 96
81 const res = await server.services.getOEmbed({ oembedUrl }) 97 const res = await server.services.getOEmbed({ oembedUrl })
82 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" ' + 98 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" ' +
83 `title="${playlistDisplayName}" src="http://localhost:${server.port}/video-playlists/embed/${playlistUUID}" ` + 99 `title="${playlistDisplayName}" src="http://${server.host}/video-playlists/embed/${playlistUUID}${suffix.output}" ` +
84 'frameborder="0" allowfullscreen></iframe>' 100 'frameborder="0" allowfullscreen></iframe>'
85 101
86 expect(res.body.html).to.equal(expectedHtml) 102 expect(res.body.html).to.equal(expectedHtml)
@@ -97,14 +113,14 @@ describe('Test services', function () {
97 113
98 it('Should have a valid oEmbed response with small max height query', async function () { 114 it('Should have a valid oEmbed response with small max height query', async function () {
99 for (const basePath of [ '/videos/watch/', '/w/' ]) { 115 for (const basePath of [ '/videos/watch/', '/w/' ]) {
100 const oembedUrl = 'http://localhost:' + server.port + basePath + video.uuid 116 const oembedUrl = 'http://' + server.host + basePath + video.uuid
101 const format = 'json' 117 const format = 'json'
102 const maxHeight = 50 118 const maxHeight = 50
103 const maxWidth = 50 119 const maxWidth = 50
104 120
105 const res = await server.services.getOEmbed({ oembedUrl, format, maxHeight, maxWidth }) 121 const res = await server.services.getOEmbed({ oembedUrl, format, maxHeight, maxWidth })
106 const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts allow-popups" ' + 122 const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts allow-popups" ' +
107 `title="${video.name}" src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` + 123 `title="${video.name}" src="http://${server.host}/videos/embed/${video.uuid}" ` +
108 'frameborder="0" allowfullscreen></iframe>' 124 'frameborder="0" allowfullscreen></iframe>'
109 125
110 expect(res.body.html).to.equal(expectedHtml) 126 expect(res.body.html).to.equal(expectedHtml)