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

46 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-04-09 09:57:32 +02:00
import { PeerTubeHelpers } from '@server/typings/plugins'
2020-04-09 11:00:30 +02:00
import { sequelizeTypescript } from '@server/initializers/database'
import { buildLogger } from '@server/helpers/logger'
import { VideoModel } from '@server/models/video/video'
2020-04-09 09:57:32 +02:00
2020-04-09 11:00:30 +02:00
function buildPluginHelpers (npmName: string): PeerTubeHelpers {
const logger = buildPluginLogger(npmName)
const database = buildDatabaseHelpers()
const videos = buildVideosHelpers()
2020-04-09 09:57:32 +02:00
return {
2020-04-09 11:00:30 +02:00
logger,
database,
videos
2020-04-09 09:57:32 +02:00
}
}
export {
buildPluginHelpers
}
// ---------------------------------------------------------------------------
2020-04-09 11:00:30 +02:00
function buildPluginLogger (npmName: string) {
2020-04-09 09:57:32 +02:00
return buildLogger(npmName)
}
2020-04-09 11:00:30 +02: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 })
})
}
}
}