aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-02-20 15:36:43 +0100
committerChocobozzz <me@florianbigard.com>2019-02-20 15:36:43 +0100
commitf8802489bbc2c0363b5668e47de7c35f573342e1 (patch)
tree526054fad5a7f944b008ac1a6e400dfbe66a1639 /server
parent1aabcae7e36bb113c2887bd7180dad2916ecaaf2 (diff)
downloadPeerTube-f8802489bbc2c0363b5668e47de7c35f573342e1.tar.gz
PeerTube-f8802489bbc2c0363b5668e47de7c35f573342e1.tar.zst
PeerTube-f8802489bbc2c0363b5668e47de7c35f573342e1.zip
Add isNSFW instance configuration key
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/config.ts10
-rw-r--r--server/initializers/checker-before-init.ts2
-rw-r--r--server/initializers/constants.ts1
-rw-r--r--server/tests/api/check-params/config.ts1
-rw-r--r--server/tests/api/server/config.ts3
5 files changed, 12 insertions, 5 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts
index 1f3341bc0..6497cda3c 100644
--- a/server/controllers/api/config.ts
+++ b/server/controllers/api/config.ts
@@ -58,6 +58,7 @@ async function getConfig (req: express.Request, res: express.Response) {
58 name: CONFIG.INSTANCE.NAME, 58 name: CONFIG.INSTANCE.NAME,
59 shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION, 59 shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION,
60 defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE, 60 defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE,
61 isNSFW: CONFIG.INSTANCE.IS_NSFW,
61 defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, 62 defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
62 customizations: { 63 customizations: {
63 javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT, 64 javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT,
@@ -134,7 +135,7 @@ async function getConfig (req: express.Request, res: express.Response) {
134 return res.json(json) 135 return res.json(json)
135} 136}
136 137
137function getAbout (req: express.Request, res: express.Response, next: express.NextFunction) { 138function getAbout (req: express.Request, res: express.Response) {
138 const about: About = { 139 const about: About = {
139 instance: { 140 instance: {
140 name: CONFIG.INSTANCE.NAME, 141 name: CONFIG.INSTANCE.NAME,
@@ -147,13 +148,13 @@ function getAbout (req: express.Request, res: express.Response, next: express.Ne
147 return res.json(about).end() 148 return res.json(about).end()
148} 149}
149 150
150async function getCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { 151async function getCustomConfig (req: express.Request, res: express.Response) {
151 const data = customConfig() 152 const data = customConfig()
152 153
153 return res.json(data).end() 154 return res.json(data).end()
154} 155}
155 156
156async function deleteCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { 157async function deleteCustomConfig (req: express.Request, res: express.Response) {
157 await remove(CONFIG.CUSTOM_FILE) 158 await remove(CONFIG.CUSTOM_FILE)
158 159
159 auditLogger.delete(getAuditIdFromRes(res), new CustomConfigAuditView(customConfig())) 160 auditLogger.delete(getAuditIdFromRes(res), new CustomConfigAuditView(customConfig()))
@@ -166,7 +167,7 @@ async function deleteCustomConfig (req: express.Request, res: express.Response,
166 return res.json(data).end() 167 return res.json(data).end()
167} 168}
168 169
169async function updateCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { 170async function updateCustomConfig (req: express.Request, res: express.Response) {
170 const oldCustomConfigAuditKeys = new CustomConfigAuditView(customConfig()) 171 const oldCustomConfigAuditKeys = new CustomConfigAuditView(customConfig())
171 172
172 // camelCase to snake_case key + Force number conversion 173 // camelCase to snake_case key + Force number conversion
@@ -203,6 +204,7 @@ function customConfig (): CustomConfig {
203 shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION, 204 shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION,
204 description: CONFIG.INSTANCE.DESCRIPTION, 205 description: CONFIG.INSTANCE.DESCRIPTION,
205 terms: CONFIG.INSTANCE.TERMS, 206 terms: CONFIG.INSTANCE.TERMS,
207 isNSFW: CONFIG.INSTANCE.IS_NSFW,
206 defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE, 208 defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE,
207 defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, 209 defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
208 customizations: { 210 customizations: {
diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts
index 29fdb263e..230fdd356 100644
--- a/server/initializers/checker-before-init.ts
+++ b/server/initializers/checker-before-init.ts
@@ -23,7 +23,7 @@ function checkMissedConfig () {
23 'import.videos.http.enabled', 'import.videos.torrent.enabled', 23 'import.videos.http.enabled', 'import.videos.torrent.enabled',
24 'trending.videos.interval_days', 24 'trending.videos.interval_days',
25 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route', 25 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route',
26 'instance.default_nsfw_policy', 'instance.robots', 'instance.securitytxt', 26 'instance.is_nsfw', 'instance.default_nsfw_policy', 'instance.robots', 'instance.securitytxt',
27 'services.twitter.username', 'services.twitter.whitelisted' 27 'services.twitter.username', 'services.twitter.whitelisted'
28 ] 28 ]
29 const requiredAlternatives = [ 29 const requiredAlternatives = [
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index c1be7f326..bb2c6765f 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -288,6 +288,7 @@ const CONFIG = {
288 get SHORT_DESCRIPTION () { return config.get<string>('instance.short_description') }, 288 get SHORT_DESCRIPTION () { return config.get<string>('instance.short_description') },
289 get DESCRIPTION () { return config.get<string>('instance.description') }, 289 get DESCRIPTION () { return config.get<string>('instance.description') },
290 get TERMS () { return config.get<string>('instance.terms') }, 290 get TERMS () { return config.get<string>('instance.terms') },
291 get IS_NSFW () { return config.get<boolean>('instance.is_nsfw') },
291 get DEFAULT_CLIENT_ROUTE () { return config.get<string>('instance.default_client_route') }, 292 get DEFAULT_CLIENT_ROUTE () { return config.get<string>('instance.default_client_route') },
292 get DEFAULT_NSFW_POLICY () { return config.get<NSFWPolicyType>('instance.default_nsfw_policy') }, 293 get DEFAULT_NSFW_POLICY () { return config.get<NSFWPolicyType>('instance.default_nsfw_policy') },
293 CUSTOMIZATIONS: { 294 CUSTOMIZATIONS: {
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index 3895c4f9a..c6b460f23 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -19,6 +19,7 @@ describe('Test config API validators', function () {
19 shortDescription: 'my short description', 19 shortDescription: 'my short description',
20 description: 'my super description', 20 description: 'my super description',
21 terms: 'my super terms', 21 terms: 'my super terms',
22 isNSFW: true,
22 defaultClientRoute: '/videos/recently-added', 23 defaultClientRoute: '/videos/recently-added',
23 defaultNSFWPolicy: 'blur', 24 defaultNSFWPolicy: 'blur',
24 customizations: { 25 customizations: {
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index 3be1c9431..42927605d 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -30,6 +30,7 @@ function checkInitialConfig (data: CustomConfig) {
30 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!') 30 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
31 expect(data.instance.terms).to.equal('No terms for now.') 31 expect(data.instance.terms).to.equal('No terms for now.')
32 expect(data.instance.defaultClientRoute).to.equal('/videos/trending') 32 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
33 expect(data.instance.isNSFW).to.be.false
33 expect(data.instance.defaultNSFWPolicy).to.equal('display') 34 expect(data.instance.defaultNSFWPolicy).to.equal('display')
34 expect(data.instance.customizations.css).to.be.empty 35 expect(data.instance.customizations.css).to.be.empty
35 expect(data.instance.customizations.javascript).to.be.empty 36 expect(data.instance.customizations.javascript).to.be.empty
@@ -69,6 +70,7 @@ function checkUpdatedConfig (data: CustomConfig) {
69 expect(data.instance.description).to.equal('my super description') 70 expect(data.instance.description).to.equal('my super description')
70 expect(data.instance.terms).to.equal('my super terms') 71 expect(data.instance.terms).to.equal('my super terms')
71 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added') 72 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
73 expect(data.instance.isNSFW).to.be.true
72 expect(data.instance.defaultNSFWPolicy).to.equal('blur') 74 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
73 expect(data.instance.customizations.javascript).to.equal('alert("coucou")') 75 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
74 expect(data.instance.customizations.css).to.equal('body { background-color: red; }') 76 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
@@ -163,6 +165,7 @@ describe('Test config', function () {
163 description: 'my super description', 165 description: 'my super description',
164 terms: 'my super terms', 166 terms: 'my super terms',
165 defaultClientRoute: '/videos/recently-added', 167 defaultClientRoute: '/videos/recently-added',
168 isNSFW: true,
166 defaultNSFWPolicy: 'blur' as 'blur', 169 defaultNSFWPolicy: 'blur' as 'blur',
167 customizations: { 170 customizations: {
168 javascript: 'alert("coucou")', 171 javascript: 'alert("coucou")',