X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fconfig.ts;h=81518bbb54332a3987ace41c61542e35a569de60;hb=8d2be0ed7bb87283a1ec98609df6b82d83db706a;hp=dd06a0597da6ae63b2ded487ef3686b91457da89;hpb=d3e56c0c4b307c99e83fbafb7f2c5884cbc20055;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index dd06a0597..81518bbb5 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts @@ -1,10 +1,10 @@ import * as express from 'express' -import { omit, snakeCase } from 'lodash' +import { snakeCase } from 'lodash' 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 { CONFIG, CONSTRAINTS_FIELDS, reloadConfig } from '../../initializers' +import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME } from '../../initializers/constants' import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' import { customConfigUpdateValidator } from '../../middlewares/validators/config' import { ClientHtml } from '../../lib/client-html' @@ -14,6 +14,9 @@ import { getServerCommit } from '../../helpers/utils' import { Emailer } from '../../lib/emailer' import { isNumeric } from 'validator' import { objectConverter } from '../../helpers/core-utils' +import { CONFIG, reloadConfig } from '../../initializers/config' +import { PluginManager } from '../../lib/plugins/plugin-manager' +import { getThemeOrDefault } from '../../lib/plugins/theme-utils' const packageJSON = require('../../../../package.json') const configRouter = express.Router() @@ -50,20 +53,47 @@ async function getConfig (req: express.Request, res: express.Response) { if (serverCommit === undefined) serverCommit = await getServerCommit() const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS) - .filter(key => CONFIG.TRANSCODING.ENABLED === CONFIG.TRANSCODING.RESOLUTIONS[key] === true) + .filter(key => CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.RESOLUTIONS[key] === true) .map(r => parseInt(r, 10)) + const registeredPlugins = PluginManager.Instance.getRegisteredPlugins() + .map(p => ({ + name: p.name, + version: p.version, + description: p.description, + clientScripts: p.clientScripts + })) + + const registeredThemes = PluginManager.Instance.getRegisteredThemes() + .map(t => ({ + name: t.name, + version: t.version, + description: t.description, + css: t.css, + clientScripts: t.clientScripts + })) + + const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME) + const json: ServerConfig = { instance: { name: CONFIG.INSTANCE.NAME, shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION, defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE, + isNSFW: CONFIG.INSTANCE.IS_NSFW, defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, customizations: { javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT, css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS } }, + plugin: { + registered: registeredPlugins + }, + theme: { + registered: registeredThemes, + default: defaultTheme + }, email: { enabled: Emailer.isEnabled() }, @@ -78,6 +108,9 @@ async function getConfig (req: express.Request, res: express.Response) { requiresEmailVerification: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION }, transcoding: { + hls: { + enabled: CONFIG.TRANSCODING.HLS.ENABLED + }, enabledResolutions }, import: { @@ -90,6 +123,13 @@ async function getConfig (req: express.Request, res: express.Response) { } } }, + autoBlacklist: { + videos: { + ofUsers: { + enabled: CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED + } + } + }, avatar: { file: { size: { @@ -120,13 +160,21 @@ async function getConfig (req: express.Request, res: express.Response) { user: { videoQuota: CONFIG.USER.VIDEO_QUOTA, videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY + }, + trending: { + videos: { + intervalDays: CONFIG.TRENDING.VIDEOS.INTERVAL_DAYS + } + }, + tracker: { + enabled: CONFIG.TRACKER.ENABLED } } return res.json(json) } -function getAbout (req: express.Request, res: express.Response, next: express.NextFunction) { +function getAbout (req: express.Request, res: express.Response) { const about: About = { instance: { name: CONFIG.INSTANCE.NAME, @@ -139,13 +187,13 @@ function getAbout (req: express.Request, res: express.Response, next: express.Ne return res.json(about).end() } -async function getCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { +async function getCustomConfig (req: express.Request, res: express.Response) { const data = customConfig() return res.json(data).end() } -async function deleteCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { +async function deleteCustomConfig (req: express.Request, res: express.Response) { await remove(CONFIG.CUSTOM_FILE) auditLogger.delete(getAuditIdFromRes(res), new CustomConfigAuditView(customConfig())) @@ -158,7 +206,7 @@ async function deleteCustomConfig (req: express.Request, res: express.Response, return res.json(data).end() } -async function updateCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { +async function updateCustomConfig (req: express.Request, res: express.Response) { const oldCustomConfigAuditKeys = new CustomConfigAuditView(customConfig()) // camelCase to snake_case key + Force number conversion @@ -195,6 +243,7 @@ function customConfig (): CustomConfig { shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION, description: CONFIG.INSTANCE.DESCRIPTION, terms: CONFIG.INSTANCE.TERMS, + isNSFW: CONFIG.INSTANCE.IS_NSFW, defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE, defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, customizations: { @@ -202,6 +251,9 @@ function customConfig (): CustomConfig { javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT } }, + theme: { + default: CONFIG.THEME.DEFAULT + }, services: { twitter: { username: CONFIG.SERVICES.TWITTER.USERNAME, @@ -234,13 +286,18 @@ function customConfig (): CustomConfig { transcoding: { enabled: CONFIG.TRANSCODING.ENABLED, allowAdditionalExtensions: CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS, + allowAudioFiles: CONFIG.TRANSCODING.ALLOW_AUDIO_FILES, threads: CONFIG.TRANSCODING.THREADS, resolutions: { '240p': CONFIG.TRANSCODING.RESOLUTIONS[ '240p' ], '360p': CONFIG.TRANSCODING.RESOLUTIONS[ '360p' ], '480p': CONFIG.TRANSCODING.RESOLUTIONS[ '480p' ], '720p': CONFIG.TRANSCODING.RESOLUTIONS[ '720p' ], - '1080p': CONFIG.TRANSCODING.RESOLUTIONS[ '1080p' ] + '1080p': CONFIG.TRANSCODING.RESOLUTIONS[ '1080p' ], + '2160p': CONFIG.TRANSCODING.RESOLUTIONS[ '2160p' ] + }, + hls: { + enabled: CONFIG.TRANSCODING.HLS.ENABLED } }, import: { @@ -252,6 +309,19 @@ function customConfig (): CustomConfig { enabled: CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED } } + }, + autoBlacklist: { + videos: { + ofUsers: { + enabled: CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED + } + } + }, + followers: { + instance: { + enabled: CONFIG.FOLLOWERS.INSTANCE.ENABLED, + manualApproval: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL + } } } }