minor bugfixes via sentry

This commit is contained in:
rimu 2024-10-16 21:55:41 +13:00
parent ba2a97c4ad
commit 77172f1d9c
3 changed files with 39 additions and 28 deletions

View file

@ -319,7 +319,7 @@ def find_actor_or_create(actor: str, create_if_not_found=True, community_only=Fa
if actor_data.status_code == 200:
try:
actor_json = actor_data.json()
except JSONDecodeError as e:
except Exception as e:
actor_data.close()
return None
actor_data.close()
@ -480,7 +480,7 @@ def refresh_user_profile_task(user_id):
user.user_name = activity_json['preferredUsername'].strip()
if 'name' in activity_json:
user.title = activity_json['name'].strip()
user.title = activity_json['name'].strip() if activity_json['name'] else ''
if 'summary' in activity_json:
about_html = activity_json['summary']
if about_html is not None and not about_html.startswith('<'): # PeerTube
@ -682,7 +682,7 @@ def actor_json_to_model(activity_json, address, server):
if activity_json['type'] == 'Person' or activity_json['type'] == 'Service':
try:
user = User(user_name=activity_json['preferredUsername'].strip(),
title=activity_json['name'].strip() if 'name' in activity_json else None,
title=activity_json['name'].strip() if 'name' in activity_json and activity_json['name'] else None,
email=f"{address}@{server}",
matrix_user_id=activity_json['matrixUserId'] if 'matrixUserId' in activity_json else '',
indexable=activity_json['indexable'] if 'indexable' in activity_json else True,
@ -918,6 +918,7 @@ def post_json_to_model(activity_log, post_json, user, community) -> Post:
domain.post_count += 1
post.domain = domain
if post is not None:
if post_json['type'] == 'Video':
post.type = POST_TYPE_VIDEO
post.url = post_json['id']
@ -940,7 +941,6 @@ def post_json_to_model(activity_log, post_json, user, community) -> Post:
if hashtag:
post.tags.append(hashtag)
if post is not None:
if 'image' in post_json and post.image is None:
image = File(source_url=post_json['image']['url'])
db.session.add(image)

View file

@ -10,6 +10,7 @@ import flask
import httpx
from flask import json, current_app
from flask_babel import _
from requests import JSONDecodeError
from sqlalchemy import or_, desc, text
from sqlalchemy.orm import configure_mappers
@ -217,7 +218,12 @@ def register(app):
nodeinfo = get_request(f"https://{instance.domain}/.well-known/nodeinfo", headers=HEADERS)
if nodeinfo.status_code == 200:
try:
nodeinfo_json = nodeinfo.json()
except Exception as e:
nodeinfo_json = {}
finally:
nodeinfo.close()
for links in nodeinfo_json['links']:
if isinstance(links, dict) and 'rel' in links and (
links['rel'] == 'http://nodeinfo.diaspora.software/ns/schema/2.0' or
@ -240,7 +246,12 @@ def register(app):
try:
node = get_request(instance.nodeinfo_href, headers=HEADERS)
if node.status_code == 200:
try:
node_json = node.json()
except Exception as e:
node_json = {}
finally:
node.close()
if 'software' in node_json:
instance.software = node_json['software']['name'].lower()
instance.version = node_json['software']['version']

View file

@ -79,7 +79,7 @@ def instance_people(instance_domain):
if instance is None:
abort(404)
if current_user.is_admin():
if current_user.is_authenticated and current_user.is_admin():
people = User.query.filter_by(instance_id=instance.id, deleted=False, banned=False).order_by(desc(User.last_seen))
else:
people = User.query.filter_by(instance_id=instance.id, deleted=False, banned=False, searchable=True).order_by(desc(User.last_seen))