Avoid federation error logs with likes on notes

pull/5975/head
Chocobozzz 2023-09-01 09:58:13 +02:00
parent c4799cd1b9
commit 0cc1a69881
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 32 additions and 39 deletions

View File

@ -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) return
await sequelizeTypescript.transaction(async t => {
// Add share entry

View File

@ -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: MActorSignatu
if (!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()) return
return sequelizeTypescript.transaction(async t => {
const video = await VideoModel.loadFull(onlyVideo.id, t)

View File

@ -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: ActivityLik
const byAccount = byActor.Account
if (!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()) return
return sequelizeTypescript.transaction(async t => {
const video = await VideoModel.loadFull(onlyVideo.id, t)

View File

@ -21,7 +21,7 @@ import { APProcessorOptions } from '../../../types/activitypub-processor.model.j
import { 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()) return
return sequelizeTypescript.transaction(async t => {
if (!byActor.Account) throw new Error('Unknown account ' + byActor.url)
@ -92,9 +91,8 @@ async function processUndoLike (byActor: MActorSignature, activity: ActivityUndo
async 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()) return
return sequelizeTypescript.transaction(async t => {
if (!byActor.Account) throw new Error('Unknown account ' + byActor.url)

View File

@ -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) {