2023-07-31 14:34:36 +02:00
|
|
|
import {
|
|
|
|
HTMLServerConfig,
|
|
|
|
RegisteredExternalAuthConfig,
|
|
|
|
RegisteredIdAndPassAuthConfig,
|
|
|
|
ServerConfig,
|
|
|
|
VideoResolutionType
|
|
|
|
} from '@peertube/peertube-models'
|
|
|
|
import { getServerCommit } from '@server/helpers/version.js'
|
|
|
|
import { CONFIG, isEmailEnabled } from '@server/initializers/config.js'
|
|
|
|
import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '@server/initializers/constants.js'
|
|
|
|
import { isSignupAllowed, isSignupAllowedForCurrentIP } from '@server/lib/signup.js'
|
|
|
|
import { ActorCustomPageModel } from '@server/models/account/actor-custom-page.js'
|
|
|
|
import { PluginModel } from '@server/models/server/plugin.js'
|
|
|
|
import { Hooks } from './plugins/hooks.js'
|
|
|
|
import { PluginManager } from './plugins/plugin-manager.js'
|
|
|
|
import { getThemeOrDefault } from './plugins/theme-utils.js'
|
|
|
|
import { VideoTranscodingProfilesManager } from './transcoding/default-transcoding-profiles.js'
|
2024-02-23 14:27:11 +01:00
|
|
|
import { ActorImageModel } from '@server/models/actor/actor-image.js'
|
2021-05-27 15:59:55 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Used to send the server config to clients (using REST/API or plugins API)
|
|
|
|
* We need a singleton class to manage config state depending on external events (to build menu entries etc)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
class ServerConfigManager {
|
|
|
|
|
|
|
|
private static instance: ServerConfigManager
|
|
|
|
|
|
|
|
private serverCommit: string
|
|
|
|
|
|
|
|
private homepageEnabled = false
|
|
|
|
|
|
|
|
private constructor () {}
|
|
|
|
|
|
|
|
async init () {
|
|
|
|
const instanceHomepage = await ActorCustomPageModel.loadInstanceHomepage()
|
|
|
|
|
|
|
|
this.updateHomepageState(instanceHomepage?.content)
|
|
|
|
}
|
|
|
|
|
|
|
|
updateHomepageState (content: string) {
|
|
|
|
this.homepageEnabled = !!content
|
|
|
|
}
|
|
|
|
|
|
|
|
async getHTMLServerConfig (): Promise<HTMLServerConfig> {
|
|
|
|
if (this.serverCommit === undefined) this.serverCommit = await getServerCommit()
|
|
|
|
|
|
|
|
const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME)
|
|
|
|
|
2024-02-23 14:27:11 +01:00
|
|
|
const { avatars, banners } = await ActorImageModel.listServerActorImages()
|
|
|
|
|
2021-05-27 15:59:55 +02:00
|
|
|
return {
|
2021-10-12 14:23:44 +02:00
|
|
|
client: {
|
|
|
|
videos: {
|
|
|
|
miniature: {
|
2022-03-08 13:39:27 +01:00
|
|
|
displayAuthorAvatar: CONFIG.CLIENT.VIDEOS.MINIATURE.DISPLAY_AUTHOR_AVATAR,
|
2021-10-12 14:25:30 +02:00
|
|
|
preferAuthorDisplayName: CONFIG.CLIENT.VIDEOS.MINIATURE.PREFER_AUTHOR_DISPLAY_NAME
|
2022-03-16 10:57:36 +01:00
|
|
|
},
|
|
|
|
resumableUpload: {
|
|
|
|
maxChunkSize: CONFIG.CLIENT.VIDEOS.RESUMABLE_UPLOAD.MAX_CHUNK_SIZE
|
2021-10-12 14:23:44 +02:00
|
|
|
}
|
2021-12-03 17:04:47 +01:00
|
|
|
},
|
|
|
|
menu: {
|
|
|
|
login: {
|
|
|
|
redirectOnSingleExternalAuth: CONFIG.CLIENT.MENU.LOGIN.REDIRECT_ON_SINGLE_EXTERNAL_AUTH
|
|
|
|
}
|
2021-10-12 14:23:44 +02:00
|
|
|
}
|
|
|
|
},
|
2021-10-14 11:35:43 +02:00
|
|
|
|
2021-12-14 17:17:01 +01:00
|
|
|
defaults: {
|
|
|
|
publish: {
|
|
|
|
downloadEnabled: CONFIG.DEFAULTS.PUBLISH.DOWNLOAD_ENABLED,
|
|
|
|
commentsEnabled: CONFIG.DEFAULTS.PUBLISH.COMMENTS_ENABLED,
|
|
|
|
privacy: CONFIG.DEFAULTS.PUBLISH.PRIVACY,
|
|
|
|
licence: CONFIG.DEFAULTS.PUBLISH.LICENCE
|
2021-12-15 15:58:10 +01:00
|
|
|
},
|
|
|
|
p2p: {
|
2021-12-16 09:38:27 +01:00
|
|
|
webapp: {
|
|
|
|
enabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED
|
|
|
|
},
|
|
|
|
embed: {
|
|
|
|
enabled: CONFIG.DEFAULTS.P2P.EMBED.ENABLED
|
|
|
|
}
|
2021-12-14 17:17:01 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-10-14 11:35:43 +02:00
|
|
|
webadmin: {
|
|
|
|
configuration: {
|
|
|
|
edition: {
|
|
|
|
allowed: CONFIG.WEBADMIN.CONFIGURATION.EDITION.ALLOWED
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-05-27 15:59:55 +02:00
|
|
|
instance: {
|
|
|
|
name: CONFIG.INSTANCE.NAME,
|
|
|
|
shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION,
|
|
|
|
isNSFW: CONFIG.INSTANCE.IS_NSFW,
|
|
|
|
defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
|
|
|
|
defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE,
|
|
|
|
customizations: {
|
|
|
|
javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT,
|
|
|
|
css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS
|
2024-02-23 14:27:11 +01:00
|
|
|
},
|
|
|
|
avatars: avatars.map(a => a.toFormattedJSON()),
|
|
|
|
banners: banners.map(b => b.toFormattedJSON())
|
2021-05-27 15:59:55 +02:00
|
|
|
},
|
|
|
|
search: {
|
|
|
|
remoteUri: {
|
|
|
|
users: CONFIG.SEARCH.REMOTE_URI.USERS,
|
|
|
|
anonymous: CONFIG.SEARCH.REMOTE_URI.ANONYMOUS
|
|
|
|
},
|
|
|
|
searchIndex: {
|
|
|
|
enabled: CONFIG.SEARCH.SEARCH_INDEX.ENABLED,
|
|
|
|
url: CONFIG.SEARCH.SEARCH_INDEX.URL,
|
|
|
|
disableLocalSearch: CONFIG.SEARCH.SEARCH_INDEX.DISABLE_LOCAL_SEARCH,
|
|
|
|
isDefaultSearch: CONFIG.SEARCH.SEARCH_INDEX.IS_DEFAULT_SEARCH
|
|
|
|
}
|
|
|
|
},
|
|
|
|
plugin: {
|
|
|
|
registered: this.getRegisteredPlugins(),
|
|
|
|
registeredExternalAuths: this.getExternalAuthsPlugins(),
|
|
|
|
registeredIdAndPassAuths: this.getIdAndPassAuthPlugins()
|
|
|
|
},
|
|
|
|
theme: {
|
|
|
|
registered: this.getRegisteredThemes(),
|
|
|
|
default: defaultTheme
|
|
|
|
},
|
|
|
|
email: {
|
|
|
|
enabled: isEmailEnabled()
|
|
|
|
},
|
|
|
|
contactForm: {
|
|
|
|
enabled: CONFIG.CONTACT_FORM.ENABLED
|
|
|
|
},
|
|
|
|
serverVersion: PEERTUBE_VERSION,
|
|
|
|
serverCommit: this.serverCommit,
|
|
|
|
transcoding: {
|
2023-04-21 14:55:10 +02:00
|
|
|
remoteRunners: {
|
|
|
|
enabled: CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.REMOTE_RUNNERS.ENABLED
|
|
|
|
},
|
2021-05-27 15:59:55 +02:00
|
|
|
hls: {
|
2023-04-21 14:55:10 +02:00
|
|
|
enabled: CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.HLS.ENABLED
|
2021-05-27 15:59:55 +02:00
|
|
|
},
|
2023-07-11 09:52:14 +02:00
|
|
|
web_videos: {
|
|
|
|
enabled: CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.WEB_VIDEOS.ENABLED
|
2021-05-27 15:59:55 +02:00
|
|
|
},
|
|
|
|
enabledResolutions: this.getEnabledResolutions('vod'),
|
|
|
|
profile: CONFIG.TRANSCODING.PROFILE,
|
|
|
|
availableProfiles: VideoTranscodingProfilesManager.Instance.getAvailableProfiles('vod')
|
|
|
|
},
|
|
|
|
live: {
|
|
|
|
enabled: CONFIG.LIVE.ENABLED,
|
|
|
|
|
|
|
|
allowReplay: CONFIG.LIVE.ALLOW_REPLAY,
|
2022-03-04 13:40:02 +01:00
|
|
|
latencySetting: {
|
|
|
|
enabled: CONFIG.LIVE.LATENCY_SETTING.ENABLED
|
|
|
|
},
|
|
|
|
|
2021-05-27 15:59:55 +02:00
|
|
|
maxDuration: CONFIG.LIVE.MAX_DURATION,
|
|
|
|
maxInstanceLives: CONFIG.LIVE.MAX_INSTANCE_LIVES,
|
|
|
|
maxUserLives: CONFIG.LIVE.MAX_USER_LIVES,
|
|
|
|
|
|
|
|
transcoding: {
|
|
|
|
enabled: CONFIG.LIVE.TRANSCODING.ENABLED,
|
2023-04-21 14:55:10 +02:00
|
|
|
remoteRunners: {
|
|
|
|
enabled: CONFIG.LIVE.TRANSCODING.ENABLED && CONFIG.LIVE.TRANSCODING.REMOTE_RUNNERS.ENABLED
|
|
|
|
},
|
2021-05-27 15:59:55 +02:00
|
|
|
enabledResolutions: this.getEnabledResolutions('live'),
|
|
|
|
profile: CONFIG.LIVE.TRANSCODING.PROFILE,
|
|
|
|
availableProfiles: VideoTranscodingProfilesManager.Instance.getAvailableProfiles('live')
|
|
|
|
},
|
|
|
|
|
|
|
|
rtmp: {
|
|
|
|
port: CONFIG.LIVE.RTMP.PORT
|
|
|
|
}
|
|
|
|
},
|
2022-03-22 16:58:49 +01:00
|
|
|
videoStudio: {
|
2023-05-04 15:29:34 +02:00
|
|
|
enabled: CONFIG.VIDEO_STUDIO.ENABLED,
|
|
|
|
remoteRunners: {
|
|
|
|
enabled: CONFIG.VIDEO_STUDIO.REMOTE_RUNNERS.ENABLED
|
|
|
|
}
|
2022-02-11 10:51:33 +01:00
|
|
|
},
|
2023-07-19 16:02:49 +02:00
|
|
|
videoFile: {
|
|
|
|
update: {
|
|
|
|
enabled: CONFIG.VIDEO_FILE.UPDATE.ENABLED
|
|
|
|
}
|
|
|
|
},
|
2021-05-27 15:59:55 +02:00
|
|
|
import: {
|
|
|
|
videos: {
|
|
|
|
http: {
|
|
|
|
enabled: CONFIG.IMPORT.VIDEOS.HTTP.ENABLED
|
|
|
|
},
|
|
|
|
torrent: {
|
|
|
|
enabled: CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED
|
|
|
|
}
|
2022-08-10 09:53:39 +02:00
|
|
|
},
|
|
|
|
videoChannelSynchronization: {
|
|
|
|
enabled: CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.ENABLED
|
2024-02-12 10:47:52 +01:00
|
|
|
},
|
|
|
|
users: {
|
|
|
|
enabled: CONFIG.IMPORT.USERS.ENABLED
|
|
|
|
}
|
|
|
|
},
|
|
|
|
export: {
|
|
|
|
users: {
|
|
|
|
enabled: CONFIG.EXPORT.USERS.ENABLED,
|
|
|
|
exportExpiration: CONFIG.EXPORT.USERS.EXPORT_EXPIRATION,
|
|
|
|
maxUserVideoQuota: CONFIG.EXPORT.USERS.MAX_USER_VIDEO_QUOTA
|
2021-05-27 15:59:55 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
autoBlacklist: {
|
|
|
|
videos: {
|
|
|
|
ofUsers: {
|
|
|
|
enabled: CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
avatar: {
|
|
|
|
file: {
|
|
|
|
size: {
|
|
|
|
max: CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max
|
|
|
|
},
|
|
|
|
extensions: CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME
|
|
|
|
}
|
|
|
|
},
|
|
|
|
banner: {
|
|
|
|
file: {
|
|
|
|
size: {
|
|
|
|
max: CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max
|
|
|
|
},
|
|
|
|
extensions: CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME
|
|
|
|
}
|
|
|
|
},
|
|
|
|
video: {
|
|
|
|
image: {
|
|
|
|
extensions: CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME,
|
|
|
|
size: {
|
|
|
|
max: CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max
|
|
|
|
}
|
|
|
|
},
|
|
|
|
file: {
|
|
|
|
extensions: CONSTRAINTS_FIELDS.VIDEOS.EXTNAME
|
|
|
|
}
|
|
|
|
},
|
|
|
|
videoCaption: {
|
|
|
|
file: {
|
|
|
|
size: {
|
|
|
|
max: CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max
|
|
|
|
},
|
|
|
|
extensions: CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.EXTNAME
|
|
|
|
}
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
videoQuota: CONFIG.USER.VIDEO_QUOTA,
|
|
|
|
videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY
|
|
|
|
},
|
2021-10-26 16:42:10 +02:00
|
|
|
videoChannels: {
|
|
|
|
maxPerUser: CONFIG.VIDEO_CHANNELS.MAX_PER_USER
|
|
|
|
},
|
2021-05-27 15:59:55 +02:00
|
|
|
trending: {
|
|
|
|
videos: {
|
|
|
|
intervalDays: CONFIG.TRENDING.VIDEOS.INTERVAL_DAYS,
|
|
|
|
algorithms: {
|
|
|
|
enabled: CONFIG.TRENDING.VIDEOS.ALGORITHMS.ENABLED,
|
|
|
|
default: CONFIG.TRENDING.VIDEOS.ALGORITHMS.DEFAULT
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
tracker: {
|
|
|
|
enabled: CONFIG.TRACKER.ENABLED
|
|
|
|
},
|
|
|
|
|
|
|
|
followings: {
|
|
|
|
instance: {
|
|
|
|
autoFollowIndex: {
|
|
|
|
indexUrl: CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_INDEX.INDEX_URL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
broadcastMessage: {
|
|
|
|
enabled: CONFIG.BROADCAST_MESSAGE.ENABLED,
|
|
|
|
message: CONFIG.BROADCAST_MESSAGE.MESSAGE,
|
|
|
|
level: CONFIG.BROADCAST_MESSAGE.LEVEL,
|
|
|
|
dismissable: CONFIG.BROADCAST_MESSAGE.DISMISSABLE
|
|
|
|
},
|
|
|
|
|
|
|
|
homepage: {
|
|
|
|
enabled: this.homepageEnabled
|
2023-12-13 10:06:25 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
openTelemetry: {
|
|
|
|
metrics: {
|
|
|
|
enabled: CONFIG.OPEN_TELEMETRY.METRICS.ENABLED,
|
|
|
|
playbackStatsInterval: CONFIG.OPEN_TELEMETRY.METRICS.PLAYBACK_STATS_INTERVAL
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
views: {
|
|
|
|
videos: {
|
|
|
|
watchingInterval: {
|
|
|
|
anonymous: CONFIG.VIEWS.VIDEOS.WATCHING_INTERVAL.ANONYMOUS,
|
|
|
|
users: CONFIG.VIEWS.VIDEOS.WATCHING_INTERVAL.USERS
|
|
|
|
}
|
|
|
|
}
|
2023-12-27 10:39:09 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
storyboards: {
|
|
|
|
enabled: CONFIG.STORYBOARDS.ENABLED
|
2021-05-27 15:59:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async getServerConfig (ip?: string): Promise<ServerConfig> {
|
|
|
|
const { allowed } = await Hooks.wrapPromiseFun(
|
|
|
|
isSignupAllowed,
|
2023-01-19 09:27:16 +01:00
|
|
|
|
2021-05-27 15:59:55 +02:00
|
|
|
{
|
2023-01-19 09:27:16 +01:00
|
|
|
ip,
|
|
|
|
signupMode: CONFIG.SIGNUP.REQUIRES_APPROVAL
|
|
|
|
? 'request-registration'
|
|
|
|
: 'direct-registration'
|
2021-05-27 15:59:55 +02:00
|
|
|
},
|
2023-01-19 09:27:16 +01:00
|
|
|
|
|
|
|
CONFIG.SIGNUP.REQUIRES_APPROVAL
|
|
|
|
? 'filter:api.user.request-signup.allowed.result'
|
|
|
|
: 'filter:api.user.signup.allowed.result'
|
2021-05-27 15:59:55 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const allowedForCurrentIP = isSignupAllowedForCurrentIP(ip)
|
|
|
|
|
|
|
|
const signup = {
|
|
|
|
allowed,
|
|
|
|
allowedForCurrentIP,
|
2021-04-24 11:57:01 +02:00
|
|
|
minimumAge: CONFIG.SIGNUP.MINIMUM_AGE,
|
2023-01-19 09:27:16 +01:00
|
|
|
requiresApproval: CONFIG.SIGNUP.REQUIRES_APPROVAL,
|
2021-05-27 15:59:55 +02:00
|
|
|
requiresEmailVerification: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION
|
|
|
|
}
|
|
|
|
|
|
|
|
const htmlConfig = await this.getHTMLServerConfig()
|
|
|
|
|
|
|
|
return { ...htmlConfig, signup }
|
|
|
|
}
|
|
|
|
|
|
|
|
getRegisteredThemes () {
|
|
|
|
return PluginManager.Instance.getRegisteredThemes()
|
|
|
|
.map(t => ({
|
2021-12-29 14:08:07 +01:00
|
|
|
npmName: PluginModel.buildNpmName(t.name, t.type),
|
2021-05-27 15:59:55 +02:00
|
|
|
name: t.name,
|
|
|
|
version: t.version,
|
|
|
|
description: t.description,
|
|
|
|
css: t.css,
|
|
|
|
clientScripts: t.clientScripts
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
getRegisteredPlugins () {
|
|
|
|
return PluginManager.Instance.getRegisteredPlugins()
|
|
|
|
.map(p => ({
|
2021-12-29 14:08:07 +01:00
|
|
|
npmName: PluginModel.buildNpmName(p.name, p.type),
|
2021-05-27 15:59:55 +02:00
|
|
|
name: p.name,
|
|
|
|
version: p.version,
|
|
|
|
description: p.description,
|
|
|
|
clientScripts: p.clientScripts
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
getEnabledResolutions (type: 'vod' | 'live') {
|
|
|
|
const transcoding = type === 'vod'
|
|
|
|
? CONFIG.TRANSCODING
|
|
|
|
: CONFIG.LIVE.TRANSCODING
|
|
|
|
|
|
|
|
return Object.keys(transcoding.RESOLUTIONS)
|
|
|
|
.filter(key => transcoding.ENABLED && transcoding.RESOLUTIONS[key] === true)
|
2023-07-31 14:34:36 +02:00
|
|
|
.map(r => parseInt(r, 10) as VideoResolutionType)
|
2021-05-27 15:59:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private getIdAndPassAuthPlugins () {
|
|
|
|
const result: RegisteredIdAndPassAuthConfig[] = []
|
|
|
|
|
|
|
|
for (const p of PluginManager.Instance.getIdAndPassAuths()) {
|
|
|
|
for (const auth of p.idAndPassAuths) {
|
|
|
|
result.push({
|
|
|
|
npmName: p.npmName,
|
|
|
|
name: p.name,
|
|
|
|
version: p.version,
|
|
|
|
authName: auth.authName,
|
|
|
|
weight: auth.getWeight()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
private getExternalAuthsPlugins () {
|
|
|
|
const result: RegisteredExternalAuthConfig[] = []
|
|
|
|
|
|
|
|
for (const p of PluginManager.Instance.getExternalAuths()) {
|
|
|
|
for (const auth of p.externalAuths) {
|
|
|
|
result.push({
|
|
|
|
npmName: p.npmName,
|
|
|
|
name: p.name,
|
|
|
|
version: p.version,
|
|
|
|
authName: auth.authName,
|
|
|
|
authDisplayName: auth.authDisplayName()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
static get Instance () {
|
|
|
|
return this.instance || (this.instance = new this())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
ServerConfigManager
|
|
|
|
}
|