aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-09-01 09:58:13 +0200
committerChocobozzz <me@florianbigard.com>2023-09-01 09:58:13 +0200
commit0cc1a698813e50d86b5a2a8400e1e8a9b82461da (patch)
treee2661e12e76f6791e8d4314d6a1c029d8fd97816
parentc4799cd1b919a0e7081872b995fe1637c174cab8 (diff)
downloadPeerTube-0cc1a698813e50d86b5a2a8400e1e8a9b82461da.tar.gz
PeerTube-0cc1a698813e50d86b5a2a8400e1e8a9b82461da.tar.zst
PeerTube-0cc1a698813e50d86b5a2a8400e1e8a9b82461da.zip
Avoid federation error logs with likes on notes
-rw-r--r--server/server/lib/activitypub/process/process-announce.ts18
-rw-r--r--server/server/lib/activitypub/process/process-dislike.ts8
-rw-r--r--server/server/lib/activitypub/process/process-like.ts8
-rw-r--r--server/server/lib/activitypub/process/process-undo.ts12
-rw-r--r--server/server/lib/activitypub/videos/get.ts25
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 @@
1import { ActivityAnnounce } from '@peertube/peertube-models' 1import { ActivityAnnounce } from '@peertube/peertube-models'
2import { getAPId } from '@server/lib/activitypub/activity.js' 2import { getAPId } from '@server/lib/activitypub/activity.js'
3import { retryTransactionWrapper } from '../../../helpers/database-utils.js' 3import { retryTransactionWrapper } from '../../../helpers/database-utils.js'
4import { logger } from '../../../helpers/logger.js'
5import { sequelizeTypescript } from '../../../initializers/database.js' 4import { sequelizeTypescript } from '../../../initializers/database.js'
6import { VideoShareModel } from '../../../models/video/video-share.js' 5import { VideoShareModel } from '../../../models/video/video-share.js'
7import { APProcessorOptions } from '../../../types/activitypub-processor.model.js' 6import { APProcessorOptions } from '../../../types/activitypub-processor.model.js'
8import { MActorSignature, MVideoAccountLightBlacklistAllFiles } from '../../../types/models/index.js' 7import { MActorSignature } from '../../../types/models/index.js'
9import { Notifier } from '../../notifier/index.js' 8import { Notifier } from '../../notifier/index.js'
10import { forwardVideoRelatedActivity } from '../send/shared/send-utils.js' 9import { forwardVideoRelatedActivity } from '../send/shared/send-utils.js'
11import { getOrCreateAPVideo } from '../videos/index.js' 10import { maybeGetOrCreateAPVideo } from '../videos/index.js'
12 11
13async function processAnnounceActivity (options: APProcessorOptions<ActivityAnnounce>) { 12async function processAnnounceActivity (options: APProcessorOptions<ActivityAnnounce>) {
14 const { activity, byActor: actorAnnouncer } = options 13 const { activity, byActor: actorAnnouncer } = options
@@ -32,17 +31,8 @@ export {
32async function processVideoShare (actorAnnouncer: MActorSignature, activity: ActivityAnnounce, notify: boolean) { 31async 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'
5import { AccountVideoRateModel } from '../../../models/account/account-video-rate.js' 5import { AccountVideoRateModel } from '../../../models/account/account-video-rate.js'
6import { APProcessorOptions } from '../../../types/activitypub-processor.model.js' 6import { APProcessorOptions } from '../../../types/activitypub-processor.model.js'
7import { MActorSignature } from '../../../types/models/index.js' 7import { MActorSignature } from '../../../types/models/index.js'
8import { federateVideoIfNeeded, getOrCreateAPVideo } from '../videos/index.js' 8import { federateVideoIfNeeded, maybeGetOrCreateAPVideo } from '../videos/index.js'
9 9
10async function processDislikeActivity (options: APProcessorOptions<ActivityDislike>) { 10async 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'
6import { AccountVideoRateModel } from '../../../models/account/account-video-rate.js' 6import { AccountVideoRateModel } from '../../../models/account/account-video-rate.js'
7import { APProcessorOptions } from '../../../types/activitypub-processor.model.js' 7import { APProcessorOptions } from '../../../types/activitypub-processor.model.js'
8import { MActorSignature } from '../../../types/models/index.js' 8import { MActorSignature } from '../../../types/models/index.js'
9import { federateVideoIfNeeded, getOrCreateAPVideo } from '../videos/index.js' 9import { federateVideoIfNeeded, maybeGetOrCreateAPVideo } from '../videos/index.js'
10 10
11async function processLikeActivity (options: APProcessorOptions<ActivityLike>) { 11async 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
21import { MActorSignature } from '../../../types/models/index.js' 21import { MActorSignature } from '../../../types/models/index.js'
22import { fetchAPObjectIfNeeded } from '../activity.js' 22import { fetchAPObjectIfNeeded } from '../activity.js'
23import { forwardVideoRelatedActivity } from '../send/shared/send-utils.js' 23import { forwardVideoRelatedActivity } from '../send/shared/send-utils.js'
24import { federateVideoIfNeeded, getOrCreateAPVideo } from '../videos/index.js' 24import { federateVideoIfNeeded, getOrCreateAPVideo, maybeGetOrCreateAPVideo } from '../videos/index.js'
25 25
26async function processUndoActivity (options: APProcessorOptions<ActivityUndo<ActivityUndoObject>>) { 26async function processUndoActivity (options: APProcessorOptions<ActivityUndo<ActivityUndoObject>>) {
27 const { activity, byActor } = options 27 const { activity, byActor } = options
@@ -67,9 +67,8 @@ export {
67async function processUndoLike (byActor: MActorSignature, activity: ActivityUndo<ActivityLike>) { 67async 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
92async function processUndoDislike (byActor: MActorSignature, activity: ActivityUndo<ActivityDislike>) { 91async 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
38function getOrCreateAPVideo (options: GetVideoParamAll): GetVideoResult<MVideoAccountLightBlacklistAllFiles> 38export function getOrCreateAPVideo (options: GetVideoParamAll): GetVideoResult<MVideoAccountLightBlacklistAllFiles>
39function getOrCreateAPVideo (options: GetVideoParamImmutable): GetVideoResult<MVideoImmutable> 39export function getOrCreateAPVideo (options: GetVideoParamImmutable): GetVideoResult<MVideoImmutable>
40function getOrCreateAPVideo (options: GetVideoParamOther): GetVideoResult<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail> 40export function getOrCreateAPVideo (options: GetVideoParamOther): GetVideoResult<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail>
41 41export async function getOrCreateAPVideo (
42async 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// --------------------------------------------------------------------------- 88export function maybeGetOrCreateAPVideo (options: GetVideoParamAll): GetVideoResult<MVideoAccountLightBlacklistAllFiles>
89export function maybeGetOrCreateAPVideo (options: GetVideoParamImmutable): GetVideoResult<MVideoImmutable>
90export function maybeGetOrCreateAPVideo (options: GetVideoParamOther): GetVideoResult<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail>
91export async function maybeGetOrCreateAPVideo (options: GetVideoParamAll | GetVideoParamImmutable | GetVideoParamOther) {
92 try {
93 const result = await getOrCreateAPVideo(options as any)
90 94
91export { 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
97async function scheduleRefresh (video: MVideoThumbnail, fetchType: VideoLoadByUrlType, syncParam: SyncParam) { 106async function scheduleRefresh (video: MVideoThumbnail, fetchType: VideoLoadByUrlType, syncParam: SyncParam) {
98 if (!video.isOutdated()) return video 107 if (!video.isOutdated()) return video