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

25 lines
769 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'
2019-07-09 11:45:19 +02:00
2019-07-10 14:06:19 +02:00
function getThemeOrDefault (name: string, defaultTheme: string) {
2019-07-09 11:45:19 +02:00
if (isThemeRegistered(name)) return name
// Fallback to admin default theme
2019-07-10 14:06:19 +02:00
if (name !== CONFIG.THEME.DEFAULT) return getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME)
2019-07-09 11:45:19 +02:00
2019-07-10 14:06:19 +02:00
return defaultTheme
2019-07-09 11:45:19 +02:00
}
function isThemeRegistered (name: string) {
2019-07-10 14:06:19 +02:00
if (name === DEFAULT_THEME_NAME || name === DEFAULT_USER_THEME_NAME) return true
2019-07-09 11:45:19 +02:00
return !!PluginManager.Instance.getRegisteredThemes()
.find(r => r.name === name)
}
export {
getThemeOrDefault,
isThemeRegistered
}