1
0
Fork 0
peertube/server/lib/plugins/plugin-helpers.ts

58 lines
1.3 KiB
TypeScript
Raw Normal View History

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