aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-12-10 13:49:19 +0100
committerChocobozzz <me@florianbigard.com>2021-12-10 13:51:44 +0100
commitd17d743051c5716e1e08cd8870d718cfd6a57f0c (patch)
tree2f8c8d1a08467f35c5ede18001fc18cb2bafafef /server/controllers
parent8cf43a6524d354fbfa0f0eaf789e8d4756bd25d6 (diff)
downloadPeerTube-d17d743051c5716e1e08cd8870d718cfd6a57f0c.tar.gz
PeerTube-d17d743051c5716e1e08cd8870d718cfd6a57f0c.tar.zst
PeerTube-d17d743051c5716e1e08cd8870d718cfd6a57f0c.zip
Add upload/import/go live video attributes hooks
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/videos/import.ts17
-rw-r--r--server/controllers/api/videos/live.ts4
-rw-r--r--server/controllers/api/videos/upload.ts3
3 files changed, 18 insertions, 6 deletions
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
38import { VideoModel } from '../../../models/video/video' 38import { VideoModel } from '../../../models/video/video'
39import { VideoCaptionModel } from '../../../models/video/video-caption' 39import { VideoCaptionModel } from '../../../models/video/video-caption'
40import { VideoImportModel } from '../../../models/video/video-import' 40import { VideoImportModel } from '../../../models/video/video-import'
41import { Hooks } from '@server/lib/plugins/hooks'
41 42
42const auditLogger = auditLoggerFactory('video-imports') 43const auditLogger = auditLoggerFactory('video-imports')
43const videoImportsRouter = express.Router() 44const videoImportsRouter = express.Router()
@@ -94,7 +95,7 @@ async function addTorrentImport (req: express.Request, res: express.Response, to
94 videoName = result.name 95 videoName = result.name
95 } 96 }
96 97
97 const video = buildVideo(res.locals.videoChannel.id, body, { name: videoName }) 98 const video = await buildVideo(res.locals.videoChannel.id, body, { name: videoName })
98 99
99 const thumbnailModel = await processThumbnail(req, video) 100 const thumbnailModel = await processThumbnail(req, video)
100 const previewModel = await processPreview(req, video) 101 const previewModel = await processPreview(req, video)
@@ -151,7 +152,7 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response)
151 }) 152 })
152 } 153 }
153 154
154 const video = buildVideo(res.locals.videoChannel.id, body, youtubeDLInfo) 155 const video = await buildVideo(res.locals.videoChannel.id, body, youtubeDLInfo)
155 156
156 // Process video thumbnail from request.files 157 // Process video thumbnail from request.files
157 let thumbnailModel = await processThumbnail(req, video) 158 let thumbnailModel = await processThumbnail(req, video)
@@ -210,8 +211,8 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response)
210 return res.json(videoImport.toFormattedJSON()).end() 211 return res.json(videoImport.toFormattedJSON()).end()
211} 212}
212 213
213function buildVideo (channelId: number, body: VideoImportCreate, importData: YoutubeDLInfo): MVideoThumbnail { 214async function buildVideo (channelId: number, body: VideoImportCreate, importData: YoutubeDLInfo): Promise<MVideoThumbnail> {
214 const videoData = { 215 let videoData = {
215 name: body.name || importData.name || 'Unknown name', 216 name: body.name || importData.name || 'Unknown name',
216 remote: false, 217 remote: false,
217 category: body.category || importData.category, 218 category: body.category || importData.category,
@@ -231,6 +232,14 @@ function buildVideo (channelId: number, body: VideoImportCreate, importData: You
231 ? new Date(body.originallyPublishedAt) 232 ? new Date(body.originallyPublishedAt)
232 : importData.originallyPublishedAt 233 : importData.originallyPublishedAt
233 } 234 }
235
236 videoData = await Hooks.wrapObject(
237 videoData,
238 body.targetUrl
239 ? 'filter:api.video.import-url.video-attribute.result'
240 : 'filter:api.video.import-torrent.video-attribute.result'
241 )
242
234 const video = new VideoModel(videoData) 243 const video = new VideoModel(videoData)
235 video.url = getLocalVideoActivityPubUrl(video) 244 video.url = getLocalVideoActivityPubUrl(video)
236 245
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) {
83 const videoInfo: LiveVideoCreate = req.body 83 const videoInfo: LiveVideoCreate = req.body
84 84
85 // Prepare data so we don't block the transaction 85 // Prepare data so we don't block the transaction
86 const videoData = buildLocalVideoFromReq(videoInfo, res.locals.videoChannel.id) 86 let videoData = buildLocalVideoFromReq(videoInfo, res.locals.videoChannel.id)
87 videoData = await Hooks.wrapObject(videoData, 'filter:api.video.live.video-attribute.result')
88
87 videoData.isLive = true 89 videoData.isLive = true
88 videoData.state = VideoState.WAITING_FOR_LIVE 90 videoData.state = VideoState.WAITING_FOR_LIVE
89 videoData.duration = 0 91 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: {
153 const videoChannel = res.locals.videoChannel 153 const videoChannel = res.locals.videoChannel
154 const user = res.locals.oauth.token.User 154 const user = res.locals.oauth.token.User
155 155
156 const videoData = buildLocalVideoFromReq(videoInfo, videoChannel.id) 156 let videoData = buildLocalVideoFromReq(videoInfo, videoChannel.id)
157 videoData = await Hooks.wrapObject(videoData, 'filter:api.video.upload.video-attribute.result')
157 158
158 videoData.state = buildNextVideoState() 159 videoData.state = buildNextVideoState()
159 videoData.duration = videoPhysicalFile.duration // duration was added by a previous middleware 160 videoData.duration = videoPhysicalFile.duration // duration was added by a previous middleware