ActivityPub-federated video streaming platform using P2P directly in your web browser
Avoid federation error logs with likes on notes
Chocobozzz0cc1a698813e
diff --git a/server/server/lib/activitypub/process/process-announce.ts b/server/server/lib/activitypub/process/process-announce.tsindex ed178f73c7..b9598c8f9e 100644--- a/server/server/lib/activitypub/process/process-announce.ts+++ b/server/server/lib/activitypub/process/process-announce.ts@@ -1,14 +1,13 @@import { ActivityAnnounce } from '@peertube/peertube-models'import { getAPId } from '@server/lib/activitypub/activity.js'import { retryTransactionWrapper } from '../../../helpers/database-utils.js'-import { logger } from '../../../helpers/logger.js'import { sequelizeTypescript } from '../../../initializers/database.js'import { VideoShareModel } from '../../../models/video/video-share.js'import { APProcessorOptions } from '../../../types/activitypub-processor.model.js'-import { MActorSignature, MVideoAccountLightBlacklistAllFiles } from '../../../types/models/index.js'+import { MActorSignature } from '../../../types/models/index.js'import { Notifier } from '../../notifier/index.js'import { forwardVideoRelatedActivity } from '../send/shared/send-utils.js'-import { getOrCreateAPVideo } from '../videos/index.js'+import { maybeGetOrCreateAPVideo } from '../videos/index.js'async function processAnnounceActivity (options: APProcessorOptions<ActivityAnnounce>) {const { activity, byActor: actorAnnouncer } = options@@ -32,17 +31,8 @@ export {async function processVideoShare (actorAnnouncer: MActorSignature, activity: ActivityAnnounce, notify: boolean) {const objectUri = getAPId(activity.object)- let video: MVideoAccountLightBlacklistAllFiles- let videoCreated: boolean-- try {- const result = await getOrCreateAPVideo({ videoObject: objectUri })- video = result.video- videoCreated = result.created- } catch (err) {- logger.debug('Cannot process share of %s. Maybe this is not a video object, so just skipping.', objectUri, { err })- return- }+ const { video, created: videoCreated } = await maybeGetOrCreateAPVideo({ videoObject: objectUri })+ if (!video) returnawait sequelizeTypescript.transaction(async t => {// Add share entrydiff --git a/server/server/lib/activitypub/process/process-dislike.ts b/server/server/lib/activitypub/process/process-dislike.tsindex 8040cad93b..9182e6de45 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'import { AccountVideoRateModel } from '../../../models/account/account-video-rate.js'import { APProcessorOptions } from '../../../types/activitypub-processor.model.js'import { MActorSignature } from '../../../types/models/index.js'-import { federateVideoIfNeeded, getOrCreateAPVideo } from '../videos/index.js'+import { federateVideoIfNeeded, maybeGetOrCreateAPVideo } from '../videos/index.js'async function processDislikeActivity (options: APProcessorOptions<ActivityDislike>) {const { activity, byActor } = options@@ -26,10 +26,8 @@ async function processDislike (activity: ActivityDislike, byActor: MActorSignatuif (!byAccount) throw new Error('Cannot create dislike with the non account actor ' + byActor.url)- const { video: onlyVideo } = await getOrCreateAPVideo({ videoObject: dislikeObject, fetchType: 'only-video' })-- // We don't care about dislikes of remote videos- if (!onlyVideo.isOwned()) return+ const { video: onlyVideo } = await maybeGetOrCreateAPVideo({ videoObject: dislikeObject, fetchType: 'only-video' })+ if (!onlyVideo?.isOwned()) returnreturn sequelizeTypescript.transaction(async t => {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.tsindex 03637f9a70..ccdb37a026 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'import { AccountVideoRateModel } from '../../../models/account/account-video-rate.js'import { APProcessorOptions } from '../../../types/activitypub-processor.model.js'import { MActorSignature } from '../../../types/models/index.js'-import { federateVideoIfNeeded, getOrCreateAPVideo } from '../videos/index.js'+import { federateVideoIfNeeded, maybeGetOrCreateAPVideo } from '../videos/index.js'async function processLikeActivity (options: APProcessorOptions<ActivityLike>) {const { activity, byActor } = options@@ -28,10 +28,8 @@ async function processLikeVideo (byActor: MActorSignature, activity: ActivityLikconst byAccount = byActor.Accountif (!byAccount) throw new Error('Cannot create like with the non account actor ' + byActor.url)- const { video: onlyVideo } = await getOrCreateAPVideo({ videoObject: videoUrl, fetchType: 'only-video' })-- // We don't care about likes of remote videos- if (!onlyVideo.isOwned()) return+ const { video: onlyVideo } = await maybeGetOrCreateAPVideo({ videoObject: videoUrl, fetchType: 'only-video' })+ if (!onlyVideo?.isOwned()) returnreturn sequelizeTypescript.transaction(async t => {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.tsindex 20a167f7b2..635c4c3b82 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.jimport { MActorSignature } from '../../../types/models/index.js'import { fetchAPObjectIfNeeded } from '../activity.js'import { forwardVideoRelatedActivity } from '../send/shared/send-utils.js'-import { federateVideoIfNeeded, getOrCreateAPVideo } from '../videos/index.js'+import { federateVideoIfNeeded, getOrCreateAPVideo, maybeGetOrCreateAPVideo } from '../videos/index.js'async function processUndoActivity (options: APProcessorOptions<ActivityUndo<ActivityUndoObject>>) {const { activity, byActor } = options@@ -67,9 +67,8 @@ export {async function processUndoLike (byActor: MActorSignature, activity: ActivityUndo<ActivityLike>) {const likeActivity = activity.object- const { video: onlyVideo } = await getOrCreateAPVideo({ videoObject: likeActivity.object })- // We don't care about likes of remote videos- if (!onlyVideo.isOwned()) return+ const { video: onlyVideo } = await maybeGetOrCreateAPVideo({ videoObject: likeActivity.object })+ if (!onlyVideo?.isOwned()) returnreturn sequelizeTypescript.transaction(async t => {if (!byActor.Account) throw new Error('Unknown account ' + byActor.url)@@ -92,9 +91,8 @@ async function processUndoLike (byActor: MActorSignature, activity: ActivityUndoasync function processUndoDislike (byActor: MActorSignature, activity: ActivityUndo<ActivityDislike>) {const dislikeActivity = activity.object- const { video: onlyVideo } = await getOrCreateAPVideo({ videoObject: dislikeActivity.object })- // We don't care about likes of remote videos- if (!onlyVideo.isOwned()) return+ const { video: onlyVideo } = await maybeGetOrCreateAPVideo({ videoObject: dislikeActivity.object })+ if (!onlyVideo?.isOwned()) returnreturn sequelizeTypescript.transaction(async t => {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.tsindex 6d70a490f2..54efcc08fa 100644--- a/server/server/lib/activitypub/videos/get.ts+++ b/server/server/lib/activitypub/videos/get.ts@@ -35,11 +35,10 @@ type GetVideoParamOther = {allowRefresh?: boolean}-function getOrCreateAPVideo (options: GetVideoParamAll): GetVideoResult<MVideoAccountLightBlacklistAllFiles>-function getOrCreateAPVideo (options: GetVideoParamImmutable): GetVideoResult<MVideoImmutable>-function getOrCreateAPVideo (options: GetVideoParamOther): GetVideoResult<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail>--async function getOrCreateAPVideo (+export function getOrCreateAPVideo (options: GetVideoParamAll): GetVideoResult<MVideoAccountLightBlacklistAllFiles>+export function getOrCreateAPVideo (options: GetVideoParamImmutable): GetVideoResult<MVideoImmutable>+export function getOrCreateAPVideo (options: GetVideoParamOther): GetVideoResult<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail>+export async function getOrCreateAPVideo (options: GetVideoParamAll | GetVideoParamImmutable | GetVideoParamOther): GetVideoResult<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> {// Default params@@ -86,12 +85,22 @@ async function getOrCreateAPVideo (}}-// ---------------------------------------------------------------------------+export function maybeGetOrCreateAPVideo (options: GetVideoParamAll): GetVideoResult<MVideoAccountLightBlacklistAllFiles>+export function maybeGetOrCreateAPVideo (options: GetVideoParamImmutable): GetVideoResult<MVideoImmutable>+export function maybeGetOrCreateAPVideo (options: GetVideoParamOther): GetVideoResult<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail>+export async function maybeGetOrCreateAPVideo (options: GetVideoParamAll | GetVideoParamImmutable | GetVideoParamOther) {+ try {+ const result = await getOrCreateAPVideo(options as any)-export {- getOrCreateAPVideo+ return result+ } catch (err) {+ logger.debug('Cannot fetch remote video ' + options.videoObject + ': maybe not a video object?', { err })+ return { video: undefined, created: false }+ }}+// ---------------------------------------------------------------------------+// Private// ---------------------------------------------------------------------------async function scheduleRefresh (video: MVideoThumbnail, fetchType: VideoLoadByUrlType, syncParam: SyncParam) {