aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/config.ts6
-rw-r--r--server/controllers/client.ts4
-rw-r--r--server/initializers/checker.ts3
-rw-r--r--server/initializers/constants.ts6
-rw-r--r--server/tests/api/check-params/config.ts6
-rw-r--r--server/tests/api/server/config.ts14
-rw-r--r--server/tests/client.ts30
7 files changed, 65 insertions, 4 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts
index e47b71f44..12074a80e 100644
--- a/server/controllers/api/config.ts
+++ b/server/controllers/api/config.ts
@@ -161,6 +161,12 @@ function customConfig (): CustomConfig {
161 javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT 161 javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT
162 } 162 }
163 }, 163 },
164 services: {
165 twitter: {
166 username: CONFIG.SERVICES.TWITTER.USERNAME,
167 whitelisted: CONFIG.SERVICES.TWITTER.WHITELISTED
168 }
169 },
164 cache: { 170 cache: {
165 previews: { 171 previews: {
166 size: CONFIG.CACHE.PREVIEWS.SIZE 172 size: CONFIG.CACHE.PREVIEWS.SIZE
diff --git a/server/controllers/client.ts b/server/controllers/client.ts
index b5dc7b7ed..20f7e5c9c 100644
--- a/server/controllers/client.ts
+++ b/server/controllers/client.ts
@@ -77,8 +77,8 @@ function addOpenGraphAndOEmbedTags (htmlStringPage: string, video: VideoModel) {
77 'description': videoDescriptionEscaped, 77 'description': videoDescriptionEscaped,
78 'image': previewUrl, 78 'image': previewUrl,
79 79
80 'twitter:card': 'summary_large_image', 80 'twitter:card': CONFIG.SERVICES.TWITTER.WHITELISTED ? 'player' : 'summary_large_image',
81 'twitter:site': '@Chocobozzz', 81 'twitter:site': CONFIG.SERVICES.TWITTER.USERNAME,
82 'twitter:title': videoNameEscaped, 82 'twitter:title': videoNameEscaped,
83 'twitter:description': videoDescriptionEscaped, 83 'twitter:description': videoDescriptionEscaped,
84 'twitter:image': previewUrl, 84 'twitter:image': previewUrl,
diff --git a/server/initializers/checker.ts b/server/initializers/checker.ts
index 739f623c6..9bf53e940 100644
--- a/server/initializers/checker.ts
+++ b/server/initializers/checker.ts
@@ -29,7 +29,8 @@ function checkMissedConfig () {
29 'user.video_quota', 29 'user.video_quota',
30 'cache.previews.size', 'admin.email', 'signup.enabled', 'signup.limit', 'transcoding.enabled', 'transcoding.threads', 30 'cache.previews.size', 'admin.email', 'signup.enabled', 'signup.limit', 'transcoding.enabled', 'transcoding.threads',
31 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route', 31 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route',
32 'instance.default_nsfw_policy' 32 'instance.default_nsfw_policy',
33 'services.twitter.username', 'services.twitter.whitelisted'
33 ] 34 ]
34 const miss: string[] = [] 35 const miss: string[] = []
35 36
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index c52c27c78..c4e8522c2 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -174,6 +174,12 @@ const CONFIG = {
174 get JAVASCRIPT () { return config.get<string>('instance.customizations.javascript') }, 174 get JAVASCRIPT () { return config.get<string>('instance.customizations.javascript') },
175 get CSS () { return config.get<string>('instance.customizations.css') } 175 get CSS () { return config.get<string>('instance.customizations.css') }
176 } 176 }
177 },
178 SERVICES: {
179 TWITTER: {
180 get USERNAME () { return config.get<string>('services.twitter.username') },
181 get WHITELISTED () { return config.get<boolean>('services.twitter.whitelisted') }
182 }
177 } 183 }
178} 184}
179 185
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index 58b780f38..6aa31e38d 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -26,6 +26,12 @@ describe('Test config API validators', function () {
26 css: 'body { background-color: red; }' 26 css: 'body { background-color: red; }'
27 } 27 }
28 }, 28 },
29 services: {
30 twitter: {
31 username: '@MySuperUsername',
32 whitelisted: true
33 }
34 },
29 cache: { 35 cache: {
30 previews: { 36 previews: {
31 size: 2 37 size: 2
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index 3f1b1532c..f24961b85 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -62,6 +62,8 @@ describe('Test config', function () {
62 expect(data.instance.defaultNSFWPolicy).to.equal('display') 62 expect(data.instance.defaultNSFWPolicy).to.equal('display')
63 expect(data.instance.customizations.css).to.be.empty 63 expect(data.instance.customizations.css).to.be.empty
64 expect(data.instance.customizations.javascript).to.be.empty 64 expect(data.instance.customizations.javascript).to.be.empty
65 expect(data.services.twitter.username).to.equal('@Chocobozzz')
66 expect(data.services.twitter.whitelisted).to.be.false
65 expect(data.cache.previews.size).to.equal(1) 67 expect(data.cache.previews.size).to.equal(1)
66 expect(data.signup.enabled).to.be.true 68 expect(data.signup.enabled).to.be.true
67 expect(data.signup.limit).to.equal(4) 69 expect(data.signup.limit).to.equal(4)
@@ -90,6 +92,12 @@ describe('Test config', function () {
90 css: 'body { background-color: red; }' 92 css: 'body { background-color: red; }'
91 } 93 }
92 }, 94 },
95 services: {
96 twitter: {
97 username: '@Kuja',
98 whitelisted: true
99 }
100 },
93 cache: { 101 cache: {
94 previews: { 102 previews: {
95 size: 2 103 size: 2
@@ -130,6 +138,8 @@ describe('Test config', function () {
130 expect(data.instance.defaultNSFWPolicy).to.equal('blur') 138 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
131 expect(data.instance.customizations.javascript).to.equal('alert("coucou")') 139 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
132 expect(data.instance.customizations.css).to.equal('body { background-color: red; }') 140 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
141 expect(data.services.twitter.username).to.equal('@Kuja')
142 expect(data.services.twitter.whitelisted).to.be.true
133 expect(data.cache.previews.size).to.equal(2) 143 expect(data.cache.previews.size).to.equal(2)
134 expect(data.signup.enabled).to.be.false 144 expect(data.signup.enabled).to.be.false
135 expect(data.signup.limit).to.equal(5) 145 expect(data.signup.limit).to.equal(5)
@@ -162,6 +172,8 @@ describe('Test config', function () {
162 expect(data.instance.defaultNSFWPolicy).to.equal('blur') 172 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
163 expect(data.instance.customizations.javascript).to.equal('alert("coucou")') 173 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
164 expect(data.instance.customizations.css).to.equal('body { background-color: red; }') 174 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
175 expect(data.services.twitter.username).to.equal('@Kuja')
176 expect(data.services.twitter.whitelisted).to.be.true
165 expect(data.cache.previews.size).to.equal(2) 177 expect(data.cache.previews.size).to.equal(2)
166 expect(data.signup.enabled).to.be.false 178 expect(data.signup.enabled).to.be.false
167 expect(data.signup.limit).to.equal(5) 179 expect(data.signup.limit).to.equal(5)
@@ -205,6 +217,8 @@ describe('Test config', function () {
205 expect(data.instance.defaultNSFWPolicy).to.equal('display') 217 expect(data.instance.defaultNSFWPolicy).to.equal('display')
206 expect(data.instance.customizations.css).to.be.empty 218 expect(data.instance.customizations.css).to.be.empty
207 expect(data.instance.customizations.javascript).to.be.empty 219 expect(data.instance.customizations.javascript).to.be.empty
220 expect(data.services.twitter.username).to.equal('@Chocobozzz')
221 expect(data.services.twitter.whitelisted).to.be.false
208 expect(data.cache.previews.size).to.equal(1) 222 expect(data.cache.previews.size).to.equal(1)
209 expect(data.signup.enabled).to.be.true 223 expect(data.signup.enabled).to.be.true
210 expect(data.signup.limit).to.equal(4) 224 expect(data.signup.limit).to.equal(4)
diff --git a/server/tests/client.ts b/server/tests/client.ts
index 2be1cf5dd..2adb39c5e 100644
--- a/server/tests/client.ts
+++ b/server/tests/client.ts
@@ -11,7 +11,7 @@ import {
11 runServer, 11 runServer,
12 serverLogin, 12 serverLogin,
13 uploadVideo, 13 uploadVideo,
14 getVideosList 14 getVideosList, updateCustomConfig, getCustomConfig
15} from './utils' 15} from './utils'
16 16
17describe('Test a client controllers', function () { 17describe('Test a client controllers', function () {
@@ -73,6 +73,34 @@ describe('Test a client controllers', function () {
73 expect(res.text).to.contain(expectedLink) 73 expect(res.text).to.contain(expectedLink)
74 }) 74 })
75 75
76 it('Should have valid twitter card', async function () {
77 const res = await request(server.url)
78 .get('/videos/watch/' + server.video.uuid)
79 .set('Accept', 'text/html')
80 .expect(200)
81
82 expect(res.text).to.contain('<meta property="twitter:card" content="summary_large_image" />')
83 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
84 })
85
86 it('Should have valid twitter card if Twitter is whitelisted', async function () {
87 const res1 = await getCustomConfig(server.url, server.accessToken)
88 const config = res1.body
89 config.services.twitter = {
90 username: '@Kuja',
91 whitelisted: true
92 }
93 await updateCustomConfig(server.url, server.accessToken, config)
94
95 const res = await request(server.url)
96 .get('/videos/watch/' + server.video.uuid)
97 .set('Accept', 'text/html')
98 .expect(200)
99
100 expect(res.text).to.contain('<meta property="twitter:card" content="player" />')
101 expect(res.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
102 })
103
76 after(async function () { 104 after(async function () {
77 process.kill(-server.app.pid) 105 process.kill(-server.app.pid)
78 106