aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/videos.ts')
-rw-r--r--server/lib/activitypub/videos.ts50
1 files changed, 28 insertions, 22 deletions
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts
index 6bc2258cc..9e43caa20 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -197,25 +197,25 @@ async function syncVideoExternalAttributes (video: MVideo, fetchedVideo: VideoTo
197 jobPayloads.push({ uri: fetchedVideo.comments, videoId: video.id, type: 'video-comments' as 'video-comments' }) 197 jobPayloads.push({ uri: fetchedVideo.comments, videoId: video.id, type: 'video-comments' as 'video-comments' })
198 } 198 }
199 199
200 await Bluebird.map(jobPayloads, payload => JobQueue.Instance.createJob({ type: 'activitypub-http-fetcher', payload })) 200 await Bluebird.map(jobPayloads, payload => JobQueue.Instance.createJobWithPromise({ type: 'activitypub-http-fetcher', payload }))
201} 201}
202 202
203function getOrCreateVideoAndAccountAndChannel (options: { 203function getOrCreateVideoAndAccountAndChannel (options: {
204 videoObject: { id: string } | string, 204 videoObject: { id: string } | string
205 syncParam?: SyncParam, 205 syncParam?: SyncParam
206 fetchType?: 'all', 206 fetchType?: 'all'
207 allowRefresh?: boolean 207 allowRefresh?: boolean
208}): Promise<{ video: MVideoAccountLightBlacklistAllFiles, created: boolean, autoBlacklisted?: boolean }> 208}): Promise<{ video: MVideoAccountLightBlacklistAllFiles, created: boolean, autoBlacklisted?: boolean }>
209function getOrCreateVideoAndAccountAndChannel (options: { 209function getOrCreateVideoAndAccountAndChannel (options: {
210 videoObject: { id: string } | string, 210 videoObject: { id: string } | string
211 syncParam?: SyncParam, 211 syncParam?: SyncParam
212 fetchType?: VideoFetchByUrlType, 212 fetchType?: VideoFetchByUrlType
213 allowRefresh?: boolean 213 allowRefresh?: boolean
214}): Promise<{ video: MVideoAccountLightBlacklistAllFiles | MVideoThumbnail, created: boolean, autoBlacklisted?: boolean }> 214}): Promise<{ video: MVideoAccountLightBlacklistAllFiles | MVideoThumbnail, created: boolean, autoBlacklisted?: boolean }>
215async function getOrCreateVideoAndAccountAndChannel (options: { 215async function getOrCreateVideoAndAccountAndChannel (options: {
216 videoObject: { id: string } | string, 216 videoObject: { id: string } | string
217 syncParam?: SyncParam, 217 syncParam?: SyncParam
218 fetchType?: VideoFetchByUrlType, 218 fetchType?: VideoFetchByUrlType
219 allowRefresh?: boolean // true by default 219 allowRefresh?: boolean // true by default
220}): Promise<{ video: MVideoAccountLightBlacklistAllFiles | MVideoThumbnail, created: boolean, autoBlacklisted?: boolean }> { 220}): Promise<{ video: MVideoAccountLightBlacklistAllFiles | MVideoThumbnail, created: boolean, autoBlacklisted?: boolean }> {
221 // Default params 221 // Default params
@@ -235,8 +235,14 @@ async function getOrCreateVideoAndAccountAndChannel (options: {
235 syncParam 235 syncParam
236 } 236 }
237 237
238 if (syncParam.refreshVideo === true) videoFromDatabase = await refreshVideoIfNeeded(refreshOptions) 238 if (syncParam.refreshVideo === true) {
239 else await JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: videoFromDatabase.url } }) 239 videoFromDatabase = await refreshVideoIfNeeded(refreshOptions)
240 } else {
241 await JobQueue.Instance.createJobWithPromise({
242 type: 'activitypub-refresher',
243 payload: { type: 'video', url: videoFromDatabase.url }
244 })
245 }
240 } 246 }
241 247
242 return { video: videoFromDatabase, created: false } 248 return { video: videoFromDatabase, created: false }
@@ -255,10 +261,10 @@ async function getOrCreateVideoAndAccountAndChannel (options: {
255} 261}
256 262
257async function updateVideoFromAP (options: { 263async function updateVideoFromAP (options: {
258 video: MVideoAccountLightBlacklistAllFiles, 264 video: MVideoAccountLightBlacklistAllFiles
259 videoObject: VideoTorrentObject, 265 videoObject: VideoTorrentObject
260 account: MAccountIdActor, 266 account: MAccountIdActor
261 channel: MChannelDefault, 267 channel: MChannelDefault
262 overrideTo?: string[] 268 overrideTo?: string[]
263}) { 269}) {
264 const { video, videoObject, account, channel, overrideTo } = options 270 const { video, videoObject, account, channel, overrideTo } = options
@@ -289,7 +295,7 @@ async function updateVideoFromAP (options: {
289 throw new Error('Account ' + account.Actor.url + ' does not own video channel ' + videoChannel.Actor.url) 295 throw new Error('Account ' + account.Actor.url + ' does not own video channel ' + videoChannel.Actor.url)
290 } 296 }
291 297
292 const to = overrideTo ? overrideTo : videoObject.to 298 const to = overrideTo || videoObject.to
293 const videoData = await videoActivityObjectToDBAttributes(channel, videoObject, to) 299 const videoData = await videoActivityObjectToDBAttributes(channel, videoObject, to)
294 video.name = videoData.name 300 video.name = videoData.name
295 video.uuid = videoData.uuid 301 video.uuid = videoData.uuid
@@ -412,8 +418,8 @@ async function updateVideoFromAP (options: {
412} 418}
413 419
414async function refreshVideoIfNeeded (options: { 420async function refreshVideoIfNeeded (options: {
415 video: MVideoThumbnail, 421 video: MVideoThumbnail
416 fetchedType: VideoFetchByUrlType, 422 fetchedType: VideoFetchByUrlType
417 syncParam: SyncParam 423 syncParam: SyncParam
418}): Promise<MVideoThumbnail> { 424}): Promise<MVideoThumbnail> {
419 if (!options.video.isOutdated()) return options.video 425 if (!options.video.isOutdated()) return options.video
@@ -582,13 +588,13 @@ async function createVideo (videoObject: VideoTorrentObject, channel: MChannelAc
582 thumbnailModel = videoCreated.id 588 thumbnailModel = videoCreated.id
583 589
584 return thumbnailModel.save() 590 return thumbnailModel.save()
585 }) 591 }).catch(err => logger.error('Cannot create miniature from url.', { err }))
586 } 592 }
587 593
588 return { autoBlacklisted, videoCreated } 594 return { autoBlacklisted, videoCreated }
589} 595}
590 596
591async function videoActivityObjectToDBAttributes (videoChannel: MChannelId, videoObject: VideoTorrentObject, to: string[] = []) { 597function videoActivityObjectToDBAttributes (videoChannel: MChannelId, videoObject: VideoTorrentObject, to: string[] = []) {
592 const privacy = to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ? VideoPrivacy.PUBLIC : VideoPrivacy.UNLISTED 598 const privacy = to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ? VideoPrivacy.PUBLIC : VideoPrivacy.UNLISTED
593 const duration = videoObject.duration.replace(/[^\d]+/, '') 599 const duration = videoObject.duration.replace(/[^\d]+/, '')
594 600
@@ -661,7 +667,7 @@ function videoFileActivityUrlToDBAttributes (
661 667
662 const mediaType = fileUrl.mediaType 668 const mediaType = fileUrl.mediaType
663 const attribute = { 669 const attribute = {
664 extname: MIMETYPES.VIDEO.MIMETYPE_EXT[ mediaType ], 670 extname: MIMETYPES.VIDEO.MIMETYPE_EXT[mediaType],
665 infoHash: parsed.infoHash, 671 infoHash: parsed.infoHash,
666 resolution: fileUrl.height, 672 resolution: fileUrl.height,
667 size: fileUrl.size, 673 size: fileUrl.size,