From fe7791bf4df7b77656386fcc50b7a2308e80dd37 Mon Sep 17 00:00:00 2001 From: freamon Date: Mon, 18 Nov 2024 15:56:47 +0000 Subject: [PATCH] apf part 01: add log_incoming_ap function --- app/activitypub/routes.py | 2 +- app/activitypub/util.py | 13 +++++++++++++ app/constants.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/app/activitypub/routes.py b/app/activitypub/routes.py index b82cdf27..a5f91568 100644 --- a/app/activitypub/routes.py +++ b/app/activitypub/routes.py @@ -25,7 +25,7 @@ from app.activitypub.util import public_key, users_total, active_half_year, acti update_post_from_activity, undo_vote, undo_downvote, post_to_page, get_redis_connection, find_reported_object, \ process_report, ensure_domains_match, can_edit, can_delete, remove_data_from_banned_user, resolve_remote_post, \ inform_followers_of_post_update, comment_model_to_json, restore_post_or_comment, ban_local_user, unban_local_user, \ - lock_post + lock_post, log_incoming_ap from app.utils import gibberish, get_setting, render_template, \ community_membership, ap_datetime, ip_address, can_downvote, \ can_upvote, can_create_post, awaken_dormant_instance, shorten_string, can_create_post_reply, sha256_digest, \ diff --git a/app/activitypub/util.py b/app/activitypub/util.py index f0811f7a..e4e92f1f 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -2565,3 +2565,16 @@ def inform_followers_of_post_update_task(post_id: int, sending_instance_id: int) post_request(i.inbox, update_json, post.author.private_key, post.author.public_url() + '#main-key') except Exception: pass + + +def log_incoming_ap(id, aplog_type, aplog_result, request_json, message=None): + aplog_in = APLOG_IN + + if aplog_in and aplog_type[0] and aplog_result[0]: + activity_log = ActivityPubLog(direction='in', activity_id=id, activity_type=aplog_type[1], result=aplog_result[1]) + if message: + activity_log.exception_message = message + if request_json: + activity_log.activity_json = json.dumps(request_json) + db.session.add(activity_log) + db.session.commit() diff --git a/app/constants.py b/app/constants.py index e6897458..b53aa12a 100644 --- a/app/constants.py +++ b/app/constants.py @@ -36,3 +36,37 @@ ROLE_STAFF = 3 ROLE_ADMIN = 4 MICROBLOG_APPS = ["mastodon", "misskey", "akkoma", "iceshrimp", "pleroma"] + +APLOG_IN = True + +APLOG_MONITOR = (True, 'Debug this') + +APLOG_SUCCESS = (True, 'success') +APLOG_FAILURE = (True, 'failure') +APLOG_IGNORED = (True, 'ignored') +APLOG_PROCESSING = (True, 'processing') + +APLOG_NOTYPE = (True, 'Unknown') +APLOG_DUPLICATE = (True, 'Duplicate') +APLOG_FOLLOW = (True, 'Follow') +APLOG_ACCEPT = (True, 'Accept') +APLOG_DELETE = (True, 'Delete') +APLOG_CHATMESSAGE = (True, 'Create ChatMessage') +APLOG_CREATE = (True, 'Create') +APLOG_UPDATE = (True, 'Update') +APLOG_LIKE = (True, 'Like') +APLOG_DISLIKE = (True, 'Dislike') +APLOG_REPORT = (True, 'Report') +APLOG_USERBAN = (True, 'User Ban') +APLOG_LOCK = (True, 'Post Lock') + +APLOG_UNDO_FOLLOW = (True, 'Undo Follow') +APLOG_UNDO_DELETE = (True, 'Undo Delete') +APLOG_UNDO_VOTE = (True, 'Undo Vote') +APLOG_UNDO_USERBAN = (True, 'Undo User Ban') + +APLOG_ADD = (True, 'Add Mod/Sticky') +APLOG_REMOVE = (True, 'Remove Mod/Sticky') + +APLOG_ANNOUNCE = (True, 'Announce') +APLOG_PT_VIEW = (True, 'PeerTube View')