diff options
Diffstat (limited to 'server/lib/job-queue/handlers')
-rw-r--r-- | server/lib/job-queue/handlers/activitypub-http-fetcher.ts | 2 | ||||
-rw-r--r-- | server/lib/job-queue/handlers/utils/activitypub-http-utils.ts | 13 | ||||
-rw-r--r-- | server/lib/job-queue/handlers/video-views.ts | 8 |
3 files changed, 16 insertions, 7 deletions
diff --git a/server/lib/job-queue/handlers/activitypub-http-fetcher.ts b/server/lib/job-queue/handlers/activitypub-http-fetcher.ts index 42217c27c..67ccfa995 100644 --- a/server/lib/job-queue/handlers/activitypub-http-fetcher.ts +++ b/server/lib/job-queue/handlers/activitypub-http-fetcher.ts | |||
@@ -23,7 +23,7 @@ async function processActivityPubHttpFetcher (job: Bull.Job) { | |||
23 | if (payload.videoId) video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoId) | 23 | if (payload.videoId) video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoId) |
24 | 24 | ||
25 | const fetcherType: { [ id in FetchType ]: (items: any[]) => Promise<any> } = { | 25 | const fetcherType: { [ id in FetchType ]: (items: any[]) => Promise<any> } = { |
26 | 'activity': items => processActivities(items), | 26 | 'activity': items => processActivities(items, { outboxUrl: payload.uri }), |
27 | 'video-likes': items => createRates(items, video, 'like'), | 27 | 'video-likes': items => createRates(items, video, 'like'), |
28 | 'video-dislikes': items => createRates(items, video, 'dislike'), | 28 | 'video-dislikes': items => createRates(items, video, 'dislike'), |
29 | 'video-shares': items => addVideoShares(items, video), | 29 | 'video-shares': items => addVideoShares(items, video), |
diff --git a/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts b/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts index fd9c74341..4961d4502 100644 --- a/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts +++ b/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts | |||
@@ -38,15 +38,20 @@ async function buildSignedRequestOptions (payload: Payload) { | |||
38 | } | 38 | } |
39 | } | 39 | } |
40 | 40 | ||
41 | function buildGlobalHeaders (body: object) { | 41 | function buildGlobalHeaders (body: any) { |
42 | const digest = 'SHA-256=' + sha256(JSON.stringify(body), 'base64') | ||
43 | |||
44 | return { | 42 | return { |
45 | 'Digest': digest | 43 | 'Digest': buildDigest(body) |
46 | } | 44 | } |
47 | } | 45 | } |
48 | 46 | ||
47 | function buildDigest (body: any) { | ||
48 | const rawBody = typeof body === 'string' ? body : JSON.stringify(body) | ||
49 | |||
50 | return 'SHA-256=' + sha256(rawBody, 'base64') | ||
51 | } | ||
52 | |||
49 | export { | 53 | export { |
54 | buildDigest, | ||
50 | buildGlobalHeaders, | 55 | buildGlobalHeaders, |
51 | computeBody, | 56 | computeBody, |
52 | buildSignedRequestOptions | 57 | buildSignedRequestOptions |
diff --git a/server/lib/job-queue/handlers/video-views.ts b/server/lib/job-queue/handlers/video-views.ts index cf180a11a..f44c3c727 100644 --- a/server/lib/job-queue/handlers/video-views.ts +++ b/server/lib/job-queue/handlers/video-views.ts | |||
@@ -3,8 +3,9 @@ import { logger } from '../../../helpers/logger' | |||
3 | import { VideoModel } from '../../../models/video/video' | 3 | import { VideoModel } from '../../../models/video/video' |
4 | import { VideoViewModel } from '../../../models/video/video-views' | 4 | import { VideoViewModel } from '../../../models/video/video-views' |
5 | import { isTestInstance } from '../../../helpers/core-utils' | 5 | import { isTestInstance } from '../../../helpers/core-utils' |
6 | import { federateVideoIfNeeded } from '../../activitypub' | ||
6 | 7 | ||
7 | async function processVideosViewsViews () { | 8 | async function processVideosViews () { |
8 | const lastHour = new Date() | 9 | const lastHour = new Date() |
9 | 10 | ||
10 | // In test mode, we run this function multiple times per hour, so we don't want the values of the previous hour | 11 | // In test mode, we run this function multiple times per hour, so we don't want the values of the previous hour |
@@ -36,6 +37,9 @@ async function processVideosViewsViews () { | |||
36 | views, | 37 | views, |
37 | videoId | 38 | videoId |
38 | }) | 39 | }) |
40 | |||
41 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId) | ||
42 | if (video.isOwned()) await federateVideoIfNeeded(video, false) | ||
39 | } catch (err) { | 43 | } catch (err) { |
40 | logger.debug('Cannot create video views for video %d in hour %d. Maybe the video does not exist anymore?', videoId, hour) | 44 | logger.debug('Cannot create video views for video %d in hour %d. Maybe the video does not exist anymore?', videoId, hour) |
41 | } | 45 | } |
@@ -51,5 +55,5 @@ async function processVideosViewsViews () { | |||
51 | // --------------------------------------------------------------------------- | 55 | // --------------------------------------------------------------------------- |
52 | 56 | ||
53 | export { | 57 | export { |
54 | processVideosViewsViews | 58 | processVideosViews |
55 | } | 59 | } |