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

Add upload/import/go live video attributes hooks

This commit is contained in:
Chocobozzz 2021-12-10 13:49:19 +01:00
parent 8cf43a6524
commit d17d743051
No known key found for this signature in database
GPG key ID: 583A612D890159BE
6 changed files with 98 additions and 6 deletions

View file

@ -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<MVideoThumbnail> {
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)

View file

@ -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

View file

@ -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