aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/videos.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-03-19 16:23:02 +0100
committerChocobozzz <me@florianbigard.com>2019-03-19 16:23:02 +0100
commit2ba92871319d7af63472c1380664a9f9eeb1c690 (patch)
treed593b2dfea29a8171b9f6afaaef076321f5edf71 /server/lib/activitypub/videos.ts
parentd74d29ad9e35929491cf37223398d2535ab23de0 (diff)
downloadPeerTube-2ba92871319d7af63472c1380664a9f9eeb1c690.tar.gz
PeerTube-2ba92871319d7af63472c1380664a9f9eeb1c690.tar.zst
PeerTube-2ba92871319d7af63472c1380664a9f9eeb1c690.zip
Cleanup invalid rates/comments/shares
Diffstat (limited to 'server/lib/activitypub/videos.ts')
-rw-r--r--server/lib/activitypub/videos.ts25
1 files changed, 20 insertions, 5 deletions
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts
index 66d0abf35..2c932371b 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -40,6 +40,9 @@ import { Notifier } from '../notifier'
40import { VideoStreamingPlaylistModel } from '../../models/video/video-streaming-playlist' 40import { VideoStreamingPlaylistModel } from '../../models/video/video-streaming-playlist'
41import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' 41import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
42import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model' 42import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model'
43import { AccountVideoRateModel } from '../../models/account/account-video-rate'
44import { VideoShareModel } from '../../models/video/video-share'
45import { VideoCommentModel } from '../../models/video/video-comment'
43 46
44async function federateVideoIfNeeded (video: VideoModel, isNewVideo: boolean, transaction?: sequelize.Transaction) { 47async function federateVideoIfNeeded (video: VideoModel, isNewVideo: boolean, transaction?: sequelize.Transaction) {
45 // If the video is not private and published, we federate it 48 // If the video is not private and published, we federate it
@@ -134,31 +137,43 @@ async function syncVideoExternalAttributes (video: VideoModel, fetchedVideo: Vid
134 const jobPayloads: ActivitypubHttpFetcherPayload[] = [] 137 const jobPayloads: ActivitypubHttpFetcherPayload[] = []
135 138
136 if (syncParam.likes === true) { 139 if (syncParam.likes === true) {
137 await crawlCollectionPage<string>(fetchedVideo.likes, items => createRates(items, video, 'like')) 140 const handler = items => createRates(items, video, 'like')
141 const cleaner = crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'like' as 'like', crawlStartDate)
142
143 await crawlCollectionPage<string>(fetchedVideo.likes, handler, cleaner)
138 .catch(err => logger.error('Cannot add likes of video %s.', video.uuid, { err })) 144 .catch(err => logger.error('Cannot add likes of video %s.', video.uuid, { err }))
139 } else { 145 } else {
140 jobPayloads.push({ uri: fetchedVideo.likes, videoId: video.id, type: 'video-likes' as 'video-likes' }) 146 jobPayloads.push({ uri: fetchedVideo.likes, videoId: video.id, type: 'video-likes' as 'video-likes' })
141 } 147 }
142 148
143 if (syncParam.dislikes === true) { 149 if (syncParam.dislikes === true) {
144 await crawlCollectionPage<string>(fetchedVideo.dislikes, items => createRates(items, video, 'dislike')) 150 const handler = items => createRates(items, video, 'dislike')
151 const cleaner = crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'dislike' as 'dislike', crawlStartDate)
152
153 await crawlCollectionPage<string>(fetchedVideo.dislikes, handler, cleaner)
145 .catch(err => logger.error('Cannot add dislikes of video %s.', video.uuid, { err })) 154 .catch(err => logger.error('Cannot add dislikes of video %s.', video.uuid, { err }))
146 } else { 155 } else {
147 jobPayloads.push({ uri: fetchedVideo.dislikes, videoId: video.id, type: 'video-dislikes' as 'video-dislikes' }) 156 jobPayloads.push({ uri: fetchedVideo.dislikes, videoId: video.id, type: 'video-dislikes' as 'video-dislikes' })
148 } 157 }
149 158
150 if (syncParam.shares === true) { 159 if (syncParam.shares === true) {
151 await crawlCollectionPage<string>(fetchedVideo.shares, items => addVideoShares(items, video)) 160 const handler = items => addVideoShares(items, video)
161 const cleaner = crawlStartDate => VideoShareModel.cleanOldSharesOf(video.id, crawlStartDate)
162
163 await crawlCollectionPage<string>(fetchedVideo.shares, handler, cleaner)
152 .catch(err => logger.error('Cannot add shares of video %s.', video.uuid, { err })) 164 .catch(err => logger.error('Cannot add shares of video %s.', video.uuid, { err }))
153 } else { 165 } else {
154 jobPayloads.push({ uri: fetchedVideo.shares, videoId: video.id, type: 'video-shares' as 'video-shares' }) 166 jobPayloads.push({ uri: fetchedVideo.shares, videoId: video.id, type: 'video-shares' as 'video-shares' })
155 } 167 }
156 168
157 if (syncParam.comments === true) { 169 if (syncParam.comments === true) {
158 await crawlCollectionPage<string>(fetchedVideo.comments, items => addVideoComments(items, video)) 170 const handler = items => addVideoComments(items, video)
171 const cleaner = crawlStartDate => VideoCommentModel.cleanOldCommentsOf(video.id, crawlStartDate)
172
173 await crawlCollectionPage<string>(fetchedVideo.comments, handler, cleaner)
159 .catch(err => logger.error('Cannot add comments of video %s.', video.uuid, { err })) 174 .catch(err => logger.error('Cannot add comments of video %s.', video.uuid, { err }))
160 } else { 175 } else {
161 jobPayloads.push({ uri: fetchedVideo.shares, videoId: video.id, type: 'video-shares' as 'video-shares' }) 176 jobPayloads.push({ uri: fetchedVideo.comments, videoId: video.id, type: 'video-comments' as 'video-comments' })
162 } 177 }
163 178
164 await Bluebird.map(jobPayloads, payload => JobQueue.Instance.createJob({ type: 'activitypub-http-fetcher', payload })) 179 await Bluebird.map(jobPayloads, payload => JobQueue.Instance.createJob({ type: 'activitypub-http-fetcher', payload }))