mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
accept Posts and Comments from a.gup.pe #31
This commit is contained in:
parent
85cc1595fd
commit
1ea3c925ea
3 changed files with 22 additions and 17 deletions
|
@ -654,13 +654,13 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
|
|||
|
||||
# Announce is new content and votes that happened on a remote server.
|
||||
if request_json['type'] == 'Announce':
|
||||
if isinstance(request_json['object'], str):
|
||||
if isinstance(request_json['object'], str): # Mastodon, PeerTube, A.gup.pe
|
||||
activity_log.activity_json = json.dumps(request_json)
|
||||
activity_log.exception_message = 'invalid json?'
|
||||
if 'actor' in request_json:
|
||||
community = find_actor_or_create(request_json['actor'], community_only=True, create_if_not_found=False)
|
||||
if community:
|
||||
resolve_remote_post(request_json['object'], community.id, request_json['actor'])
|
||||
post = resolve_remote_post(request_json['object'], community.id, request_json['actor'])
|
||||
elif request_json['object']['type'] == 'Create' or request_json['object']['type'] == 'Update':
|
||||
activity_log.activity_type = request_json['object']['type']
|
||||
if 'object' in request_json and 'object' in request_json['object']:
|
||||
|
@ -1176,7 +1176,7 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
|
|||
if activity_log.exception_message is not None and activity_log.result == 'processing':
|
||||
activity_log.result = 'failure'
|
||||
# Don't log successful json - save space
|
||||
if site.log_activitypub_json and activity_log.result == 'success':
|
||||
if site.log_activitypub_json and activity_log.result == 'success' and not current_app.debug:
|
||||
activity_log.activity_json = ''
|
||||
db.session.commit()
|
||||
|
||||
|
|
|
@ -1222,7 +1222,7 @@ def new_instance_profile_task(instance_id: int):
|
|||
InstanceRole.instance_id == instance.id,
|
||||
InstanceRole.role == 'admin').delete()
|
||||
db.session.commit()
|
||||
elif instance_data.status_code == 406: # Mastodon and PeerTube do this
|
||||
elif instance_data.status_code == 406 or instance_data.status_code == 404: # Mastodon and PeerTube do 406, a.gup.pe does 404
|
||||
instance.inbox = f"https://{instance.domain}/inbox"
|
||||
instance.updated_at = utcnow()
|
||||
db.session.commit()
|
||||
|
@ -2413,7 +2413,7 @@ def resolve_remote_post(uri: str, community_id: int, announce_actor=None) -> Uni
|
|||
if announce_actor:
|
||||
parsed_url = urlparse(announce_actor)
|
||||
announce_actor_domain = parsed_url.netloc
|
||||
if announce_actor_domain != uri_domain:
|
||||
if announce_actor_domain != 'a.gup.pe' and announce_actor_domain != uri_domain:
|
||||
return None
|
||||
actor_domain = None
|
||||
actor = None
|
||||
|
@ -2490,13 +2490,22 @@ def resolve_remote_post(uri: str, community_id: int, announce_actor=None) -> Uni
|
|||
'id': f"https://{uri_domain}/activities/create/gibberish(15)",
|
||||
'object': post_data
|
||||
}
|
||||
post = create_post(activity_log, community, request_json, user)
|
||||
if post:
|
||||
if 'published' in post_data:
|
||||
post.posted_at=post_data['published']
|
||||
post.last_active=post_data['published']
|
||||
db.session.commit()
|
||||
return post
|
||||
if 'inReplyTo' in request_json['object'] and request_json['object']['inReplyTo']:
|
||||
post_reply = create_post_reply(activity_log, community, request_json['object']['inReplyTo'], request_json, user)
|
||||
if post_reply:
|
||||
if 'published' in post_data:
|
||||
post_reply.posted_at = post_data['published']
|
||||
post_reply.post.last_active = post_data['published']
|
||||
db.session.commit()
|
||||
return post_reply
|
||||
else:
|
||||
post = create_post(activity_log, community, request_json, user)
|
||||
if post:
|
||||
if 'published' in post_data:
|
||||
post.posted_at=post_data['published']
|
||||
post.last_active=post_data['published']
|
||||
db.session.commit()
|
||||
return post
|
||||
|
||||
return None
|
||||
|
||||
|
|
|
@ -5,14 +5,11 @@ from random import randint
|
|||
from time import sleep
|
||||
|
||||
import flask
|
||||
import markdown2
|
||||
import requests
|
||||
from flask_caching import CachedResponse
|
||||
from sqlalchemy.sql.operators import or_, and_
|
||||
|
||||
from app import db, cache
|
||||
from app.activitypub.util import make_image_sizes_async, refresh_user_profile, find_actor_or_create, \
|
||||
refresh_community_profile_task, users_total, active_month, local_posts, local_communities, local_comments
|
||||
from app.activitypub.util import users_total, active_month, local_posts, local_communities
|
||||
from app.activitypub.signature import default_context
|
||||
from app.constants import SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER, POST_TYPE_IMAGE, POST_TYPE_LINK, \
|
||||
SUBSCRIPTION_OWNER, SUBSCRIPTION_MODERATOR, POST_TYPE_VIDEO, POST_TYPE_POLL
|
||||
|
@ -24,7 +21,6 @@ from flask_moment import moment
|
|||
from flask_login import current_user, login_required
|
||||
from flask_babel import _, get_locale
|
||||
from sqlalchemy import select, desc, text
|
||||
from sqlalchemy_searchable import search
|
||||
from app.utils import render_template, get_setting, gibberish, request_etag_matches, return_304, blocked_domains, \
|
||||
ap_datetime, ip_address, retrieve_block_list, shorten_string, markdown_to_text, user_filters_home, \
|
||||
joined_communities, moderating_communities, parse_page, theme_list, get_request, markdown_to_html, allowlist_html, \
|
||||
|
|
Loading…
Reference in a new issue