aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-04-09 14:51:28 +0200
committerChocobozzz <me@florianbigard.com>2021-04-09 15:17:43 +0200
commit22820226e54dee61287666a178df2176fafb202a (patch)
tree3fce30315da83eda4b4f96064ad2703202d0d0f5 /server/controllers
parent023edc8a54a58d15f8d4f00d7f76e0074d0d3a81 (diff)
downloadPeerTube-22820226e54dee61287666a178df2176fafb202a.tar.gz
PeerTube-22820226e54dee61287666a178df2176fafb202a.tar.zst
PeerTube-22820226e54dee61287666a178df2176fafb202a.zip
Add server plugin helpers
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/config.ts250
-rw-r--r--server/controllers/static.ts2
2 files changed, 6 insertions, 246 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts
index e28f7502d..2ddb73519 100644
--- a/server/controllers/api/config.ts
+++ b/server/controllers/api/config.ts
@@ -1,24 +1,17 @@
1import { Hooks } from '@server/lib/plugins/hooks'
2import * as express from 'express' 1import * as express from 'express'
3import { remove, writeJSON } from 'fs-extra' 2import { remove, writeJSON } from 'fs-extra'
4import { snakeCase } from 'lodash' 3import { snakeCase } from 'lodash'
5import validator from 'validator' 4import validator from 'validator'
6import { RegisteredExternalAuthConfig, RegisteredIdAndPassAuthConfig, ServerConfig, UserRight } from '../../../shared' 5import { getServerConfig } from '@server/lib/config'
6import { UserRight } from '../../../shared'
7import { About } from '../../../shared/models/server/about.model' 7import { About } from '../../../shared/models/server/about.model'
8import { CustomConfig } from '../../../shared/models/server/custom-config.model' 8import { CustomConfig } from '../../../shared/models/server/custom-config.model'
9import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger' 9import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger'
10import { objectConverter } from '../../helpers/core-utils' 10import { objectConverter } from '../../helpers/core-utils'
11import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' 11import { CONFIG, reloadConfig } from '../../initializers/config'
12import { getServerCommit } from '../../helpers/utils'
13import { getEnabledResolutions } from '../../lib/video-transcoding'
14import { CONFIG, isEmailEnabled, reloadConfig } from '../../initializers/config'
15import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '../../initializers/constants'
16import { ClientHtml } from '../../lib/client-html' 12import { ClientHtml } from '../../lib/client-html'
17import { PluginManager } from '../../lib/plugins/plugin-manager'
18import { getThemeOrDefault } from '../../lib/plugins/theme-utils'
19import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' 13import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares'
20import { customConfigUpdateValidator } from '../../middlewares/validators/config' 14import { customConfigUpdateValidator } from '../../middlewares/validators/config'
21import { VideoTranscodingProfilesManager } from '@server/lib/video-transcoding-profiles'
22 15
23const configRouter = express.Router() 16const configRouter = express.Router()
24 17
@@ -46,182 +39,8 @@ configRouter.delete('/custom',
46 asyncMiddleware(deleteCustomConfig) 39 asyncMiddleware(deleteCustomConfig)
47) 40)
48 41
49let serverCommit: string
50
51async function getConfig (req: express.Request, res: express.Response) { 42async function getConfig (req: express.Request, res: express.Response) {
52 const { allowed } = await Hooks.wrapPromiseFun( 43 const json = await getServerConfig(req.ip)
53 isSignupAllowed,
54 {
55 ip: req.ip
56 },
57 'filter:api.user.signup.allowed.result'
58 )
59
60 const allowedForCurrentIP = isSignupAllowedForCurrentIP(req.ip)
61 const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME)
62
63 if (serverCommit === undefined) serverCommit = await getServerCommit()
64
65 const json: ServerConfig = {
66 instance: {
67 name: CONFIG.INSTANCE.NAME,
68 shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION,
69 isNSFW: CONFIG.INSTANCE.IS_NSFW,
70 defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
71 defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE,
72 customizations: {
73 javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT,
74 css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS
75 }
76 },
77 search: {
78 remoteUri: {
79 users: CONFIG.SEARCH.REMOTE_URI.USERS,
80 anonymous: CONFIG.SEARCH.REMOTE_URI.ANONYMOUS
81 },
82 searchIndex: {
83 enabled: CONFIG.SEARCH.SEARCH_INDEX.ENABLED,
84 url: CONFIG.SEARCH.SEARCH_INDEX.URL,
85 disableLocalSearch: CONFIG.SEARCH.SEARCH_INDEX.DISABLE_LOCAL_SEARCH,
86 isDefaultSearch: CONFIG.SEARCH.SEARCH_INDEX.IS_DEFAULT_SEARCH
87 }
88 },
89 plugin: {
90 registered: getRegisteredPlugins(),
91 registeredExternalAuths: getExternalAuthsPlugins(),
92 registeredIdAndPassAuths: getIdAndPassAuthPlugins()
93 },
94 theme: {
95 registered: getRegisteredThemes(),
96 default: defaultTheme
97 },
98 email: {
99 enabled: isEmailEnabled()
100 },
101 contactForm: {
102 enabled: CONFIG.CONTACT_FORM.ENABLED
103 },
104 serverVersion: PEERTUBE_VERSION,
105 serverCommit,
106 signup: {
107 allowed,
108 allowedForCurrentIP,
109 requiresEmailVerification: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION
110 },
111 transcoding: {
112 hls: {
113 enabled: CONFIG.TRANSCODING.HLS.ENABLED
114 },
115 webtorrent: {
116 enabled: CONFIG.TRANSCODING.WEBTORRENT.ENABLED
117 },
118 enabledResolutions: getEnabledResolutions('vod'),
119 profile: CONFIG.TRANSCODING.PROFILE,
120 availableProfiles: VideoTranscodingProfilesManager.Instance.getAvailableProfiles('vod')
121 },
122 live: {
123 enabled: CONFIG.LIVE.ENABLED,
124
125 allowReplay: CONFIG.LIVE.ALLOW_REPLAY,
126 maxDuration: CONFIG.LIVE.MAX_DURATION,
127 maxInstanceLives: CONFIG.LIVE.MAX_INSTANCE_LIVES,
128 maxUserLives: CONFIG.LIVE.MAX_USER_LIVES,
129
130 transcoding: {
131 enabled: CONFIG.LIVE.TRANSCODING.ENABLED,
132 enabledResolutions: getEnabledResolutions('live'),
133 profile: CONFIG.LIVE.TRANSCODING.PROFILE,
134 availableProfiles: VideoTranscodingProfilesManager.Instance.getAvailableProfiles('live')
135 },
136
137 rtmp: {
138 port: CONFIG.LIVE.RTMP.PORT
139 }
140 },
141 import: {
142 videos: {
143 http: {
144 enabled: CONFIG.IMPORT.VIDEOS.HTTP.ENABLED
145 },
146 torrent: {
147 enabled: CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED
148 }
149 }
150 },
151 autoBlacklist: {
152 videos: {
153 ofUsers: {
154 enabled: CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED
155 }
156 }
157 },
158 avatar: {
159 file: {
160 size: {
161 max: CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max
162 },
163 extensions: CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME
164 }
165 },
166 banner: {
167 file: {
168 size: {
169 max: CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max
170 },
171 extensions: CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME
172 }
173 },
174 video: {
175 image: {
176 extensions: CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME,
177 size: {
178 max: CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max
179 }
180 },
181 file: {
182 extensions: CONSTRAINTS_FIELDS.VIDEOS.EXTNAME
183 }
184 },
185 videoCaption: {
186 file: {
187 size: {
188 max: CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max
189 },
190 extensions: CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.EXTNAME
191 }
192 },
193 user: {
194 videoQuota: CONFIG.USER.VIDEO_QUOTA,
195 videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY
196 },
197 trending: {
198 videos: {
199 intervalDays: CONFIG.TRENDING.VIDEOS.INTERVAL_DAYS,
200 algorithms: {
201 enabled: CONFIG.TRENDING.VIDEOS.ALGORITHMS.ENABLED,
202 default: CONFIG.TRENDING.VIDEOS.ALGORITHMS.DEFAULT
203 }
204 }
205 },
206 tracker: {
207 enabled: CONFIG.TRACKER.ENABLED
208 },
209
210 followings: {
211 instance: {
212 autoFollowIndex: {
213 indexUrl: CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_INDEX.INDEX_URL
214 }
215 }
216 },
217
218 broadcastMessage: {
219 enabled: CONFIG.BROADCAST_MESSAGE.ENABLED,
220 message: CONFIG.BROADCAST_MESSAGE.MESSAGE,
221 level: CONFIG.BROADCAST_MESSAGE.LEVEL,
222 dismissable: CONFIG.BROADCAST_MESSAGE.DISMISSABLE
223 }
224 }
225 44
226 return res.json(json) 45 return res.json(json)
227} 46}
@@ -292,69 +111,10 @@ async function updateCustomConfig (req: express.Request, res: express.Response)
292 return res.json(data) 111 return res.json(data)
293} 112}
294 113
295function getRegisteredThemes () {
296 return PluginManager.Instance.getRegisteredThemes()
297 .map(t => ({
298 name: t.name,
299 version: t.version,
300 description: t.description,
301 css: t.css,
302 clientScripts: t.clientScripts
303 }))
304}
305
306function getRegisteredPlugins () {
307 return PluginManager.Instance.getRegisteredPlugins()
308 .map(p => ({
309 name: p.name,
310 version: p.version,
311 description: p.description,
312 clientScripts: p.clientScripts
313 }))
314}
315
316function getIdAndPassAuthPlugins () {
317 const result: RegisteredIdAndPassAuthConfig[] = []
318
319 for (const p of PluginManager.Instance.getIdAndPassAuths()) {
320 for (const auth of p.idAndPassAuths) {
321 result.push({
322 npmName: p.npmName,
323 name: p.name,
324 version: p.version,
325 authName: auth.authName,
326 weight: auth.getWeight()
327 })
328 }
329 }
330
331 return result
332}
333
334function getExternalAuthsPlugins () {
335 const result: RegisteredExternalAuthConfig[] = []
336
337 for (const p of PluginManager.Instance.getExternalAuths()) {
338 for (const auth of p.externalAuths) {
339 result.push({
340 npmName: p.npmName,
341 name: p.name,
342 version: p.version,
343 authName: auth.authName,
344 authDisplayName: auth.authDisplayName()
345 })
346 }
347 }
348
349 return result
350}
351
352// --------------------------------------------------------------------------- 114// ---------------------------------------------------------------------------
353 115
354export { 116export {
355 configRouter, 117 configRouter
356 getRegisteredPlugins,
357 getRegisteredThemes
358} 118}
359 119
360// --------------------------------------------------------------------------- 120// ---------------------------------------------------------------------------
diff --git a/server/controllers/static.ts b/server/controllers/static.ts
index e6a0628e6..8d9003a3e 100644
--- a/server/controllers/static.ts
+++ b/server/controllers/static.ts
@@ -1,8 +1,8 @@
1import * as cors from 'cors' 1import * as cors from 'cors'
2import * as express from 'express' 2import * as express from 'express'
3import { join } from 'path' 3import { join } from 'path'
4import { getRegisteredPlugins, getRegisteredThemes } from '@server/controllers/api/config'
5import { serveIndexHTML } from '@server/lib/client-html' 4import { serveIndexHTML } from '@server/lib/client-html'
5import { getRegisteredPlugins, getRegisteredThemes } from '@server/lib/config'
6import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' 6import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
7import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/nodeinfo' 7import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/nodeinfo'
8import { root } from '../helpers/core-utils' 8import { root } from '../helpers/core-utils'