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'
|
2020-04-09 11:35:29 +02:00
|
|
|
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()
|
2020-04-09 11:35:29 +02:00
|
|
|
const videos = buildVideosHelpers()
|
2020-04-09 09:57:32 +02:00
|
|
|
|
|
|
|
return {
|
2020-04-09 11:00:30 +02:00
|
|
|
logger,
|
2020-04-09 11:35:29 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2020-04-09 11:35:29 +02:00
|
|
|
|
|
|
|
function buildVideosHelpers () {
|
|
|
|
return {
|
|
|
|
removeVideo: (id: number) => {
|
|
|
|
return sequelizeTypescript.transaction(async t => {
|
|
|
|
const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id, t)
|
|
|
|
|
|
|
|
await video.destroy({ transaction: t })
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|