X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fvideos.ts;h=907f7e11e273e55a559af20f7f9762de0498846f;hb=28be89161aab245526d64f6fb7dd29391a97fe0a;hp=2899acff3a7448fa96b0aa2433f3809aee0cc865;hpb=0f320037e689b2778959c12ddd4ce790f6e4ae4f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index 2899acff3..907f7e11e 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts @@ -20,6 +20,7 @@ import { VideoFileModel } from '../../models/video/video-file' import { VideoShareModel } from '../../models/video/video-share' import { getOrCreateActorAndServerAndModel } from './actor' import { addVideoComments } from './video-comments' +import { crawlCollectionPage } from './crawl' function fetchRemoteVideoPreview (video: VideoModel, reject: Function) { const host = video.VideoChannel.Account.Actor.Server.host @@ -92,6 +93,7 @@ async function videoActivityObjectToDBAttributes (videoChannel: VideoChannelMode channelId: videoChannel.id, duration: parseInt(duration, 10), createdAt: new Date(videoObject.published), + publishedAt: new Date(videoObject.published), // FIXME: updatedAt does not seems to be considered by Sequelize updatedAt: new Date(videoObject.updated), views: videoObject.views, @@ -216,25 +218,17 @@ async function getOrCreateAccountAndVideoAndChannel (videoObject: VideoTorrentOb const video = await retryTransactionWrapper(getOrCreateVideo, options) // Process outside the transaction because we could fetch remote data - if (videoObject.likes && Array.isArray(videoObject.likes.orderedItems)) { - logger.info('Adding likes of video %s.', video.uuid) - await createRates(videoObject.likes.orderedItems, video, 'like') - } + logger.info('Adding likes of video %s.', video.uuid) + await crawlCollectionPage(videoObject.likes, (items) => createRates(items, video, 'like')) - if (videoObject.dislikes && Array.isArray(videoObject.dislikes.orderedItems)) { - logger.info('Adding dislikes of video %s.', video.uuid) - await createRates(videoObject.dislikes.orderedItems, video, 'dislike') - } + logger.info('Adding dislikes of video %s.', video.uuid) + await crawlCollectionPage(videoObject.dislikes, (items) => createRates(items, video, 'dislike')) - if (videoObject.shares && Array.isArray(videoObject.shares.orderedItems)) { - logger.info('Adding shares of video %s.', video.uuid) - await addVideoShares(video, videoObject.shares.orderedItems) - } + logger.info('Adding shares of video %s.', video.uuid) + await crawlCollectionPage(videoObject.shares, (items) => addVideoShares(items, video)) - if (videoObject.comments && Array.isArray(videoObject.comments.orderedItems)) { - logger.info('Adding comments of video %s.', video.uuid) - await addVideoComments(video, videoObject.comments.orderedItems) - } + logger.info('Adding comments of video %s.', video.uuid) + await crawlCollectionPage(videoObject.comments, (items) => addVideoComments(items, video)) return { actor, channelActor, video } } @@ -266,7 +260,7 @@ async function createRates (actorUrls: string[], video: VideoModel, rate: VideoR return } -async function addVideoShares (instance: VideoModel, shareUrls: string[]) { +async function addVideoShares (shareUrls: string[], instance: VideoModel) { for (const shareUrl of shareUrls) { // Fetch url const { body } = await doRequest({ @@ -306,7 +300,8 @@ export { videoFileActivityUrlToDBAttributes, getOrCreateVideo, getOrCreateVideoChannel, - addVideoShares} + addVideoShares +} // ---------------------------------------------------------------------------