diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-22 11:51:39 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-27 09:41:54 +0200 |
commit | f6eebcb336c067e160a62020a5140d8d992ba384 (patch) | |
tree | 48fbf9c292243c9cc13beb3749eceaf61fe2baef /server/lib/job-queue | |
parent | 22a16e36f6526887ed8f5e5d3c9f9e5da0b4a8cd (diff) | |
download | PeerTube-f6eebcb336c067e160a62020a5140d8d992ba384.tar.gz PeerTube-f6eebcb336c067e160a62020a5140d8d992ba384.tar.zst PeerTube-f6eebcb336c067e160a62020a5140d8d992ba384.zip |
Add ability to search a video with an URL
Diffstat (limited to 'server/lib/job-queue')
-rw-r--r-- | server/lib/job-queue/handlers/activitypub-http-fetcher.ts | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/server/lib/job-queue/handlers/activitypub-http-fetcher.ts b/server/lib/job-queue/handlers/activitypub-http-fetcher.ts index f21da087e..72d670277 100644 --- a/server/lib/job-queue/handlers/activitypub-http-fetcher.ts +++ b/server/lib/job-queue/handlers/activitypub-http-fetcher.ts | |||
@@ -1,22 +1,36 @@ | |||
1 | import * as Bull from 'bull' | 1 | import * as Bull from 'bull' |
2 | import { logger } from '../../../helpers/logger' | 2 | import { logger } from '../../../helpers/logger' |
3 | import { processActivities } from '../../activitypub/process' | 3 | import { processActivities } from '../../activitypub/process' |
4 | import { ActivitypubHttpBroadcastPayload } from './activitypub-http-broadcast' | 4 | import { VideoModel } from '../../../models/video/video' |
5 | import { addVideoShares, createRates } from '../../activitypub/videos' | ||
6 | import { addVideoComments } from '../../activitypub/video-comments' | ||
5 | import { crawlCollectionPage } from '../../activitypub/crawl' | 7 | import { crawlCollectionPage } from '../../activitypub/crawl' |
6 | import { Activity } from '../../../../shared/models/activitypub' | 8 | |
9 | type FetchType = 'activity' | 'video-likes' | 'video-dislikes' | 'video-shares' | 'video-comments' | ||
7 | 10 | ||
8 | export type ActivitypubHttpFetcherPayload = { | 11 | export type ActivitypubHttpFetcherPayload = { |
9 | uris: string[] | 12 | uri: string |
13 | type: FetchType | ||
14 | videoId?: number | ||
10 | } | 15 | } |
11 | 16 | ||
12 | async function processActivityPubHttpFetcher (job: Bull.Job) { | 17 | async function processActivityPubHttpFetcher (job: Bull.Job) { |
13 | logger.info('Processing ActivityPub fetcher in job %d.', job.id) | 18 | logger.info('Processing ActivityPub fetcher in job %d.', job.id) |
14 | 19 | ||
15 | const payload = job.data as ActivitypubHttpBroadcastPayload | 20 | const payload = job.data as ActivitypubHttpFetcherPayload |
21 | |||
22 | let video: VideoModel | ||
23 | if (payload.videoId) video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoId) | ||
16 | 24 | ||
17 | for (const uri of payload.uris) { | 25 | const fetcherType: { [ id in FetchType ]: (items: any[]) => Promise<any> } = { |
18 | await crawlCollectionPage<Activity>(uri, (items) => processActivities(items)) | 26 | 'activity': items => processActivities(items), |
27 | 'video-likes': items => createRates(items, video, 'like'), | ||
28 | 'video-dislikes': items => createRates(items, video, 'dislike'), | ||
29 | 'video-shares': items => addVideoShares(items, video), | ||
30 | 'video-comments': items => addVideoComments(items, video) | ||
19 | } | 31 | } |
32 | |||
33 | return crawlCollectionPage(payload.uri, fetcherType[payload.type]) | ||
20 | } | 34 | } |
21 | 35 | ||
22 | // --------------------------------------------------------------------------- | 36 | // --------------------------------------------------------------------------- |