cobalt/src/modules/config.js

70 lines
2.5 KiB
JavaScript
Raw Normal View History

import UrlPattern from "url-pattern";
import { loadJSON } from "./sub/loadFromFs.js";
2024-05-12 15:06:04 +01:00
const config = loadJSON("./src/config.json");
const packageJson = loadJSON("./package.json");
const servicesConfigJson = loadJSON("./src/modules/processing/servicesConfig.json");
Object.values(servicesConfigJson.config).forEach(service => {
service.patterns = service.patterns.map(
pattern => new UrlPattern(pattern, {
segmentValueCharset: UrlPattern.defaultOptions.segmentValueCharset + '@\\.'
})
)
})
const
apiURL = process.env.API_URL || '',
// WEB mode related environment variables
webEnvs = {
webPort: process.env.WEB_PORT || 9001,
webURL: process.env.WEB_URL || '',
showSponsors: !!process.env.SHOW_SPONSORS,
isBeta: !!process.env.IS_BETA,
plausibleHostname: process.env.PLAUSIBLE_HOSTNAME,
apiURL
},
// API mode related environment variables
apiEnvs = {
apiURL,
apiPort: process.env.API_PORT || 9000,
apiName: process.env.API_NAME || 'unknown',
listenAddress: process.env.API_LISTEN_ADDRESS,
freebindCIDR: process.platform === 'linux' && process.env.FREEBIND_CIDR,
corsWildcard: process.env.CORS_WILDCARD !== '0',
corsURL: process.env.CORS_URL,
cookiePath: process.env.COOKIE_PATH,
rateLimitWindow: (process.env.RATELIMIT_WINDOW && parseInt(process.env.RATELIMIT_WINDOW)) || 60,
rateLimitMax: (process.env.RATELIMIT_MAX && parseInt(process.env.RATELIMIT_MAX)) || 20,
durationLimit: (process.env.DURATION_LIMIT && parseInt(process.env.DURATION_LIMIT)) || 10800,
2024-05-16 16:00:11 +01:00
streamLifespan: 90,
2024-05-14 10:37:41 +01:00
processingPriority: process.platform !== 'win32'
&& process.env.PROCESSING_PRIORITY
&& parseInt(process.env.PROCESSING_PRIORITY)
}
export const
services = servicesConfigJson.config,
hlsExceptions = servicesConfigJson.hlsExceptions,
audioIgnore = servicesConfigJson.audioIgnore,
2022-08-16 08:14:19 +01:00
version = packageJson.version,
genericUserAgent = config.genericUserAgent,
2024-05-14 10:37:41 +01:00
repo = packageJson.bugs.url.replace('/issues', ''),
2022-08-16 08:14:19 +01:00
authorInfo = config.authorInfo,
donations = config.donations,
ffmpegArgs = config.ffmpegArgs,
supportedAudio = config.supportedAudio,
celebrations = config.celebrations,
links = config.links,
sponsors = config.sponsors,
mode = (apiURL && !webEnvs.webURL) ? 'API' :
(webEnvs.webURL && apiURL) ? 'WEB' : undefined,
env = mode === 'API' ? apiEnvs : webEnvs