PeerTube/server/core/lib/plugins/theme-utils.ts

21 lines
851 B
TypeScript
Raw Normal View History

import { DEFAULT_THEME_NAME, DEFAULT_USER_THEME_NAME } from '../../initializers/constants.js'
import { PluginManager } from './plugin-manager.js'
import { CONFIG } from '../../initializers/config.js'
import { ServerConfigManager } from '../server-config-manager.js'
2019-07-09 04:45:19 -05:00
export function getThemeOrDefault (name: string, defaultTheme: string) {
2019-07-09 04:45:19 -05:00
if (isThemeRegistered(name)) return name
// Fallback to admin default theme
2019-07-10 07:06:19 -05:00
if (name !== CONFIG.THEME.DEFAULT) return getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME)
2019-07-09 04:45:19 -05:00
2019-07-10 07:06:19 -05:00
return defaultTheme
2019-07-09 04:45:19 -05:00
}
export function isThemeRegistered (name: string) {
2019-07-10 07:06:19 -05:00
if (name === DEFAULT_THEME_NAME || name === DEFAULT_USER_THEME_NAME) return true
2019-07-09 04:45:19 -05:00
return PluginManager.Instance.getRegisteredThemes().some(r => r.name === name) ||
ServerConfigManager.Instance.getBuiltInThemes().some(r => r.name === name)
2019-07-09 04:45:19 -05:00
}