peertube-plugin-livechat/server/lib/helpers.ts

43 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-04-10 11:57:47 +00:00
import { Response } from 'express'
2021-04-09 19:28:16 +00:00
const packagejson: any = require('../../../package.json')
const version: string = packagejson.version || ''
if (!/^\d+\.\d+\.\d+/.test(version)) {
throw new Error('Incorrect version in package.json.')
}
2021-04-12 18:52:21 +00:00
const pluginName: string = packagejson.name || ''
if (!/^peertube-plugin-[-a-z]+$/.test(pluginName)) {
2021-04-09 19:28:16 +00:00
throw new Error('Incorrect plugin name in package.json.')
}
2021-04-12 18:52:21 +00:00
const pluginShortName = pluginName.substring('peertube-plugin-'.length)
2021-04-09 19:28:16 +00:00
// FIXME: in Peertube <= 3.1.0, PeertubeHelpers dont provide this function
function getBaseRouter (): string {
2021-04-12 18:52:21 +00:00
return '/plugins/' + pluginShortName + '/router/'
2021-04-09 19:28:16 +00:00
}
// FIXME: in Peertube <= 3.1.0, PeertubeHelpers dont provide this function
function getBaseStaticRoute (): string {
2021-04-12 18:52:21 +00:00
return '/plugins/' + pluginShortName + '/' + version + '/static/'
2021-04-09 19:28:16 +00:00
}
2021-04-10 11:57:47 +00:00
// FIXME: Peertube <= 3.1.0 has no way to test that current user is admin
// This is a hack.
function isUserAdmin (res: Response): boolean {
if (!res.locals?.authenticated) {
return false
}
if (res.locals?.oauth?.token?.User?.role === 0) {
return true
}
return false
}
2021-04-09 19:28:16 +00:00
export {
getBaseRouter,
2021-04-10 11:57:47 +00:00
getBaseStaticRoute,
2021-04-12 18:52:21 +00:00
isUserAdmin,
pluginName,
pluginShortName
2021-04-09 19:28:16 +00:00
}