start supporting new jf2 style micropub endpoints
This commit is contained in:
parent
21a1351dde
commit
093ad551df
2 changed files with 22 additions and 8 deletions
|
@ -95,8 +95,6 @@ def tick():
|
|||
q.enqueue(update_feed, feed.id)
|
||||
|
||||
|
||||
|
||||
|
||||
def update_feed(feed_id, content=None,
|
||||
content_type=None, is_polling=True):
|
||||
|
||||
|
|
|
@ -306,6 +306,23 @@ def micropub_callback(resp):
|
|||
|
||||
@flask_login.login_required
|
||||
def update_micropub_syndicate_to():
|
||||
|
||||
def adapt_expanded(exp):
|
||||
"""Backcompat support for old-style "syndicate-to-expanded" properties,
|
||||
e.g.,
|
||||
{
|
||||
"id": "twitter::kylewmahan",
|
||||
"name": "@kylewmahan",
|
||||
"service": "Twitter"
|
||||
}
|
||||
"""
|
||||
if isinstance(exp, dict):
|
||||
return {
|
||||
'uid': exp.get('id'),
|
||||
'name': '{} on {}'.format(exp.get('name'), exp.get('service')),
|
||||
}
|
||||
return exp
|
||||
|
||||
endpt = flask_login.current_user.micropub_endpoint
|
||||
token = flask_login.current_user.access_token
|
||||
if not endpt or not token:
|
||||
|
@ -331,9 +348,10 @@ def update_micropub_syndicate_to():
|
|||
|
||||
if content_type == 'application/json':
|
||||
blob = resp.json()
|
||||
syndicate_tos = blob.get('syndicate-to-expanded')
|
||||
syndicate_tos = adapt_expanded(blob.get('syndicate-to-expanded'))
|
||||
if not syndicate_tos:
|
||||
syndicate_tos = blob.get('syndicate-to')
|
||||
|
||||
else: # try to parse query string
|
||||
syndicate_tos = pyquerystring.parse(resp.text).get('syndicate-to', [])
|
||||
if isinstance(syndicate_tos, list):
|
||||
|
@ -735,17 +753,15 @@ def font_awesome_class_for_service(service):
|
|||
@views.app_template_filter('syndication_target_id')
|
||||
def syndication_target_id(target):
|
||||
if isinstance(target, dict):
|
||||
return target.get('id')
|
||||
return target.get('uid') or target.get('id')
|
||||
return target
|
||||
|
||||
|
||||
@views.app_template_filter('render_syndication_target')
|
||||
def render_syndication_target(target):
|
||||
if isinstance(target, dict):
|
||||
service = target.get('service')
|
||||
name = target.get('name')
|
||||
return '<i class="{}"></i> {}'.format(
|
||||
font_awesome_class_for_service(service), name)
|
||||
full_name = target.get('name')
|
||||
return full_name
|
||||
|
||||
return '<img src="{}" alt="{}" /> {}'.format(
|
||||
favicon_for_url(target), target, prettify_url(target))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue