2018-07-10 11:02:20 -04:00
|
|
|
import * as Bull from 'bull'
|
2020-12-08 08:30:29 -05:00
|
|
|
import { ActivitypubHttpFetcherPayload, FetchType } from '@shared/models'
|
2017-12-28 05:16:08 -05:00
|
|
|
import { logger } from '../../../helpers/logger'
|
2019-02-26 04:55:40 -05:00
|
|
|
import { AccountModel } from '../../../models/account/account'
|
2019-03-19 11:23:02 -04:00
|
|
|
import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
|
2020-12-08 08:30:29 -05:00
|
|
|
import { VideoModel } from '../../../models/video/video'
|
2019-03-19 11:23:02 -04:00
|
|
|
import { VideoCommentModel } from '../../../models/video/video-comment'
|
2020-12-08 08:30:29 -05:00
|
|
|
import { VideoShareModel } from '../../../models/video/video-share'
|
2020-06-18 04:45:25 -04:00
|
|
|
import { MAccountDefault, MVideoFullLight } from '../../../types/models'
|
2020-12-08 08:30:29 -05:00
|
|
|
import { crawlCollectionPage } from '../../activitypub/crawl'
|
|
|
|
import { createAccountPlaylists } from '../../activitypub/playlist'
|
|
|
|
import { processActivities } from '../../activitypub/process'
|
|
|
|
import { addVideoShares } from '../../activitypub/share'
|
|
|
|
import { addVideoComments } from '../../activitypub/video-comments'
|
|
|
|
import { createRates } from '../../activitypub/video-rates'
|
2018-01-25 09:05:18 -05:00
|
|
|
|
2018-07-10 11:02:20 -04:00
|
|
|
async function processActivityPubHttpFetcher (job: Bull.Job) {
|
2018-01-25 09:05:18 -05:00
|
|
|
logger.info('Processing ActivityPub fetcher in job %d.', job.id)
|
|
|
|
|
2018-08-22 05:51:39 -04:00
|
|
|
const payload = job.data as ActivitypubHttpFetcherPayload
|
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
let video: MVideoFullLight
|
2018-08-22 05:51:39 -04:00
|
|
|
if (payload.videoId) video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoId)
|
2017-11-22 04:29:55 -05:00
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
let account: MAccountDefault
|
2019-02-26 04:55:40 -05:00
|
|
|
if (payload.accountId) account = await AccountModel.load(payload.accountId)
|
|
|
|
|
2018-08-22 05:51:39 -04:00
|
|
|
const fetcherType: { [ id in FetchType ]: (items: any[]) => Promise<any> } = {
|
2019-08-02 04:53:36 -04:00
|
|
|
'activity': items => processActivities(items, { outboxUrl: payload.uri, fromFetch: true }),
|
2018-08-22 05:51:39 -04:00
|
|
|
'video-likes': items => createRates(items, video, 'like'),
|
|
|
|
'video-dislikes': items => createRates(items, video, 'dislike'),
|
|
|
|
'video-shares': items => addVideoShares(items, video),
|
2019-08-06 11:19:53 -04:00
|
|
|
'video-comments': items => addVideoComments(items),
|
2019-02-26 04:55:40 -05:00
|
|
|
'account-playlists': items => createAccountPlaylists(items, account)
|
2017-11-22 04:29:55 -05:00
|
|
|
}
|
2018-08-22 05:51:39 -04:00
|
|
|
|
2020-12-08 08:30:29 -05:00
|
|
|
const cleanerType: { [ id in FetchType ]?: (crawlStartDate: Date) => Promise<any> } = {
|
2019-03-19 11:23:02 -04:00
|
|
|
'video-likes': crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'like' as 'like', crawlStartDate),
|
|
|
|
'video-dislikes': crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'dislike' as 'dislike', crawlStartDate),
|
|
|
|
'video-shares': crawlStartDate => VideoShareModel.cleanOldSharesOf(video.id, crawlStartDate),
|
|
|
|
'video-comments': crawlStartDate => VideoCommentModel.cleanOldCommentsOf(video.id, crawlStartDate)
|
|
|
|
}
|
|
|
|
|
|
|
|
return crawlCollectionPage(payload.uri, fetcherType[payload.type], cleanerType[payload.type])
|
2017-11-22 04:29:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2018-01-25 09:05:18 -05:00
|
|
|
processActivityPubHttpFetcher
|
2017-11-22 04:29:55 -05:00
|
|
|
}
|