From ab3ead3a6f080e6768b898e699c8de92703d93c6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 9 Apr 2020 11:35:29 +0200 Subject: Add ability to remove a video from a plugin --- server/lib/plugins/hooks.ts | 2 +- server/lib/plugins/plugin-helpers.ts | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'server/lib/plugins') diff --git a/server/lib/plugins/hooks.ts b/server/lib/plugins/hooks.ts index bcc8c674e..aa92f03cc 100644 --- a/server/lib/plugins/hooks.ts +++ b/server/lib/plugins/hooks.ts @@ -25,7 +25,7 @@ const Hooks = { }, runAction: (hookName: U, params?: T) => { - PluginManager.Instance.runHook(hookName, params) + PluginManager.Instance.runHook(hookName, undefined, params) .catch(err => logger.error('Fatal hook error.', { err })) } } diff --git a/server/lib/plugins/plugin-helpers.ts b/server/lib/plugins/plugin-helpers.ts index a1493c7df..e91beffba 100644 --- a/server/lib/plugins/plugin-helpers.ts +++ b/server/lib/plugins/plugin-helpers.ts @@ -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 }) + }) + } + } +} -- cgit v1.2.3