Add instance actor

This commit is contained in:
freamon 2024-05-04 21:26:39 +01:00
parent c82581462d
commit cfef490143
2 changed files with 49 additions and 0 deletions

View file

@ -51,6 +51,28 @@ def webfinger():
else:
return 'Webfinger regex failed to match'
# special case: instance actor
if actor == current_app.config['SERVER_NAME']:
webfinger_data = {
"subject": f"acct:{actor}@{current_app.config['SERVER_NAME']}",
"aliases": [f"https://{current_app.config['SERVER_NAME']}/actor"],
"links": [
{
"rel": "http://webfinger.net/rel/profile-page",
"type": "text/html",
"href": f"https://{current_app.config['SERVER_NAME']}/about"
},
{
"rel": "self",
"type": "application/activity+json",
"href": f"https://{current_app.config['SERVER_NAME']}/actor",
}
]
}
resp = jsonify(webfinger_data)
resp.headers.add_header('Access-Control-Allow-Origin', '*')
return resp
seperator = 'u'
type = 'Person'
user = User.query.filter_by(user_name=actor.strip(), deleted=False, banned=False, ap_id=None).first()

View file

@ -415,3 +415,30 @@ def activitypub_application():
resp = jsonify(application_data)
resp.content_type = 'application/activity+json'
return resp
# instance actor (literally uses the word 'actor' without the /u/)
# required for interacting with instances using 'secure mode' (aka authorized fetch)
@bp.route('/actor', methods=['GET'])
def instance_actor():
application_data = {
'@context': default_context(),
'type': 'Application',
'id': f"https://{current_app.config['SERVER_NAME']}/actor",
'preferredUsername': f"{current_app.config['SERVER_NAME']}",
'url': f"https://{current_app.config['SERVER_NAME']}/about",
'manuallyApprovesFollowers': True,
'inbox': f"https://{current_app.config['SERVER_NAME']}/actor/inbox",
'outbox': f"https://{current_app.config['SERVER_NAME']}/actor/outbox",
'publicKey': {
'id': f"https://{current_app.config['SERVER_NAME']}/actor#main-key",
'owner': f"https://{current_app.config['SERVER_NAME']}/actor",
'publicKeyPem': g.site.public_key
},
'endpoints': {
'sharedInbox': f"https://{current_app.config['SERVER_NAME']}/site_inbox",
}
}
resp = jsonify(application_data)
resp.content_type = 'application/activity+json'
return resp