From d17d743051c5716e1e08cd8870d718cfd6a57f0c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 10 Dec 2021 13:49:19 +0100 Subject: Add upload/import/go live video attributes hooks --- server/controllers/api/videos/import.ts | 17 +++++++++++++---- server/controllers/api/videos/live.ts | 4 +++- server/controllers/api/videos/upload.ts | 3 ++- 3 files changed, 18 insertions(+), 6 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index eddb9b32d..52864bdfd 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts @@ -38,6 +38,7 @@ import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoIm import { VideoModel } from '../../../models/video/video' import { VideoCaptionModel } from '../../../models/video/video-caption' import { VideoImportModel } from '../../../models/video/video-import' +import { Hooks } from '@server/lib/plugins/hooks' const auditLogger = auditLoggerFactory('video-imports') const videoImportsRouter = express.Router() @@ -94,7 +95,7 @@ async function addTorrentImport (req: express.Request, res: express.Response, to videoName = result.name } - const video = buildVideo(res.locals.videoChannel.id, body, { name: videoName }) + const video = await buildVideo(res.locals.videoChannel.id, body, { name: videoName }) const thumbnailModel = await processThumbnail(req, video) const previewModel = await processPreview(req, video) @@ -151,7 +152,7 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response) }) } - const video = buildVideo(res.locals.videoChannel.id, body, youtubeDLInfo) + const video = await buildVideo(res.locals.videoChannel.id, body, youtubeDLInfo) // Process video thumbnail from request.files let thumbnailModel = await processThumbnail(req, video) @@ -210,8 +211,8 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response) return res.json(videoImport.toFormattedJSON()).end() } -function buildVideo (channelId: number, body: VideoImportCreate, importData: YoutubeDLInfo): MVideoThumbnail { - const videoData = { +async function buildVideo (channelId: number, body: VideoImportCreate, importData: YoutubeDLInfo): Promise { + let videoData = { name: body.name || importData.name || 'Unknown name', remote: false, category: body.category || importData.category, @@ -231,6 +232,14 @@ function buildVideo (channelId: number, body: VideoImportCreate, importData: You ? new Date(body.originallyPublishedAt) : importData.originallyPublishedAt } + + videoData = await Hooks.wrapObject( + videoData, + body.targetUrl + ? 'filter:api.video.import-url.video-attribute.result' + : 'filter:api.video.import-torrent.video-attribute.result' + ) + const video = new VideoModel(videoData) video.url = getLocalVideoActivityPubUrl(video) diff --git a/server/controllers/api/videos/live.ts b/server/controllers/api/videos/live.ts index e29615ff5..3e1480cf2 100644 --- a/server/controllers/api/videos/live.ts +++ b/server/controllers/api/videos/live.ts @@ -83,7 +83,9 @@ async function addLiveVideo (req: express.Request, res: express.Response) { const videoInfo: LiveVideoCreate = req.body // Prepare data so we don't block the transaction - const videoData = buildLocalVideoFromReq(videoInfo, res.locals.videoChannel.id) + let videoData = buildLocalVideoFromReq(videoInfo, res.locals.videoChannel.id) + videoData = await Hooks.wrapObject(videoData, 'filter:api.video.live.video-attribute.result') + videoData.isLive = true videoData.state = VideoState.WAITING_FOR_LIVE videoData.duration = 0 diff --git a/server/controllers/api/videos/upload.ts b/server/controllers/api/videos/upload.ts index c827f6bf0..1be87f746 100644 --- a/server/controllers/api/videos/upload.ts +++ b/server/controllers/api/videos/upload.ts @@ -153,7 +153,8 @@ async function addVideo (options: { const videoChannel = res.locals.videoChannel const user = res.locals.oauth.token.User - const videoData = buildLocalVideoFromReq(videoInfo, videoChannel.id) + let videoData = buildLocalVideoFromReq(videoInfo, videoChannel.id) + videoData = await Hooks.wrapObject(videoData, 'filter:api.video.upload.video-attribute.result') videoData.state = buildNextVideoState() videoData.duration = videoPhysicalFile.duration // duration was added by a previous middleware -- cgit v1.2.3