Add support for Link object

This commit is contained in:
Thomas Sileo 2018-07-03 23:29:55 +02:00
parent 1ef476b9b9
commit d31e2f8d1d
2 changed files with 27 additions and 7 deletions

24
app.py
View file

@ -209,6 +209,14 @@ def domain(url):
return urlparse(url).netloc
@app.template_filter()
def get_url(u):
if isinstance(u, dict):
return u["href"]
else:
return u
@app.template_filter()
def get_actor(url):
if not url:
@ -674,6 +682,11 @@ def wellknown_nodeinfo():
)
# @app.route('/fake_feed')
# def fake_feed():
# return '<?xml version="1.0"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0"><id>https://lol3.tun.a4.io/fake_feed</id><author><id>https://lol3.tun.a4.io/fake</id></author><entry></entry></feed>'
@app.route("/.well-known/webfinger")
def wellknown_webfinger():
"""Enable WebFinger support, required for Mastodon interopability."""
@ -695,6 +708,13 @@ def wellknown_webfinger():
"rel": "http://ostatus.org/schema/1.0/subscribe",
"template": BASE_URL + "/authorize_follow?profile={uri}",
},
# {"rel": "magic-public-key", "href": KEY.to_magic_key()},
# {"rel": "salmon", "href": BASE_URL + "/salmon"},
# {
# "rel": "http://schemas.google.com/g/2010#updates-from",
# "type": "application/atom+xml",
# "href": f"{BASE_URL}/fake_feed",
# },
],
}
@ -1258,7 +1278,7 @@ def api_new_note():
inReplyTo=reply.id if reply else None,
)
if 'file' in request.files:
if "file" in request.files:
file = request.files["file"]
rfilename = secure_filename(file.filename)
prefix = hashlib.sha256(os.urandom(32)).hexdigest()[:6]
@ -1270,7 +1290,7 @@ def api_new_note():
if filename.lower().endswith(".jpg") or filename.lower().endswith(".jpeg"):
piexif.remove(os.path.join("static", "media", filename))
raw_note['attachment'] = [
raw_note["attachment"] = [
{
"mediaType": mtype,
"name": rfilename,

View file

@ -1,5 +1,5 @@
{% macro display_actor_inline(follower, size=50) -%}
<a class="actor-box" href="{{follower.get_url()}}" style="clear:both;">
<a class="actor-box" href="{{follower.url | get_url }}" style="clear:both;">
<span style="float:left;padding-right:15px;">
{% if not follower.icon %}
<img class="actor-icon" src="/static/nopic.png" style="width:{{ size }}px">
@ -8,7 +8,7 @@
</span>
<div class="actor-inline">
<div style="font-weight:bold">{{ follower.name or follower.preferredUsername }}</div>
<small>@{{ follower.preferredUsername }}@{{ follower.get_url() | domain }}</small>
<small>@{{ follower.preferredUsername }}@{{ follower.url | get_url | domain }}</small>
</div>
</a>
{%- endmacro %}
@ -20,14 +20,14 @@
<div class="note h-entry" id="activity-{{ obj.id | permalink_id }}">
<div class="h-card p-author">
<a class="u-url u-uid no-hover" href="{{ actor.get_url() }}"><img class="u-photo" src="{% if not actor.icon %}/static/nopic.png{% else %}{{ actor.icon.url }}{% endif %}">
<a class="u-url u-uid no-hover" href="{{ actor.url | get_url }}"><img class="u-photo" src="{% if not actor.icon %}/static/nopic.png{% else %}{{ actor.icon.url }}{% endif %}">
</a>
<data class="p-name" value="{{ actor.name or actor.preferredUsername }}"></data>
</div>
<div class="note-wrapper">
<a href="{{ actor.get_url() }}" style="margin:0;text-decoration:none;" class="no-hover"><strong>{{ actor.name or actor.preferredUsername }}</strong>
<span class="l">@{% if not no_color and obj.id | is_from_outbox %}<span class="pcolor">{{ actor.preferredUsername }}</span>{% else %}{{ actor.preferredUsername }}{% endif %}@{% if not no_color and obj.id | is_from_outbox %}<span class="pcolor">{{ actor.get_url() | domain }}</span>{% else %}{{ actor.get_url() | domain }}{% endif %}</span></a>
<a href="{{ actor.url | get_url }}" style="margin:0;text-decoration:none;" class="no-hover"><strong>{{ actor.name or actor.preferredUsername }}</strong>
<span class="l">@{% if not no_color and obj.id | is_from_outbox %}<span class="pcolor">{{ actor.preferredUsername }}</span>{% else %}{{ actor.preferredUsername }}{% endif %}@{% if not no_color and obj.id | is_from_outbox %}<span class="pcolor">{{ actor.url | get_url | domain }}</span>{% else %}{{ actor.url | get_url | domain }}{% endif %}</span></a>
{% if not perma %}
<span style="float:right">