aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/config.ts
diff options
context:
space:
mode:
authorChocobozzz <chocobozzz@cpy.re>2021-05-27 15:59:55 +0200
committerGitHub <noreply@github.com>2021-05-27 15:59:55 +0200
commit2539932e16129992a2c0889b4ff527c265a8e2c7 (patch)
treefb5048e63e02a2485eb96d27455f43e4b22e8ae0 /server/lib/config.ts
parenteb34ec30e0b57286fc6f85160490d2e973a3b0b1 (diff)
downloadPeerTube-2539932e16129992a2c0889b4ff527c265a8e2c7.tar.gz
PeerTube-2539932e16129992a2c0889b4ff527c265a8e2c7.tar.zst
PeerTube-2539932e16129992a2c0889b4ff527c265a8e2c7.zip
Instance homepage support (#4007)
* Prepare homepage parsers * Add ability to update instance hompage * Add ability to set homepage as landing page * Add homepage preview in admin * Dynamically update left menu for homepage * Inject home content in homepage * Add videos list and channel miniature custom markup * Remove unused elements in markup service
Diffstat (limited to 'server/lib/config.ts')
-rw-r--r--server/lib/config.ts274
1 files changed, 0 insertions, 274 deletions
diff --git a/server/lib/config.ts b/server/lib/config.ts
deleted file mode 100644
index 18d49f05a..000000000
--- a/server/lib/config.ts
+++ /dev/null
@@ -1,274 +0,0 @@
1import { isSignupAllowed, isSignupAllowedForCurrentIP } from '@server/helpers/signup'
2import { getServerCommit } from '@server/helpers/utils'
3import { CONFIG, isEmailEnabled } from '@server/initializers/config'
4import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '@server/initializers/constants'
5import { HTMLServerConfig, RegisteredExternalAuthConfig, RegisteredIdAndPassAuthConfig, ServerConfig } from '@shared/models'
6import { Hooks } from './plugins/hooks'
7import { PluginManager } from './plugins/plugin-manager'
8import { getThemeOrDefault } from './plugins/theme-utils'
9import { VideoTranscodingProfilesManager } from './transcoding/video-transcoding-profiles'
10
11async function getServerConfig (ip?: string): Promise<ServerConfig> {
12 const { allowed } = await Hooks.wrapPromiseFun(
13 isSignupAllowed,
14 {
15 ip
16 },
17 'filter:api.user.signup.allowed.result'
18 )
19
20 const allowedForCurrentIP = isSignupAllowedForCurrentIP(ip)
21
22 const signup = {
23 allowed,
24 allowedForCurrentIP,
25 requiresEmailVerification: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION
26 }
27
28 const htmlConfig = await getHTMLServerConfig()
29
30 return { ...htmlConfig, signup }
31}
32
33// Config injected in HTML
34let serverCommit: string
35async function getHTMLServerConfig (): Promise<HTMLServerConfig> {
36 if (serverCommit === undefined) serverCommit = await getServerCommit()
37
38 const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME)
39
40 return {
41 instance: {
42 name: CONFIG.INSTANCE.NAME,
43 shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION,
44 isNSFW: CONFIG.INSTANCE.IS_NSFW,
45 defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
46 defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE,
47 customizations: {
48 javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT,
49 css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS
50 }
51 },
52 search: {
53 remoteUri: {
54 users: CONFIG.SEARCH.REMOTE_URI.USERS,
55 anonymous: CONFIG.SEARCH.REMOTE_URI.ANONYMOUS
56 },
57 searchIndex: {
58 enabled: CONFIG.SEARCH.SEARCH_INDEX.ENABLED,
59 url: CONFIG.SEARCH.SEARCH_INDEX.URL,
60 disableLocalSearch: CONFIG.SEARCH.SEARCH_INDEX.DISABLE_LOCAL_SEARCH,
61 isDefaultSearch: CONFIG.SEARCH.SEARCH_INDEX.IS_DEFAULT_SEARCH
62 }
63 },
64 plugin: {
65 registered: getRegisteredPlugins(),
66 registeredExternalAuths: getExternalAuthsPlugins(),
67 registeredIdAndPassAuths: getIdAndPassAuthPlugins()
68 },
69 theme: {
70 registered: getRegisteredThemes(),
71 default: defaultTheme
72 },
73 email: {
74 enabled: isEmailEnabled()
75 },
76 contactForm: {
77 enabled: CONFIG.CONTACT_FORM.ENABLED
78 },
79 serverVersion: PEERTUBE_VERSION,
80 serverCommit,
81 transcoding: {
82 hls: {
83 enabled: CONFIG.TRANSCODING.HLS.ENABLED
84 },
85 webtorrent: {
86 enabled: CONFIG.TRANSCODING.WEBTORRENT.ENABLED
87 },
88 enabledResolutions: getEnabledResolutions('vod'),
89 profile: CONFIG.TRANSCODING.PROFILE,
90 availableProfiles: VideoTranscodingProfilesManager.Instance.getAvailableProfiles('vod')
91 },
92 live: {
93 enabled: CONFIG.LIVE.ENABLED,
94
95 allowReplay: CONFIG.LIVE.ALLOW_REPLAY,
96 maxDuration: CONFIG.LIVE.MAX_DURATION,
97 maxInstanceLives: CONFIG.LIVE.MAX_INSTANCE_LIVES,
98 maxUserLives: CONFIG.LIVE.MAX_USER_LIVES,
99
100 transcoding: {
101 enabled: CONFIG.LIVE.TRANSCODING.ENABLED,
102 enabledResolutions: getEnabledResolutions('live'),
103 profile: CONFIG.LIVE.TRANSCODING.PROFILE,
104 availableProfiles: VideoTranscodingProfilesManager.Instance.getAvailableProfiles('live')
105 },
106
107 rtmp: {
108 port: CONFIG.LIVE.RTMP.PORT
109 }
110 },
111 import: {
112 videos: {
113 http: {
114 enabled: CONFIG.IMPORT.VIDEOS.HTTP.ENABLED
115 },
116 torrent: {
117 enabled: CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED
118 }
119 }
120 },
121 autoBlacklist: {
122 videos: {
123 ofUsers: {
124 enabled: CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED
125 }
126 }
127 },
128 avatar: {
129 file: {
130 size: {
131 max: CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max
132 },
133 extensions: CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME
134 }
135 },
136 banner: {
137 file: {
138 size: {
139 max: CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max
140 },
141 extensions: CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME
142 }
143 },
144 video: {
145 image: {
146 extensions: CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME,
147 size: {
148 max: CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max
149 }
150 },
151 file: {
152 extensions: CONSTRAINTS_FIELDS.VIDEOS.EXTNAME
153 }
154 },
155 videoCaption: {
156 file: {
157 size: {
158 max: CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max
159 },
160 extensions: CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.EXTNAME
161 }
162 },
163 user: {
164 videoQuota: CONFIG.USER.VIDEO_QUOTA,
165 videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY
166 },
167 trending: {
168 videos: {
169 intervalDays: CONFIG.TRENDING.VIDEOS.INTERVAL_DAYS,
170 algorithms: {
171 enabled: CONFIG.TRENDING.VIDEOS.ALGORITHMS.ENABLED,
172 default: CONFIG.TRENDING.VIDEOS.ALGORITHMS.DEFAULT
173 }
174 }
175 },
176 tracker: {
177 enabled: CONFIG.TRACKER.ENABLED
178 },
179
180 followings: {
181 instance: {
182 autoFollowIndex: {
183 indexUrl: CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_INDEX.INDEX_URL
184 }
185 }
186 },
187
188 broadcastMessage: {
189 enabled: CONFIG.BROADCAST_MESSAGE.ENABLED,
190 message: CONFIG.BROADCAST_MESSAGE.MESSAGE,
191 level: CONFIG.BROADCAST_MESSAGE.LEVEL,
192 dismissable: CONFIG.BROADCAST_MESSAGE.DISMISSABLE
193 }
194 }
195}
196
197function getRegisteredThemes () {
198 return PluginManager.Instance.getRegisteredThemes()
199 .map(t => ({
200 name: t.name,
201 version: t.version,
202 description: t.description,
203 css: t.css,
204 clientScripts: t.clientScripts
205 }))
206}
207
208function getRegisteredPlugins () {
209 return PluginManager.Instance.getRegisteredPlugins()
210 .map(p => ({
211 name: p.name,
212 version: p.version,
213 description: p.description,
214 clientScripts: p.clientScripts
215 }))
216}
217
218function getEnabledResolutions (type: 'vod' | 'live') {
219 const transcoding = type === 'vod'
220 ? CONFIG.TRANSCODING
221 : CONFIG.LIVE.TRANSCODING
222
223 return Object.keys(transcoding.RESOLUTIONS)
224 .filter(key => transcoding.ENABLED && transcoding.RESOLUTIONS[key] === true)
225 .map(r => parseInt(r, 10))
226}
227
228// ---------------------------------------------------------------------------
229
230export {
231 getServerConfig,
232 getRegisteredThemes,
233 getEnabledResolutions,
234 getRegisteredPlugins,
235 getHTMLServerConfig
236}
237
238// ---------------------------------------------------------------------------
239
240function getIdAndPassAuthPlugins () {
241 const result: RegisteredIdAndPassAuthConfig[] = []
242
243 for (const p of PluginManager.Instance.getIdAndPassAuths()) {
244 for (const auth of p.idAndPassAuths) {
245 result.push({
246 npmName: p.npmName,
247 name: p.name,
248 version: p.version,
249 authName: auth.authName,
250 weight: auth.getWeight()
251 })
252 }
253 }
254
255 return result
256}
257
258function getExternalAuthsPlugins () {
259 const result: RegisteredExternalAuthConfig[] = []
260
261 for (const p of PluginManager.Instance.getExternalAuths()) {
262 for (const auth of p.externalAuths) {
263 result.push({
264 npmName: p.npmName,
265 name: p.name,
266 version: p.version,
267 authName: auth.authName,
268 authDisplayName: auth.authDisplayName()
269 })
270 }
271 }
272
273 return result
274}