X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fconfig.ts;h=8a00f9835a319c834fe2419206c9c5d451f641dc;hb=6ad88df896e359e428259ff511f6fca3675cb4af;hp=8563b74370bd3f277d825f98d503e28605e83ac7;hpb=18a6f04c071f7a0735eb39b8c67fd51a082d1a31;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 8563b7437..8a00f9835 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts @@ -1,10 +1,10 @@ import * as express from 'express' import { snakeCase } from 'lodash' -import { ServerConfig, ServerConfigPlugin, UserRight } from '../../../shared' +import { ServerConfig, UserRight } from '../../../shared' import { About } from '../../../shared/models/server/about.model' import { CustomConfig } from '../../../shared/models/server/custom-config.model' import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' -import { CONSTRAINTS_FIELDS } from '../../initializers/constants' +import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '../../initializers/constants' import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' import { customConfigUpdateValidator } from '../../middlewares/validators/config' import { ClientHtml } from '../../lib/client-html' @@ -16,9 +16,9 @@ import { isNumeric } from 'validator' import { objectConverter } from '../../helpers/core-utils' import { CONFIG, reloadConfig } from '../../initializers/config' import { PluginManager } from '../../lib/plugins/plugin-manager' -import { PluginType } from '../../../shared/models/plugins/plugin.type' +import { getThemeOrDefault } from '../../lib/plugins/theme-utils' +import { Hooks } from '@server/lib/plugins/hooks' -const packageJSON = require('../../../../package.json') const configRouter = express.Router() const auditLogger = auditLoggerFactory('config') @@ -46,30 +46,19 @@ configRouter.delete('/custom', ) let serverCommit: string + async function getConfig (req: express.Request, res: express.Response) { - const allowed = await isSignupAllowed() + const { allowed } = await Hooks.wrapPromiseFun( + isSignupAllowed, + {}, + 'filter:api.user.signup.allowed.result' + ) + const allowedForCurrentIP = isSignupAllowedForCurrentIP(req.ip) + const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME) if (serverCommit === undefined) serverCommit = await getServerCommit() - const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS) - .filter(key => CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.RESOLUTIONS[key] === true) - .map(r => parseInt(r, 10)) - - const plugins: ServerConfigPlugin[] = [] - const registeredPlugins = PluginManager.Instance.getRegisteredPlugins() - for (const pluginName of Object.keys(registeredPlugins)) { - const plugin = registeredPlugins[ pluginName ] - if (plugin.type !== PluginType.PLUGIN) continue - - plugins.push({ - name: plugin.name, - version: plugin.version, - description: plugin.description, - clientScripts: plugin.clientScripts - }) - } - const json: ServerConfig = { instance: { name: CONFIG.INSTANCE.NAME, @@ -82,14 +71,20 @@ async function getConfig (req: express.Request, res: express.Response) { css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS } }, - plugins, + plugin: { + registered: getRegisteredPlugins() + }, + theme: { + registered: getRegisteredThemes(), + default: defaultTheme + }, email: { enabled: Emailer.isEnabled() }, contactForm: { enabled: CONFIG.CONTACT_FORM.ENABLED }, - serverVersion: packageJSON.version, + serverVersion: PEERTUBE_VERSION, serverCommit, signup: { allowed, @@ -100,7 +95,10 @@ async function getConfig (req: express.Request, res: express.Response) { hls: { enabled: CONFIG.TRANSCODING.HLS.ENABLED }, - enabledResolutions + webtorrent: { + enabled: CONFIG.TRANSCODING.WEBTORRENT.ENABLED + }, + enabledResolutions: getEnabledResolutions() }, import: { videos: { @@ -169,7 +167,19 @@ function getAbout (req: express.Request, res: express.Response) { name: CONFIG.INSTANCE.NAME, shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION, description: CONFIG.INSTANCE.DESCRIPTION, - terms: CONFIG.INSTANCE.TERMS + terms: CONFIG.INSTANCE.TERMS, + codeOfConduct: CONFIG.INSTANCE.CODE_OF_CONDUCT, + + hardwareInformation: CONFIG.INSTANCE.HARDWARE_INFORMATION, + + creationReason: CONFIG.INSTANCE.CREATION_REASON, + moderationInformation: CONFIG.INSTANCE.MODERATION_INFORMATION, + administrator: CONFIG.INSTANCE.ADMINISTRATOR, + maintenanceLifetime: CONFIG.INSTANCE.MAINTENANCE_LIFETIME, + businessModel: CONFIG.INSTANCE.BUSINESS_MODEL, + + languages: CONFIG.INSTANCE.LANGUAGES, + categories: CONFIG.INSTANCE.CATEGORIES } } @@ -232,6 +242,18 @@ function customConfig (): CustomConfig { shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION, description: CONFIG.INSTANCE.DESCRIPTION, terms: CONFIG.INSTANCE.TERMS, + codeOfConduct: CONFIG.INSTANCE.CODE_OF_CONDUCT, + + creationReason: CONFIG.INSTANCE.CREATION_REASON, + moderationInformation: CONFIG.INSTANCE.MODERATION_INFORMATION, + administrator: CONFIG.INSTANCE.ADMINISTRATOR, + maintenanceLifetime: CONFIG.INSTANCE.MAINTENANCE_LIFETIME, + businessModel: CONFIG.INSTANCE.BUSINESS_MODEL, + hardwareInformation: CONFIG.INSTANCE.HARDWARE_INFORMATION, + + languages: CONFIG.INSTANCE.LANGUAGES, + categories: CONFIG.INSTANCE.CATEGORIES, + isNSFW: CONFIG.INSTANCE.IS_NSFW, defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE, defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, @@ -240,6 +262,9 @@ function customConfig (): CustomConfig { javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT } }, + theme: { + default: CONFIG.THEME.DEFAULT + }, services: { twitter: { username: CONFIG.SERVICES.TWITTER.USERNAME, @@ -275,6 +300,7 @@ function customConfig (): CustomConfig { allowAudioFiles: CONFIG.TRANSCODING.ALLOW_AUDIO_FILES, threads: CONFIG.TRANSCODING.THREADS, resolutions: { + '0p': CONFIG.TRANSCODING.RESOLUTIONS[ '0p' ], '240p': CONFIG.TRANSCODING.RESOLUTIONS[ '240p' ], '360p': CONFIG.TRANSCODING.RESOLUTIONS[ '360p' ], '480p': CONFIG.TRANSCODING.RESOLUTIONS[ '480p' ], @@ -282,6 +308,9 @@ function customConfig (): CustomConfig { '1080p': CONFIG.TRANSCODING.RESOLUTIONS[ '1080p' ], '2160p': CONFIG.TRANSCODING.RESOLUTIONS[ '2160p' ] }, + webtorrent: { + enabled: CONFIG.TRANSCODING.WEBTORRENT.ENABLED + }, hls: { enabled: CONFIG.TRANSCODING.HLS.ENABLED } @@ -308,6 +337,18 @@ function customConfig (): CustomConfig { enabled: CONFIG.FOLLOWERS.INSTANCE.ENABLED, manualApproval: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL } + }, + followings: { + instance: { + autoFollowBack: { + enabled: CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_BACK.ENABLED + }, + + autoFollowIndex: { + enabled: CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_INDEX.ENABLED, + indexUrl: CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_INDEX.INDEX_URL + } + } } } } @@ -316,6 +357,7 @@ function convertCustomConfigBody (body: CustomConfig) { function keyConverter (k: string) { // Transcoding resolutions exception if (/^\d{3,4}p$/.exec(k)) return k + if (/^0p$/.exec(k)) return k return snakeCase(k) } @@ -328,3 +370,30 @@ function convertCustomConfigBody (body: CustomConfig) { return objectConverter(body, keyConverter, valueConverter) } + +function getRegisteredThemes () { + return PluginManager.Instance.getRegisteredThemes() + .map(t => ({ + name: t.name, + version: t.version, + description: t.description, + css: t.css, + clientScripts: t.clientScripts + })) +} + +function getEnabledResolutions () { + return Object.keys(CONFIG.TRANSCODING.RESOLUTIONS) + .filter(key => CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.RESOLUTIONS[ key ] === true) + .map(r => parseInt(r, 10)) +} + +function getRegisteredPlugins () { + return PluginManager.Instance.getRegisteredPlugins() + .map(p => ({ + name: p.name, + version: p.version, + description: p.description, + clientScripts: p.clientScripts + })) +}