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.ts34
1 files changed, 12 insertions, 22 deletions
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts
index 5a56942a9..63bb07ec1 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -49,10 +49,11 @@ import { AccountVideoRateModel } from '../../models/account/account-video-rate'
49import { VideoShareModel } from '../../models/video/video-share' 49import { VideoShareModel } from '../../models/video/video-share'
50import { VideoCommentModel } from '../../models/video/video-comment' 50import { VideoCommentModel } from '../../models/video/video-comment'
51import { sequelizeTypescript } from '../../initializers/database' 51import { sequelizeTypescript } from '../../initializers/database'
52import { createPlaceholderThumbnail, createVideoThumbnailFromUrl } from '../thumbnail' 52import { createPlaceholderThumbnail, createVideoMiniatureFromUrl } from '../thumbnail'
53import { ThumbnailModel } from '../../models/video/thumbnail' 53import { ThumbnailModel } from '../../models/video/thumbnail'
54import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' 54import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type'
55import { join } from 'path' 55import { join } from 'path'
56import { FilteredModelAttributes } from '../../typings/sequelize'
56 57
57async function federateVideoIfNeeded (video: VideoModel, isNewVideo: boolean, transaction?: sequelize.Transaction) { 58async function federateVideoIfNeeded (video: VideoModel, isNewVideo: boolean, transaction?: sequelize.Transaction) {
58 // If the video is not private and is published, we federate it 59 // If the video is not private and is published, we federate it
@@ -247,7 +248,7 @@ async function updateVideoFromAP (options: {
247 let thumbnailModel: ThumbnailModel 248 let thumbnailModel: ThumbnailModel
248 249
249 try { 250 try {
250 thumbnailModel = await createVideoThumbnailFromUrl(options.videoObject.icon.url, options.video, ThumbnailType.THUMBNAIL) 251 thumbnailModel = await createVideoMiniatureFromUrl(options.videoObject.icon.url, options.video, ThumbnailType.MINIATURE)
251 } catch (err) { 252 } catch (err) {
252 logger.warn('Cannot generate thumbnail of %s.', options.videoObject.id, { err }) 253 logger.warn('Cannot generate thumbnail of %s.', options.videoObject.id, { err })
253 } 254 }
@@ -288,16 +289,12 @@ async function updateVideoFromAP (options: {
288 289
289 await options.video.save(sequelizeOptions) 290 await options.video.save(sequelizeOptions)
290 291
291 if (thumbnailModel) { 292 if (thumbnailModel) if (thumbnailModel) await options.video.addAndSaveThumbnail(thumbnailModel, t)
292 thumbnailModel.videoId = options.video.id
293 options.video.addThumbnail(await thumbnailModel.save({ transaction: t }))
294 }
295 293
296 // FIXME: use icon URL instead 294 // FIXME: use icon URL instead
297 const previewUrl = buildRemoteBaseUrl(options.video, join(STATIC_PATHS.PREVIEWS, options.video.getPreview().filename)) 295 const previewUrl = buildRemoteBaseUrl(options.video, join(STATIC_PATHS.PREVIEWS, options.video.getPreview().filename))
298 const previewModel = createPlaceholderThumbnail(previewUrl, options.video, ThumbnailType.PREVIEW, PREVIEWS_SIZE) 296 const previewModel = createPlaceholderThumbnail(previewUrl, options.video, ThumbnailType.PREVIEW, PREVIEWS_SIZE)
299 297 await options.video.addAndSaveThumbnail(previewModel, t)
300 options.video.addThumbnail(await previewModel.save({ transaction: t }))
301 298
302 { 299 {
303 const videoFileAttributes = videoFileActivityUrlToDBAttributes(options.video, options.videoObject) 300 const videoFileAttributes = videoFileActivityUrlToDBAttributes(options.video, options.videoObject)
@@ -311,7 +308,7 @@ async function updateVideoFromAP (options: {
311 308
312 // Update or add other one 309 // Update or add other one
313 const upsertTasks = videoFileAttributes.map(a => { 310 const upsertTasks = videoFileAttributes.map(a => {
314 return (VideoFileModel.upsert<VideoFileModel>(a, { returning: true, transaction: t }) as any) // FIXME: sequelize typings 311 return VideoFileModel.upsert<VideoFileModel>(a, { returning: true, transaction: t })
315 .then(([ file ]) => file) 312 .then(([ file ]) => file)
316 }) 313 })
317 314
@@ -334,8 +331,7 @@ async function updateVideoFromAP (options: {
334 331
335 // Update or add other one 332 // Update or add other one
336 const upsertTasks = streamingPlaylistAttributes.map(a => { 333 const upsertTasks = streamingPlaylistAttributes.map(a => {
337 // FIXME: sequelize typings 334 return VideoStreamingPlaylistModel.upsert<VideoStreamingPlaylistModel>(a, { returning: true, transaction: t })
338 return (VideoStreamingPlaylistModel.upsert<VideoStreamingPlaylistModel>(a, { returning: true, transaction: t }) as any)
339 .then(([ streamingPlaylist ]) => streamingPlaylist) 335 .then(([ streamingPlaylist ]) => streamingPlaylist)
340 }) 336 })
341 337
@@ -464,7 +460,7 @@ async function createVideo (videoObject: VideoTorrentObject, channelActor: Actor
464 const videoData = await videoActivityObjectToDBAttributes(channelActor.VideoChannel, videoObject, videoObject.to) 460 const videoData = await videoActivityObjectToDBAttributes(channelActor.VideoChannel, videoObject, videoObject.to)
465 const video = VideoModel.build(videoData) 461 const video = VideoModel.build(videoData)
466 462
467 const promiseThumbnail = createVideoThumbnailFromUrl(videoObject.icon.url, video, ThumbnailType.THUMBNAIL) 463 const promiseThumbnail = createVideoMiniatureFromUrl(videoObject.icon.url, video, ThumbnailType.MINIATURE)
468 464
469 let thumbnailModel: ThumbnailModel 465 let thumbnailModel: ThumbnailModel
470 if (waitThumbnail === true) { 466 if (waitThumbnail === true) {
@@ -477,18 +473,12 @@ async function createVideo (videoObject: VideoTorrentObject, channelActor: Actor
477 const videoCreated = await video.save(sequelizeOptions) 473 const videoCreated = await video.save(sequelizeOptions)
478 videoCreated.VideoChannel = channelActor.VideoChannel 474 videoCreated.VideoChannel = channelActor.VideoChannel
479 475
480 if (thumbnailModel) { 476 if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
481 thumbnailModel.videoId = videoCreated.id
482
483 videoCreated.addThumbnail(await thumbnailModel.save({ transaction: t }))
484 }
485 477
486 // FIXME: use icon URL instead 478 // FIXME: use icon URL instead
487 const previewUrl = buildRemoteBaseUrl(videoCreated, join(STATIC_PATHS.PREVIEWS, video.generatePreviewName())) 479 const previewUrl = buildRemoteBaseUrl(videoCreated, join(STATIC_PATHS.PREVIEWS, video.generatePreviewName()))
488 const previewModel = createPlaceholderThumbnail(previewUrl, video, ThumbnailType.PREVIEW, PREVIEWS_SIZE) 480 const previewModel = createPlaceholderThumbnail(previewUrl, video, ThumbnailType.PREVIEW, PREVIEWS_SIZE)
489 previewModel.videoId = videoCreated.id 481 if (thumbnailModel) await videoCreated.addAndSaveThumbnail(previewModel, t)
490
491 videoCreated.addThumbnail(await previewModel.save({ transaction: t }))
492 482
493 // Process files 483 // Process files
494 const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoCreated, videoObject) 484 const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoCreated, videoObject)
@@ -594,7 +584,7 @@ function videoFileActivityUrlToDBAttributes (video: VideoModel, videoObject: Vid
594 throw new Error('Cannot find video files for ' + video.url) 584 throw new Error('Cannot find video files for ' + video.url)
595 } 585 }
596 586
597 const attributes: object[] = [] // FIXME: add typings 587 const attributes: FilteredModelAttributes<VideoFileModel>[] = []
598 for (const fileUrl of fileUrls) { 588 for (const fileUrl of fileUrls) {
599 // Fetch associated magnet uri 589 // Fetch associated magnet uri
600 const magnet = videoObject.url.find(u => { 590 const magnet = videoObject.url.find(u => {
@@ -629,7 +619,7 @@ function streamingPlaylistActivityUrlToDBAttributes (video: VideoModel, videoObj
629 const playlistUrls = videoObject.url.filter(u => isAPStreamingPlaylistUrlObject(u)) as ActivityPlaylistUrlObject[] 619 const playlistUrls = videoObject.url.filter(u => isAPStreamingPlaylistUrlObject(u)) as ActivityPlaylistUrlObject[]
630 if (playlistUrls.length === 0) return [] 620 if (playlistUrls.length === 0) return []
631 621
632 const attributes: object[] = [] // FIXME: add typings 622 const attributes: FilteredModelAttributes<VideoStreamingPlaylistModel>[] = []
633 for (const playlistUrlObject of playlistUrls) { 623 for (const playlistUrlObject of playlistUrls) {
634 const segmentsSha256UrlObject = playlistUrlObject.tag 624 const segmentsSha256UrlObject = playlistUrlObject.tag
635 .find(t => { 625 .find(t => {