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'
|
2020-04-09 04:35:29 -05:00
|
|
|
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()
|
2020-04-09 04:35:29 -05:00
|
|
|
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,
|
2020-04-09 04:35:29 -05:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2020-04-09 04:35:29 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|