diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-06 12:26:58 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-06 12:26:58 +0100 |
commit | 73471b1a52f242e86364ffb077ea6cadb3b07ae2 (patch) | |
tree | 43dbb7748e281f8d80f15326f489cdea10ec857d /server/controllers/api/config.ts | |
parent | c22419dd265c0c7185bf4197a1cb286eb3d8ebc0 (diff) | |
parent | f5305c04aae14467d6f957b713c5a902275cbb89 (diff) | |
download | PeerTube-73471b1a52f242e86364ffb077ea6cadb3b07ae2.tar.gz PeerTube-73471b1a52f242e86364ffb077ea6cadb3b07ae2.tar.zst PeerTube-73471b1a52f242e86364ffb077ea6cadb3b07ae2.zip |
Merge branch 'release/v1.2.0'
Diffstat (limited to 'server/controllers/api/config.ts')
-rw-r--r-- | server/controllers/api/config.ts | 63 |
1 files changed, 38 insertions, 25 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 5233e9f68..255026f46 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { omit } from 'lodash' | 2 | import { omit, snakeCase } from 'lodash' |
3 | import { ServerConfig, UserRight } from '../../../shared' | 3 | import { ServerConfig, UserRight } from '../../../shared' |
4 | import { About } from '../../../shared/models/server/about.model' | 4 | import { About } from '../../../shared/models/server/about.model' |
5 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' | 5 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' |
@@ -11,6 +11,9 @@ import { ClientHtml } from '../../lib/client-html' | |||
11 | import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger' | 11 | import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger' |
12 | import { remove, writeJSON } from 'fs-extra' | 12 | import { remove, writeJSON } from 'fs-extra' |
13 | import { getServerCommit } from '../../helpers/utils' | 13 | import { getServerCommit } from '../../helpers/utils' |
14 | import { Emailer } from '../../lib/emailer' | ||
15 | import { isNumeric } from 'validator' | ||
16 | import { objectConverter } from '../../helpers/core-utils' | ||
14 | 17 | ||
15 | const packageJSON = require('../../../../package.json') | 18 | const packageJSON = require('../../../../package.json') |
16 | const configRouter = express.Router() | 19 | const configRouter = express.Router() |
@@ -61,6 +64,12 @@ async function getConfig (req: express.Request, res: express.Response) { | |||
61 | css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS | 64 | css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS |
62 | } | 65 | } |
63 | }, | 66 | }, |
67 | email: { | ||
68 | enabled: Emailer.isEnabled() | ||
69 | }, | ||
70 | contactForm: { | ||
71 | enabled: CONFIG.CONTACT_FORM.ENABLED | ||
72 | }, | ||
64 | serverVersion: packageJSON.version, | 73 | serverVersion: packageJSON.version, |
65 | serverCommit, | 74 | serverCommit, |
66 | signup: { | 75 | signup: { |
@@ -111,6 +120,11 @@ async function getConfig (req: express.Request, res: express.Response) { | |||
111 | user: { | 120 | user: { |
112 | videoQuota: CONFIG.USER.VIDEO_QUOTA, | 121 | videoQuota: CONFIG.USER.VIDEO_QUOTA, |
113 | videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY | 122 | videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY |
123 | }, | ||
124 | trending: { | ||
125 | videos: { | ||
126 | intervalDays: CONFIG.TRENDING.VIDEOS.INTERVAL_DAYS | ||
127 | } | ||
114 | } | 128 | } |
115 | } | 129 | } |
116 | 130 | ||
@@ -150,32 +164,10 @@ async function deleteCustomConfig (req: express.Request, res: express.Response, | |||
150 | } | 164 | } |
151 | 165 | ||
152 | async function updateCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { | 166 | async function updateCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { |
153 | const toUpdate: CustomConfig = req.body | ||
154 | const oldCustomConfigAuditKeys = new CustomConfigAuditView(customConfig()) | 167 | const oldCustomConfigAuditKeys = new CustomConfigAuditView(customConfig()) |
155 | 168 | ||
156 | // Force number conversion | 169 | // camelCase to snake_case key + Force number conversion |
157 | toUpdate.cache.previews.size = parseInt('' + toUpdate.cache.previews.size, 10) | 170 | const toUpdateJSON = convertCustomConfigBody(req.body) |
158 | toUpdate.cache.captions.size = parseInt('' + toUpdate.cache.captions.size, 10) | ||
159 | toUpdate.signup.limit = parseInt('' + toUpdate.signup.limit, 10) | ||
160 | toUpdate.user.videoQuota = parseInt('' + toUpdate.user.videoQuota, 10) | ||
161 | toUpdate.user.videoQuotaDaily = parseInt('' + toUpdate.user.videoQuotaDaily, 10) | ||
162 | toUpdate.transcoding.threads = parseInt('' + toUpdate.transcoding.threads, 10) | ||
163 | |||
164 | // camelCase to snake_case key | ||
165 | const toUpdateJSON = omit( | ||
166 | toUpdate, | ||
167 | 'user.videoQuota', | ||
168 | 'instance.defaultClientRoute', | ||
169 | 'instance.shortDescription', | ||
170 | 'cache.videoCaptions', | ||
171 | 'signup.requiresEmailVerification' | ||
172 | ) | ||
173 | toUpdateJSON.user['video_quota'] = toUpdate.user.videoQuota | ||
174 | toUpdateJSON.user['video_quota_daily'] = toUpdate.user.videoQuotaDaily | ||
175 | toUpdateJSON.instance['default_client_route'] = toUpdate.instance.defaultClientRoute | ||
176 | toUpdateJSON.instance['short_description'] = toUpdate.instance.shortDescription | ||
177 | toUpdateJSON.instance['default_nsfw_policy'] = toUpdate.instance.defaultNSFWPolicy | ||
178 | toUpdateJSON.signup['requires_email_verification'] = toUpdate.signup.requiresEmailVerification | ||
179 | 171 | ||
180 | await writeJSON(CONFIG.CUSTOM_FILE, toUpdateJSON, { spaces: 2 }) | 172 | await writeJSON(CONFIG.CUSTOM_FILE, toUpdateJSON, { spaces: 2 }) |
181 | 173 | ||
@@ -237,12 +229,16 @@ function customConfig (): CustomConfig { | |||
237 | admin: { | 229 | admin: { |
238 | email: CONFIG.ADMIN.EMAIL | 230 | email: CONFIG.ADMIN.EMAIL |
239 | }, | 231 | }, |
232 | contactForm: { | ||
233 | enabled: CONFIG.CONTACT_FORM.ENABLED | ||
234 | }, | ||
240 | user: { | 235 | user: { |
241 | videoQuota: CONFIG.USER.VIDEO_QUOTA, | 236 | videoQuota: CONFIG.USER.VIDEO_QUOTA, |
242 | videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY | 237 | videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY |
243 | }, | 238 | }, |
244 | transcoding: { | 239 | transcoding: { |
245 | enabled: CONFIG.TRANSCODING.ENABLED, | 240 | enabled: CONFIG.TRANSCODING.ENABLED, |
241 | allowAdditionalExtensions: CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS, | ||
246 | threads: CONFIG.TRANSCODING.THREADS, | 242 | threads: CONFIG.TRANSCODING.THREADS, |
247 | resolutions: { | 243 | resolutions: { |
248 | '240p': CONFIG.TRANSCODING.RESOLUTIONS[ '240p' ], | 244 | '240p': CONFIG.TRANSCODING.RESOLUTIONS[ '240p' ], |
@@ -264,3 +260,20 @@ function customConfig (): CustomConfig { | |||
264 | } | 260 | } |
265 | } | 261 | } |
266 | } | 262 | } |
263 | |||
264 | function convertCustomConfigBody (body: CustomConfig) { | ||
265 | function keyConverter (k: string) { | ||
266 | // Transcoding resolutions exception | ||
267 | if (/^\d{3,4}p$/.exec(k)) return k | ||
268 | |||
269 | return snakeCase(k) | ||
270 | } | ||
271 | |||
272 | function valueConverter (v: any) { | ||
273 | if (isNumeric(v + '')) return parseInt('' + v, 10) | ||
274 | |||
275 | return v | ||
276 | } | ||
277 | |||
278 | return objectConverter(body, keyConverter, valueConverter) | ||
279 | } | ||