aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-02-22 10:22:53 +0100
committerChocobozzz <me@florianbigard.com>2018-02-22 10:22:53 +0100
commit00b5556c182fa70dfca17c517488b8afae6257c9 (patch)
tree853ad8d85572b5b37b1956fea96a51fed211453f /server
parent6221f311de0eb8f2a9e7e4a77b8cb0ecbde6dfcd (diff)
downloadPeerTube-00b5556c182fa70dfca17c517488b8afae6257c9.tar.gz
PeerTube-00b5556c182fa70dfca17c517488b8afae6257c9.tar.zst
PeerTube-00b5556c182fa70dfca17c517488b8afae6257c9.zip
Add ability to add custom css/javascript
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/config.ts12
-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.ts20
4 files changed, 38 insertions, 6 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts
index 532afb8c0..8cfaf3e29 100644
--- a/server/controllers/api/config.ts
+++ b/server/controllers/api/config.ts
@@ -43,7 +43,11 @@ async function getConfig (req: express.Request, res: express.Response, next: exp
43 43
44 const json: ServerConfig = { 44 const json: ServerConfig = {
45 instance: { 45 instance: {
46 name: CONFIG.INSTANCE.NAME 46 name: CONFIG.INSTANCE.NAME,
47 customizations: {
48 javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT,
49 css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS
50 }
47 }, 51 },
48 serverVersion: packageJSON.version, 52 serverVersion: packageJSON.version,
49 signup: { 53 signup: {
@@ -132,7 +136,11 @@ function customConfig (): CustomConfig {
132 instance: { 136 instance: {
133 name: CONFIG.INSTANCE.NAME, 137 name: CONFIG.INSTANCE.NAME,
134 description: CONFIG.INSTANCE.DESCRIPTION, 138 description: CONFIG.INSTANCE.DESCRIPTION,
135 terms: CONFIG.INSTANCE.TERMS 139 terms: CONFIG.INSTANCE.TERMS,
140 customizations: {
141 css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS,
142 javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT
143 }
136 }, 144 },
137 cache: { 145 cache: {
138 previews: { 146 previews: {
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index ac001bbc7..328a3e70a 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -158,7 +158,11 @@ const CONFIG = {
158 INSTANCE: { 158 INSTANCE: {
159 get NAME () { return config.get<string>('instance.name') }, 159 get NAME () { return config.get<string>('instance.name') },
160 get DESCRIPTION () { return config.get<string>('instance.description') }, 160 get DESCRIPTION () { return config.get<string>('instance.description') },
161 get TERMS () { return config.get<string>('instance.terms') } 161 get TERMS () { return config.get<string>('instance.terms') },
162 CUSTOMIZATIONS: {
163 get JAVASCRIPT () { return config.get<string>('instance.customizations.javascript') },
164 get CSS () { return config.get<string>('instance.customizations.css') }
165 }
162 } 166 }
163} 167}
164 168
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index efc1e4e09..c1c0a3f59 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -17,7 +17,11 @@ describe('Test config API validators', function () {
17 instance: { 17 instance: {
18 name: 'PeerTube updated', 18 name: 'PeerTube updated',
19 description: 'my super description', 19 description: 'my super description',
20 terms: 'my super terms' 20 terms: 'my super terms',
21 customizations: {
22 javascript: 'alert("coucou")',
23 css: 'body { background-color: red; }'
24 }
21 }, 25 },
22 cache: { 26 cache: {
23 previews: { 27 previews: {
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index f1f7afef9..048135a34 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -3,6 +3,7 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { About } from '../../../../shared/models/config/about.model' 5import { About } from '../../../../shared/models/config/about.model'
6import { CustomConfig } from '../../../../shared/models/config/custom-config.model'
6import { deleteCustomConfig, getAbout, killallServers, reRunServer } from '../../utils' 7import { deleteCustomConfig, getAbout, killallServers, reRunServer } from '../../utils'
7const expect = chai.expect 8const expect = chai.expect
8 9
@@ -48,11 +49,13 @@ describe('Test config', function () {
48 49
49 it('Should get the customized configuration', async function () { 50 it('Should get the customized configuration', async function () {
50 const res = await getCustomConfig(server.url, server.accessToken) 51 const res = await getCustomConfig(server.url, server.accessToken)
51 const data = res.body 52 const data = res.body as CustomConfig
52 53
53 expect(data.instance.name).to.equal('PeerTube') 54 expect(data.instance.name).to.equal('PeerTube')
54 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!') 55 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
55 expect(data.instance.terms).to.equal('No terms for now.') 56 expect(data.instance.terms).to.equal('No terms for now.')
57 expect(data.instance.customizations.css).to.be.empty
58 expect(data.instance.customizations.javascript).to.be.empty
56 expect(data.cache.previews.size).to.equal(1) 59 expect(data.cache.previews.size).to.equal(1)
57 expect(data.signup.enabled).to.be.true 60 expect(data.signup.enabled).to.be.true
58 expect(data.signup.limit).to.equal(4) 61 expect(data.signup.limit).to.equal(4)
@@ -72,7 +75,11 @@ describe('Test config', function () {
72 instance: { 75 instance: {
73 name: 'PeerTube updated', 76 name: 'PeerTube updated',
74 description: 'my super description', 77 description: 'my super description',
75 terms: 'my super terms' 78 terms: 'my super terms',
79 customizations: {
80 javascript: 'alert("coucou")',
81 css: 'body { background-color: red; }'
82 }
76 }, 83 },
77 cache: { 84 cache: {
78 previews: { 85 previews: {
@@ -109,6 +116,8 @@ describe('Test config', function () {
109 expect(data.instance.name).to.equal('PeerTube updated') 116 expect(data.instance.name).to.equal('PeerTube updated')
110 expect(data.instance.description).to.equal('my super description') 117 expect(data.instance.description).to.equal('my super description')
111 expect(data.instance.terms).to.equal('my super terms') 118 expect(data.instance.terms).to.equal('my super terms')
119 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
120 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
112 expect(data.cache.previews.size).to.equal(2) 121 expect(data.cache.previews.size).to.equal(2)
113 expect(data.signup.enabled).to.be.false 122 expect(data.signup.enabled).to.be.false
114 expect(data.signup.limit).to.equal(5) 123 expect(data.signup.limit).to.equal(5)
@@ -136,6 +145,8 @@ describe('Test config', function () {
136 expect(data.instance.name).to.equal('PeerTube updated') 145 expect(data.instance.name).to.equal('PeerTube updated')
137 expect(data.instance.description).to.equal('my super description') 146 expect(data.instance.description).to.equal('my super description')
138 expect(data.instance.terms).to.equal('my super terms') 147 expect(data.instance.terms).to.equal('my super terms')
148 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
149 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
139 expect(data.cache.previews.size).to.equal(2) 150 expect(data.cache.previews.size).to.equal(2)
140 expect(data.signup.enabled).to.be.false 151 expect(data.signup.enabled).to.be.false
141 expect(data.signup.limit).to.equal(5) 152 expect(data.signup.limit).to.equal(5)
@@ -167,6 +178,11 @@ describe('Test config', function () {
167 const res = await getCustomConfig(server.url, server.accessToken) 178 const res = await getCustomConfig(server.url, server.accessToken)
168 const data = res.body 179 const data = res.body
169 180
181 expect(data.instance.name).to.equal('PeerTube')
182 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
183 expect(data.instance.terms).to.equal('No terms for now.')
184 expect(data.instance.customizations.css).to.be.empty
185 expect(data.instance.customizations.javascript).to.be.empty
170 expect(data.cache.previews.size).to.equal(1) 186 expect(data.cache.previews.size).to.equal(1)
171 expect(data.signup.enabled).to.be.true 187 expect(data.signup.enabled).to.be.true
172 expect(data.signup.limit).to.equal(4) 188 expect(data.signup.limit).to.equal(4)