1
0
Fork 0
peertube/server/lib/plugins/plugin-helpers.ts
2020-05-04 16:21:39 +02:00

57 lines
1.3 KiB
TypeScript

import { PeerTubeHelpers } from '@server/typings/plugins'
import { sequelizeTypescript } from '@server/initializers/database'
import { buildLogger } from '@server/helpers/logger'
import { VideoModel } from '@server/models/video/video'
import { WEBSERVER } from '@server/initializers/constants'
function buildPluginHelpers (npmName: string): PeerTubeHelpers {
const logger = buildPluginLogger(npmName)
const database = buildDatabaseHelpers()
const videos = buildVideosHelpers()
const config = buildConfigHelpers()
return {
logger,
database,
videos,
config
}
}
export {
buildPluginHelpers
}
// ---------------------------------------------------------------------------
function buildPluginLogger (npmName: string) {
return buildLogger(npmName)
}
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 })
})
}
}
}
function buildConfigHelpers () {
return {
getWebserverUrl () {
return WEBSERVER.URL
}
}
}