aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-17 10:32:03 +0100
committerChocobozzz <me@florianbigard.com>2018-01-17 10:41:27 +0100
commitfd206f0b2d7e5c8e00e2817266d90ec54f79e1da (patch)
tree86b096cf2abd7eb49b892de1c9be855f45a41a9c /server/controllers
parent9581cabc596acb18c0ad86bcf3a07c2b45e8e47e (diff)
downloadPeerTube-fd206f0b2d7e5c8e00e2817266d90ec54f79e1da.tar.gz
PeerTube-fd206f0b2d7e5c8e00e2817266d90ec54f79e1da.tar.zst
PeerTube-fd206f0b2d7e5c8e00e2817266d90ec54f79e1da.zip
Add ability to update some configuration keys
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/config.ts91
1 files changed, 87 insertions, 4 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts
index 35c89835b..f0b2c3d79 100644
--- a/server/controllers/api/config.ts
+++ b/server/controllers/api/config.ts
@@ -1,15 +1,34 @@
1import * as express from 'express' 1import * as express from 'express'
2import { ServerConfig, UserRight } from '../../../shared'
3import { CustomConfig } from '../../../shared/models/config/custom-config.model'
4import { unlinkPromise, writeFilePromise } from '../../helpers/core-utils'
2import { isSignupAllowed } from '../../helpers/utils' 5import { isSignupAllowed } from '../../helpers/utils'
3 6import { CONFIG, CONSTRAINTS_FIELDS, reloadConfig } from '../../initializers'
4import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers' 7import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares'
5import { asyncMiddleware } from '../../middlewares' 8import { customConfigUpdateValidator } from '../../middlewares/validators/config'
6import { ServerConfig } from '../../../shared' 9import { omit } from 'lodash'
7 10
8const configRouter = express.Router() 11const configRouter = express.Router()
9 12
10configRouter.get('/', 13configRouter.get('/',
11 asyncMiddleware(getConfig) 14 asyncMiddleware(getConfig)
12) 15)
16configRouter.get('/custom',
17 authenticate,
18 ensureUserHasRight(UserRight.MANAGE_CONFIGURATION),
19 asyncMiddleware(getCustomConfig)
20)
21configRouter.put('/custom',
22 authenticate,
23 ensureUserHasRight(UserRight.MANAGE_CONFIGURATION),
24 asyncMiddleware(customConfigUpdateValidator),
25 asyncMiddleware(updateCustomConfig)
26)
27configRouter.delete('/custom',
28 authenticate,
29 ensureUserHasRight(UserRight.MANAGE_CONFIGURATION),
30 asyncMiddleware(deleteCustomConfig)
31)
13 32
14async function getConfig (req: express.Request, res: express.Response, next: express.NextFunction) { 33async function getConfig (req: express.Request, res: express.Response, next: express.NextFunction) {
15 const allowed = await isSignupAllowed() 34 const allowed = await isSignupAllowed()
@@ -43,8 +62,72 @@ async function getConfig (req: express.Request, res: express.Response, next: exp
43 return res.json(json) 62 return res.json(json)
44} 63}
45 64
65async function getCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) {
66 const data = customConfig()
67
68 return res.json(data).end()
69}
70
71async function deleteCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) {
72 await unlinkPromise(CONFIG.CUSTOM_FILE)
73
74 reloadConfig()
75
76 const data = customConfig()
77
78 return res.json(data).end()
79}
80
81async function updateCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) {
82 const toUpdate: CustomConfig = req.body
83
84 // Need to change the videoQuota key a little bit
85 const toUpdateJSON = omit(toUpdate, 'videoQuota')
86 toUpdateJSON.user['video_quota'] = toUpdate.user.videoQuota
87
88 await writeFilePromise(CONFIG.CUSTOM_FILE, JSON.stringify(toUpdateJSON))
89
90 reloadConfig()
91
92 const data = customConfig()
93 return res.json(data).end()
94}
95
46// --------------------------------------------------------------------------- 96// ---------------------------------------------------------------------------
47 97
48export { 98export {
49 configRouter 99 configRouter
50} 100}
101
102// ---------------------------------------------------------------------------
103
104function customConfig (): CustomConfig {
105 return {
106 cache: {
107 previews: {
108 size: CONFIG.CACHE.PREVIEWS.SIZE
109 }
110 },
111 signup: {
112 enabled: CONFIG.SIGNUP.ENABLED,
113 limit: CONFIG.SIGNUP.LIMIT
114 },
115 admin: {
116 email: CONFIG.ADMIN.EMAIL
117 },
118 user: {
119 videoQuota: CONFIG.USER.VIDEO_QUOTA
120 },
121 transcoding: {
122 enabled: CONFIG.TRANSCODING.ENABLED,
123 threads: CONFIG.TRANSCODING.THREADS,
124 resolutions: {
125 '240p': CONFIG.TRANSCODING.RESOLUTIONS[ '240p' ],
126 '360p': CONFIG.TRANSCODING.RESOLUTIONS[ '360p' ],
127 '480p': CONFIG.TRANSCODING.RESOLUTIONS[ '480p' ],
128 '720p': CONFIG.TRANSCODING.RESOLUTIONS[ '720p' ],
129 '1080p': CONFIG.TRANSCODING.RESOLUTIONS[ '1080p' ]
130 }
131 }
132 }
133}