diff options
author | Chocobozzz <me@florianbigard.com> | 2023-09-01 09:58:13 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-09-01 09:58:13 +0200 |
commit | 0cc1a698813e50d86b5a2a8400e1e8a9b82461da (patch) | |
tree | e2661e12e76f6791e8d4314d6a1c029d8fd97816 /server | |
parent | c4799cd1b919a0e7081872b995fe1637c174cab8 (diff) | |
download | PeerTube-0cc1a698813e50d86b5a2a8400e1e8a9b82461da.tar.gz PeerTube-0cc1a698813e50d86b5a2a8400e1e8a9b82461da.tar.zst PeerTube-0cc1a698813e50d86b5a2a8400e1e8a9b82461da.zip |
Avoid federation error logs with likes on notes
Diffstat (limited to 'server')
5 files changed, 32 insertions, 39 deletions
diff --git a/server/server/lib/activitypub/process/process-announce.ts b/server/server/lib/activitypub/process/process-announce.ts index ed178f73c..b9598c8f9 100644 --- a/server/server/lib/activitypub/process/process-announce.ts +++ b/server/server/lib/activitypub/process/process-announce.ts | |||
@@ -1,14 +1,13 @@ | |||
1 | import { ActivityAnnounce } from '@peertube/peertube-models' | 1 | import { ActivityAnnounce } from '@peertube/peertube-models' |
2 | import { getAPId } from '@server/lib/activitypub/activity.js' | 2 | import { getAPId } from '@server/lib/activitypub/activity.js' |
3 | import { retryTransactionWrapper } from '../../../helpers/database-utils.js' | 3 | import { retryTransactionWrapper } from '../../../helpers/database-utils.js' |
4 | import { logger } from '../../../helpers/logger.js' | ||
5 | import { sequelizeTypescript } from '../../../initializers/database.js' | 4 | import { sequelizeTypescript } from '../../../initializers/database.js' |
6 | import { VideoShareModel } from '../../../models/video/video-share.js' | 5 | import { VideoShareModel } from '../../../models/video/video-share.js' |
7 | import { APProcessorOptions } from '../../../types/activitypub-processor.model.js' | 6 | import { APProcessorOptions } from '../../../types/activitypub-processor.model.js' |
8 | import { MActorSignature, MVideoAccountLightBlacklistAllFiles } from '../../../types/models/index.js' | 7 | import { MActorSignature } from '../../../types/models/index.js' |
9 | import { Notifier } from '../../notifier/index.js' | 8 | import { Notifier } from '../../notifier/index.js' |
10 | import { forwardVideoRelatedActivity } from '../send/shared/send-utils.js' | 9 | import { forwardVideoRelatedActivity } from '../send/shared/send-utils.js' |
11 | import { getOrCreateAPVideo } from '../videos/index.js' | 10 | import { maybeGetOrCreateAPVideo } from '../videos/index.js' |
12 | 11 | ||
13 | async function processAnnounceActivity (options: APProcessorOptions<ActivityAnnounce>) { | 12 | async function processAnnounceActivity (options: APProcessorOptions<ActivityAnnounce>) { |
14 | const { activity, byActor: actorAnnouncer } = options | 13 | const { activity, byActor: actorAnnouncer } = options |
@@ -32,17 +31,8 @@ export { | |||
32 | async function processVideoShare (actorAnnouncer: MActorSignature, activity: ActivityAnnounce, notify: boolean) { | 31 | async function processVideoShare (actorAnnouncer: MActorSignature, activity: ActivityAnnounce, notify: boolean) { |
33 | const objectUri = getAPId(activity.object) | 32 | const objectUri = getAPId(activity.object) |
34 | 33 | ||
35 | let video: MVideoAccountLightBlacklistAllFiles | 34 | const { video, created: videoCreated } = await maybeGetOrCreateAPVideo({ videoObject: objectUri }) |
36 | let videoCreated: boolean | 35 | if (!video) return |
37 | |||
38 | try { | ||
39 | const result = await getOrCreateAPVideo({ videoObject: objectUri }) | ||
40 | video = result.video | ||
41 | videoCreated = result.created | ||
42 | } catch (err) { | ||
43 | logger.debug('Cannot process share of %s. Maybe this is not a video object, so just skipping.', objectUri, { err }) | ||
44 | return | ||
45 | } | ||
46 | 36 | ||
47 | await sequelizeTypescript.transaction(async t => { | 37 | await sequelizeTypescript.transaction(async t => { |
48 | // Add share entry | 38 | // Add share entry |
diff --git a/server/server/lib/activitypub/process/process-dislike.ts b/server/server/lib/activitypub/process/process-dislike.ts index 8040cad93..9182e6de4 100644 --- a/server/server/lib/activitypub/process/process-dislike.ts +++ b/server/server/lib/activitypub/process/process-dislike.ts | |||
@@ -5,7 +5,7 @@ import { sequelizeTypescript } from '../../../initializers/database.js' | |||
5 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate.js' | 5 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate.js' |
6 | import { APProcessorOptions } from '../../../types/activitypub-processor.model.js' | 6 | import { APProcessorOptions } from '../../../types/activitypub-processor.model.js' |
7 | import { MActorSignature } from '../../../types/models/index.js' | 7 | import { MActorSignature } from '../../../types/models/index.js' |
8 | import { federateVideoIfNeeded, getOrCreateAPVideo } from '../videos/index.js' | 8 | import { federateVideoIfNeeded, maybeGetOrCreateAPVideo } from '../videos/index.js' |
9 | 9 | ||
10 | async function processDislikeActivity (options: APProcessorOptions<ActivityDislike>) { | 10 | async function processDislikeActivity (options: APProcessorOptions<ActivityDislike>) { |
11 | const { activity, byActor } = options | 11 | const { activity, byActor } = options |
@@ -26,10 +26,8 @@ async function processDislike (activity: ActivityDislike, byActor: MActorSignatu | |||
26 | 26 | ||
27 | if (!byAccount) throw new Error('Cannot create dislike with the non account actor ' + byActor.url) | 27 | if (!byAccount) throw new Error('Cannot create dislike with the non account actor ' + byActor.url) |
28 | 28 | ||
29 | const { video: onlyVideo } = await getOrCreateAPVideo({ videoObject: dislikeObject, fetchType: 'only-video' }) | 29 | const { video: onlyVideo } = await maybeGetOrCreateAPVideo({ videoObject: dislikeObject, fetchType: 'only-video' }) |
30 | 30 | if (!onlyVideo?.isOwned()) return | |
31 | // We don't care about dislikes of remote videos | ||
32 | if (!onlyVideo.isOwned()) return | ||
33 | 31 | ||
34 | return sequelizeTypescript.transaction(async t => { | 32 | return sequelizeTypescript.transaction(async t => { |
35 | const video = await VideoModel.loadFull(onlyVideo.id, t) | 33 | const video = await VideoModel.loadFull(onlyVideo.id, t) |
diff --git a/server/server/lib/activitypub/process/process-like.ts b/server/server/lib/activitypub/process/process-like.ts index 03637f9a7..ccdb37a02 100644 --- a/server/server/lib/activitypub/process/process-like.ts +++ b/server/server/lib/activitypub/process/process-like.ts | |||
@@ -6,7 +6,7 @@ import { getAPId } from '../../../lib/activitypub/activity.js' | |||
6 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate.js' | 6 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate.js' |
7 | import { APProcessorOptions } from '../../../types/activitypub-processor.model.js' | 7 | import { APProcessorOptions } from '../../../types/activitypub-processor.model.js' |
8 | import { MActorSignature } from '../../../types/models/index.js' | 8 | import { MActorSignature } from '../../../types/models/index.js' |
9 | import { federateVideoIfNeeded, getOrCreateAPVideo } from '../videos/index.js' | 9 | import { federateVideoIfNeeded, maybeGetOrCreateAPVideo } from '../videos/index.js' |
10 | 10 | ||
11 | async function processLikeActivity (options: APProcessorOptions<ActivityLike>) { | 11 | async function processLikeActivity (options: APProcessorOptions<ActivityLike>) { |
12 | const { activity, byActor } = options | 12 | const { activity, byActor } = options |
@@ -28,10 +28,8 @@ async function processLikeVideo (byActor: MActorSignature, activity: ActivityLik | |||
28 | const byAccount = byActor.Account | 28 | const byAccount = byActor.Account |
29 | if (!byAccount) throw new Error('Cannot create like with the non account actor ' + byActor.url) | 29 | if (!byAccount) throw new Error('Cannot create like with the non account actor ' + byActor.url) |
30 | 30 | ||
31 | const { video: onlyVideo } = await getOrCreateAPVideo({ videoObject: videoUrl, fetchType: 'only-video' }) | 31 | const { video: onlyVideo } = await maybeGetOrCreateAPVideo({ videoObject: videoUrl, fetchType: 'only-video' }) |
32 | 32 | if (!onlyVideo?.isOwned()) return | |
33 | // We don't care about likes of remote videos | ||
34 | if (!onlyVideo.isOwned()) return | ||
35 | 33 | ||
36 | return sequelizeTypescript.transaction(async t => { | 34 | return sequelizeTypescript.transaction(async t => { |
37 | const video = await VideoModel.loadFull(onlyVideo.id, t) | 35 | const video = await VideoModel.loadFull(onlyVideo.id, t) |
diff --git a/server/server/lib/activitypub/process/process-undo.ts b/server/server/lib/activitypub/process/process-undo.ts index 20a167f7b..635c4c3b8 100644 --- a/server/server/lib/activitypub/process/process-undo.ts +++ b/server/server/lib/activitypub/process/process-undo.ts | |||
@@ -21,7 +21,7 @@ import { APProcessorOptions } from '../../../types/activitypub-processor.model.j | |||
21 | import { MActorSignature } from '../../../types/models/index.js' | 21 | import { MActorSignature } from '../../../types/models/index.js' |
22 | import { fetchAPObjectIfNeeded } from '../activity.js' | 22 | import { fetchAPObjectIfNeeded } from '../activity.js' |
23 | import { forwardVideoRelatedActivity } from '../send/shared/send-utils.js' | 23 | import { forwardVideoRelatedActivity } from '../send/shared/send-utils.js' |
24 | import { federateVideoIfNeeded, getOrCreateAPVideo } from '../videos/index.js' | 24 | import { federateVideoIfNeeded, getOrCreateAPVideo, maybeGetOrCreateAPVideo } from '../videos/index.js' |
25 | 25 | ||
26 | async function processUndoActivity (options: APProcessorOptions<ActivityUndo<ActivityUndoObject>>) { | 26 | async function processUndoActivity (options: APProcessorOptions<ActivityUndo<ActivityUndoObject>>) { |
27 | const { activity, byActor } = options | 27 | const { activity, byActor } = options |
@@ -67,9 +67,8 @@ export { | |||
67 | async function processUndoLike (byActor: MActorSignature, activity: ActivityUndo<ActivityLike>) { | 67 | async function processUndoLike (byActor: MActorSignature, activity: ActivityUndo<ActivityLike>) { |
68 | const likeActivity = activity.object | 68 | const likeActivity = activity.object |
69 | 69 | ||
70 | const { video: onlyVideo } = await getOrCreateAPVideo({ videoObject: likeActivity.object }) | 70 | const { video: onlyVideo } = await maybeGetOrCreateAPVideo({ videoObject: likeActivity.object }) |
71 | // We don't care about likes of remote videos | 71 | if (!onlyVideo?.isOwned()) return |
72 | if (!onlyVideo.isOwned()) return | ||
73 | 72 | ||
74 | return sequelizeTypescript.transaction(async t => { | 73 | return sequelizeTypescript.transaction(async t => { |
75 | if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) | 74 | if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) |
@@ -92,9 +91,8 @@ async function processUndoLike (byActor: MActorSignature, activity: ActivityUndo | |||
92 | async function processUndoDislike (byActor: MActorSignature, activity: ActivityUndo<ActivityDislike>) { | 91 | async function processUndoDislike (byActor: MActorSignature, activity: ActivityUndo<ActivityDislike>) { |
93 | const dislikeActivity = activity.object | 92 | const dislikeActivity = activity.object |
94 | 93 | ||
95 | const { video: onlyVideo } = await getOrCreateAPVideo({ videoObject: dislikeActivity.object }) | 94 | const { video: onlyVideo } = await maybeGetOrCreateAPVideo({ videoObject: dislikeActivity.object }) |
96 | // We don't care about likes of remote videos | 95 | if (!onlyVideo?.isOwned()) return |
97 | if (!onlyVideo.isOwned()) return | ||
98 | 96 | ||
99 | return sequelizeTypescript.transaction(async t => { | 97 | return sequelizeTypescript.transaction(async t => { |
100 | if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) | 98 | if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) |
diff --git a/server/server/lib/activitypub/videos/get.ts b/server/server/lib/activitypub/videos/get.ts index 6d70a490f..54efcc08f 100644 --- a/server/server/lib/activitypub/videos/get.ts +++ b/server/server/lib/activitypub/videos/get.ts | |||
@@ -35,11 +35,10 @@ type GetVideoParamOther = { | |||
35 | allowRefresh?: boolean | 35 | allowRefresh?: boolean |
36 | } | 36 | } |
37 | 37 | ||
38 | function getOrCreateAPVideo (options: GetVideoParamAll): GetVideoResult<MVideoAccountLightBlacklistAllFiles> | 38 | export function getOrCreateAPVideo (options: GetVideoParamAll): GetVideoResult<MVideoAccountLightBlacklistAllFiles> |
39 | function getOrCreateAPVideo (options: GetVideoParamImmutable): GetVideoResult<MVideoImmutable> | 39 | export function getOrCreateAPVideo (options: GetVideoParamImmutable): GetVideoResult<MVideoImmutable> |
40 | function getOrCreateAPVideo (options: GetVideoParamOther): GetVideoResult<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail> | 40 | export function getOrCreateAPVideo (options: GetVideoParamOther): GetVideoResult<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail> |
41 | 41 | export async function getOrCreateAPVideo ( | |
42 | async function getOrCreateAPVideo ( | ||
43 | options: GetVideoParamAll | GetVideoParamImmutable | GetVideoParamOther | 42 | options: GetVideoParamAll | GetVideoParamImmutable | GetVideoParamOther |
44 | ): GetVideoResult<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> { | 43 | ): GetVideoResult<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> { |
45 | // Default params | 44 | // Default params |
@@ -86,13 +85,23 @@ async function getOrCreateAPVideo ( | |||
86 | } | 85 | } |
87 | } | 86 | } |
88 | 87 | ||
89 | // --------------------------------------------------------------------------- | 88 | export function maybeGetOrCreateAPVideo (options: GetVideoParamAll): GetVideoResult<MVideoAccountLightBlacklistAllFiles> |
89 | export function maybeGetOrCreateAPVideo (options: GetVideoParamImmutable): GetVideoResult<MVideoImmutable> | ||
90 | export function maybeGetOrCreateAPVideo (options: GetVideoParamOther): GetVideoResult<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail> | ||
91 | export async function maybeGetOrCreateAPVideo (options: GetVideoParamAll | GetVideoParamImmutable | GetVideoParamOther) { | ||
92 | try { | ||
93 | const result = await getOrCreateAPVideo(options as any) | ||
90 | 94 | ||
91 | export { | 95 | return result |
92 | getOrCreateAPVideo | 96 | } catch (err) { |
97 | logger.debug('Cannot fetch remote video ' + options.videoObject + ': maybe not a video object?', { err }) | ||
98 | return { video: undefined, created: false } | ||
99 | } | ||
93 | } | 100 | } |
94 | 101 | ||
95 | // --------------------------------------------------------------------------- | 102 | // --------------------------------------------------------------------------- |
103 | // Private | ||
104 | // --------------------------------------------------------------------------- | ||
96 | 105 | ||
97 | async function scheduleRefresh (video: MVideoThumbnail, fetchType: VideoLoadByUrlType, syncParam: SyncParam) { | 106 | async function scheduleRefresh (video: MVideoThumbnail, fetchType: VideoLoadByUrlType, syncParam: SyncParam) { |
98 | if (!video.isOutdated()) return video | 107 | if (!video.isOutdated()) return video |