aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r--server/lib/activitypub/playlist.ts14
-rw-r--r--server/lib/activitypub/video-comments.ts3
-rw-r--r--server/lib/activitypub/videos.ts34
3 files changed, 19 insertions, 32 deletions
diff --git a/server/lib/activitypub/playlist.ts b/server/lib/activitypub/playlist.ts
index 721c19603..36a91faec 100644
--- a/server/lib/activitypub/playlist.ts
+++ b/server/lib/activitypub/playlist.ts
@@ -16,7 +16,8 @@ import { VideoPlaylistElementModel } from '../../models/video/video-playlist-ele
16import { VideoModel } from '../../models/video/video' 16import { VideoModel } from '../../models/video/video'
17import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' 17import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
18import { sequelizeTypescript } from '../../initializers/database' 18import { sequelizeTypescript } from '../../initializers/database'
19import { createPlaylistThumbnailFromUrl } from '../thumbnail' 19import { createPlaylistMiniatureFromUrl } from '../thumbnail'
20import { FilteredModelAttributes } from '../../typings/sequelize'
20 21
21function playlistObjectToDBAttributes (playlistObject: PlaylistObject, byAccount: AccountModel, to: string[]) { 22function playlistObjectToDBAttributes (playlistObject: PlaylistObject, byAccount: AccountModel, to: string[]) {
22 const privacy = to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ? VideoPlaylistPrivacy.PUBLIC : VideoPlaylistPrivacy.UNLISTED 23 const privacy = to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ? VideoPlaylistPrivacy.PUBLIC : VideoPlaylistPrivacy.UNLISTED
@@ -86,8 +87,7 @@ async function createOrUpdateVideoPlaylist (playlistObject: PlaylistObject, byAc
86 } 87 }
87 } 88 }
88 89
89 // FIXME: sequelize typings 90 const [ playlist ] = await VideoPlaylistModel.upsert<VideoPlaylistModel>(playlistAttributes, { returning: true })
90 const [ playlist ] = (await VideoPlaylistModel.upsert<VideoPlaylistModel>(playlistAttributes, { returning: true }) as any)
91 91
92 let accItems: string[] = [] 92 let accItems: string[] = []
93 await crawlCollectionPage<string>(playlistObject.id, items => { 93 await crawlCollectionPage<string>(playlistObject.id, items => {
@@ -100,10 +100,8 @@ async function createOrUpdateVideoPlaylist (playlistObject: PlaylistObject, byAc
100 100
101 if (playlistObject.icon) { 101 if (playlistObject.icon) {
102 try { 102 try {
103 const thumbnailModel = await createPlaylistThumbnailFromUrl(playlistObject.icon.url, refreshedPlaylist) 103 const thumbnailModel = await createPlaylistMiniatureFromUrl(playlistObject.icon.url, refreshedPlaylist)
104 thumbnailModel.videoPlaylistId = refreshedPlaylist.id 104 await refreshedPlaylist.setAndSaveThumbnail(thumbnailModel, undefined)
105
106 refreshedPlaylist.setThumbnail(await thumbnailModel.save())
107 } catch (err) { 105 } catch (err) {
108 logger.warn('Cannot generate thumbnail of %s.', playlistObject.id, { err }) 106 logger.warn('Cannot generate thumbnail of %s.', playlistObject.id, { err })
109 } 107 }
@@ -156,7 +154,7 @@ export {
156// --------------------------------------------------------------------------- 154// ---------------------------------------------------------------------------
157 155
158async function resetVideoPlaylistElements (elementUrls: string[], playlist: VideoPlaylistModel) { 156async function resetVideoPlaylistElements (elementUrls: string[], playlist: VideoPlaylistModel) {
159 const elementsToCreate: object[] = [] // FIXME: sequelize typings 157 const elementsToCreate: FilteredModelAttributes<VideoPlaylistElementModel>[] = []
160 158
161 await Bluebird.map(elementUrls, async elementUrl => { 159 await Bluebird.map(elementUrls, async elementUrl => {
162 try { 160 try {
diff --git a/server/lib/activitypub/video-comments.ts b/server/lib/activitypub/video-comments.ts
index cb67bf9a4..18f44d50e 100644
--- a/server/lib/activitypub/video-comments.ts
+++ b/server/lib/activitypub/video-comments.ts
@@ -73,8 +73,7 @@ async function addVideoComment (videoInstance: VideoModel, commentUrl: string) {
73 const entry = await videoCommentActivityObjectToDBAttributes(videoInstance, actor, body) 73 const entry = await videoCommentActivityObjectToDBAttributes(videoInstance, actor, body)
74 if (!entry) return { created: false } 74 if (!entry) return { created: false }
75 75
76 // FIXME: sequelize typings 76 const [ comment, created ] = await VideoCommentModel.upsert<VideoCommentModel>(entry, { returning: true })
77 const [ comment, created ] = (await VideoCommentModel.upsert<VideoCommentModel>(entry, { returning: true }) as any)
78 comment.Account = actor.Account 77 comment.Account = actor.Account
79 comment.Video = videoInstance 78 comment.Video = videoInstance
80 79
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 => {