diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-06 17:19:53 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-06 17:26:51 +0200 |
commit | 6b9c966f6428c9e47bead3410a0401e8ebd744bf (patch) | |
tree | 282218ec56725b0e2e878b0471cd08a54fd91998 /server/lib/activitypub/videos.ts | |
parent | 466e3f20a537f1eff4b4fd03297df11ba371d049 (diff) | |
download | PeerTube-6b9c966f6428c9e47bead3410a0401e8ebd744bf.tar.gz PeerTube-6b9c966f6428c9e47bead3410a0401e8ebd744bf.tar.zst PeerTube-6b9c966f6428c9e47bead3410a0401e8ebd744bf.zip |
Automatically remove bad followings
Diffstat (limited to 'server/lib/activitypub/videos.ts')
-rw-r--r-- | server/lib/activitypub/videos.ts | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index d7bc3d650..2102702e1 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -56,6 +56,7 @@ import { join } from 'path' | |||
56 | import { FilteredModelAttributes } from '../../typings/sequelize' | 56 | import { FilteredModelAttributes } from '../../typings/sequelize' |
57 | import { Hooks } from '../plugins/hooks' | 57 | import { Hooks } from '../plugins/hooks' |
58 | import { autoBlacklistVideoIfNeeded } from '../video-blacklist' | 58 | import { autoBlacklistVideoIfNeeded } from '../video-blacklist' |
59 | import { ActorFollowScoreCache } from '../files-cache' | ||
59 | 60 | ||
60 | async function federateVideoIfNeeded (video: VideoModel, isNewVideo: boolean, transaction?: sequelize.Transaction) { | 61 | async function federateVideoIfNeeded (video: VideoModel, isNewVideo: boolean, transaction?: sequelize.Transaction) { |
61 | if ( | 62 | if ( |
@@ -182,7 +183,7 @@ async function syncVideoExternalAttributes (video: VideoModel, fetchedVideo: Vid | |||
182 | } | 183 | } |
183 | 184 | ||
184 | if (syncParam.comments === true) { | 185 | if (syncParam.comments === true) { |
185 | const handler = items => addVideoComments(items, video) | 186 | const handler = items => addVideoComments(items) |
186 | const cleaner = crawlStartDate => VideoCommentModel.cleanOldCommentsOf(video.id, crawlStartDate) | 187 | const cleaner = crawlStartDate => VideoCommentModel.cleanOldCommentsOf(video.id, crawlStartDate) |
187 | 188 | ||
188 | await crawlCollectionPage<string>(fetchedVideo.comments, handler, cleaner) | 189 | await crawlCollectionPage<string>(fetchedVideo.comments, handler, cleaner) |
@@ -421,10 +422,14 @@ async function refreshVideoIfNeeded (options: { | |||
421 | await retryTransactionWrapper(updateVideoFromAP, updateOptions) | 422 | await retryTransactionWrapper(updateVideoFromAP, updateOptions) |
422 | await syncVideoExternalAttributes(video, videoObject, options.syncParam) | 423 | await syncVideoExternalAttributes(video, videoObject, options.syncParam) |
423 | 424 | ||
425 | ActorFollowScoreCache.Instance.addGoodServerId(video.VideoChannel.Actor.serverId) | ||
426 | |||
424 | return video | 427 | return video |
425 | } catch (err) { | 428 | } catch (err) { |
426 | logger.warn('Cannot refresh video %s.', options.video.url, { err }) | 429 | logger.warn('Cannot refresh video %s.', options.video.url, { err }) |
427 | 430 | ||
431 | ActorFollowScoreCache.Instance.addBadServerId(video.VideoChannel.Actor.serverId) | ||
432 | |||
428 | // Don't refresh in loop | 433 | // Don't refresh in loop |
429 | await video.setAsRefreshed() | 434 | await video.setAsRefreshed() |
430 | return video | 435 | return video |
@@ -500,7 +505,7 @@ async function createVideo (videoObject: VideoTorrentObject, channelActor: Actor | |||
500 | 505 | ||
501 | const videoStreamingPlaylists = streamingPlaylistActivityUrlToDBAttributes(videoCreated, videoObject, videoFiles) | 506 | const videoStreamingPlaylists = streamingPlaylistActivityUrlToDBAttributes(videoCreated, videoObject, videoFiles) |
502 | const playlistPromises = videoStreamingPlaylists.map(p => VideoStreamingPlaylistModel.create(p, { transaction: t })) | 507 | const playlistPromises = videoStreamingPlaylists.map(p => VideoStreamingPlaylistModel.create(p, { transaction: t })) |
503 | await Promise.all(playlistPromises) | 508 | const streamingPlaylists = await Promise.all(playlistPromises) |
504 | 509 | ||
505 | // Process tags | 510 | // Process tags |
506 | const tags = videoObject.tag | 511 | const tags = videoObject.tag |
@@ -513,7 +518,12 @@ async function createVideo (videoObject: VideoTorrentObject, channelActor: Actor | |||
513 | const videoCaptionsPromises = videoObject.subtitleLanguage.map(c => { | 518 | const videoCaptionsPromises = videoObject.subtitleLanguage.map(c => { |
514 | return VideoCaptionModel.insertOrReplaceLanguage(videoCreated.id, c.identifier, t) | 519 | return VideoCaptionModel.insertOrReplaceLanguage(videoCreated.id, c.identifier, t) |
515 | }) | 520 | }) |
516 | await Promise.all(videoCaptionsPromises) | 521 | const captions = await Promise.all(videoCaptionsPromises) |
522 | |||
523 | video.VideoFiles = videoFiles | ||
524 | video.VideoStreamingPlaylists = streamingPlaylists | ||
525 | video.Tags = tagInstances | ||
526 | video.VideoCaptions = captions | ||
517 | 527 | ||
518 | const autoBlacklisted = await autoBlacklistVideoIfNeeded({ | 528 | const autoBlacklisted = await autoBlacklistVideoIfNeeded({ |
519 | video, | 529 | video, |