1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 18:29:27 +02:00

Add ability to remove a video from a plugin

This commit is contained in:
Chocobozzz 2020-04-09 11:35:29 +02:00
parent 1b05d82d86
commit ab3ead3a6f
No known key found for this signature in database
GPG key ID: 583A612D890159BE
5 changed files with 68 additions and 9 deletions

View file

@ -1,15 +1,18 @@
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'
function buildPluginHelpers (npmName: string): PeerTubeHelpers {
const logger = buildPluginLogger(npmName)
const database = buildDatabaseHelpers()
const videos = buildVideosHelpers()
return {
logger,
database
database,
videos
}
}
@ -28,3 +31,15 @@ function buildDatabaseHelpers () {
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 })
})
}
}
}