From 74d249bc1346c7cfaac7ee49bebbebcf2a01f82a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 26 Feb 2021 16:26:27 +0100 Subject: Add ability to cleanup remote AP interactions --- .../custom-validators/activitypub/activity.ts | 26 ++++++++++------------ .../helpers/custom-validators/activitypub/rate.ts | 13 +++++++---- .../helpers/custom-validators/activitypub/share.ts | 11 +++++++++ 3 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 server/helpers/custom-validators/activitypub/share.ts (limited to 'server/helpers/custom-validators/activitypub') diff --git a/server/helpers/custom-validators/activitypub/activity.ts b/server/helpers/custom-validators/activitypub/activity.ts index 8b8c0685f..da79b2782 100644 --- a/server/helpers/custom-validators/activitypub/activity.ts +++ b/server/helpers/custom-validators/activitypub/activity.ts @@ -1,15 +1,16 @@ import validator from 'validator' import { Activity, ActivityType } from '../../../../shared/models/activitypub' +import { exists } from '../misc' import { sanitizeAndCheckActorObject } from './actor' +import { isCacheFileObjectValid } from './cache-file' +import { isFlagActivityValid } from './flag' import { isActivityPubUrlValid, isBaseActivityValid, isObjectValid } from './misc' -import { isDislikeActivityValid } from './rate' +import { isPlaylistObjectValid } from './playlist' +import { isDislikeActivityValid, isLikeActivityValid } from './rate' +import { isShareActivityValid } from './share' import { sanitizeAndCheckVideoCommentObject } from './video-comments' import { sanitizeAndCheckVideoTorrentObject } from './videos' import { isViewActivityValid } from './view' -import { exists } from '../misc' -import { isCacheFileObjectValid } from './cache-file' -import { isFlagActivityValid } from './flag' -import { isPlaylistObjectValid } from './playlist' function isRootActivityValid (activity: any) { return isCollection(activity) || isActivity(activity) @@ -70,8 +71,11 @@ function checkFlagActivity (activity: any) { } function checkDislikeActivity (activity: any) { - return isBaseActivityValid(activity, 'Dislike') && - isDislikeActivityValid(activity) + return isDislikeActivityValid(activity) +} + +function checkLikeActivity (activity: any) { + return isLikeActivityValid(activity) } function checkCreateActivity (activity: any) { @@ -118,8 +122,7 @@ function checkRejectActivity (activity: any) { } function checkAnnounceActivity (activity: any) { - return isBaseActivityValid(activity, 'Announce') && - isObjectValid(activity.object) + return isShareActivityValid(activity) } function checkUndoActivity (activity: any) { @@ -132,8 +135,3 @@ function checkUndoActivity (activity: any) { checkCreateActivity(activity.object) ) } - -function checkLikeActivity (activity: any) { - return isBaseActivityValid(activity, 'Like') && - isObjectValid(activity.object) -} diff --git a/server/helpers/custom-validators/activitypub/rate.ts b/server/helpers/custom-validators/activitypub/rate.ts index ba68e8074..aafdda443 100644 --- a/server/helpers/custom-validators/activitypub/rate.ts +++ b/server/helpers/custom-validators/activitypub/rate.ts @@ -1,13 +1,18 @@ -import { isActivityPubUrlValid, isObjectValid } from './misc' +import { isBaseActivityValid, isObjectValid } from './misc' + +function isLikeActivityValid (activity: any) { + return isBaseActivityValid(activity, 'Like') && + isObjectValid(activity.object) +} function isDislikeActivityValid (activity: any) { - return activity.type === 'Dislike' && - isActivityPubUrlValid(activity.actor) && + return isBaseActivityValid(activity, 'Dislike') && isObjectValid(activity.object) } // --------------------------------------------------------------------------- export { - isDislikeActivityValid + isDislikeActivityValid, + isLikeActivityValid } diff --git a/server/helpers/custom-validators/activitypub/share.ts b/server/helpers/custom-validators/activitypub/share.ts new file mode 100644 index 000000000..fb5e4c05e --- /dev/null +++ b/server/helpers/custom-validators/activitypub/share.ts @@ -0,0 +1,11 @@ +import { isBaseActivityValid, isObjectValid } from './misc' + +function isShareActivityValid (activity: any) { + return isBaseActivityValid(activity, 'Announce') && + isObjectValid(activity.object) +} +// --------------------------------------------------------------------------- + +export { + isShareActivityValid +} -- cgit v1.2.3