PeerTube/server/lib/plugins/plugin-helpers.ts

58 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-04-09 02:57:32 -05:00
import { PeerTubeHelpers } from '@server/typings/plugins'
2020-04-09 04:00:30 -05:00
import { sequelizeTypescript } from '@server/initializers/database'
import { buildLogger } from '@server/helpers/logger'
import { VideoModel } from '@server/models/video/video'
2020-04-30 01:46:40 -05:00
import { WEBSERVER } from '@server/initializers/constants'
2020-04-09 02:57:32 -05:00
2020-04-09 04:00:30 -05:00
function buildPluginHelpers (npmName: string): PeerTubeHelpers {
const logger = buildPluginLogger(npmName)
const database = buildDatabaseHelpers()
const videos = buildVideosHelpers()
2020-04-09 02:57:32 -05:00
2020-04-30 01:46:40 -05:00
const config = buildConfigHelpers()
2020-04-09 02:57:32 -05:00
return {
2020-04-09 04:00:30 -05:00
logger,
database,
2020-04-30 01:46:40 -05:00
videos,
config
2020-04-09 02:57:32 -05:00
}
}
export {
buildPluginHelpers
}
// ---------------------------------------------------------------------------
2020-04-09 04:00:30 -05:00
function buildPluginLogger (npmName: string) {
2020-04-09 02:57:32 -05:00
return buildLogger(npmName)
}
2020-04-09 04:00:30 -05:00
function buildDatabaseHelpers () {
return {
query: sequelizeTypescript.query.bind(sequelizeTypescript)
}
}
function buildVideosHelpers () {
return {
removeVideo: (id: number) => {
return sequelizeTypescript.transaction(async t => {
const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id, t)
await video.destroy({ transaction: t })
})
}
}
}
2020-04-30 01:46:40 -05:00
function buildConfigHelpers () {
return {
getWebserverUrl () {
return WEBSERVER.URL
}
}
}