kopia lustrzana https://github.com/snarfed/bridgy-fed
webfinger: check domain home page too; preserve port in MagicKey domain
rodzic
63a9e47002
commit
c47e07ab94
26
webfinger.py
26
webfinger.py
|
@ -36,23 +36,29 @@ class UserHandler(handlers.XrdOrJrdHandler):
|
|||
return 'templates/webfinger_user'
|
||||
|
||||
def template_vars(self, domain, url=None):
|
||||
if not url:
|
||||
url = 'http://%s/' % domain
|
||||
assert domain
|
||||
|
||||
# TODO: unify with activitypub
|
||||
resp = common.requests_get(url)
|
||||
parsed = BeautifulSoup(resp.content, from_encoding=resp.encoding)
|
||||
mf2 = mf2py.parse(parsed, url=resp.url)
|
||||
# logging.debug('Parsed mf2 for %s: %s', resp.url, json.dumps(mf2, indent=2))
|
||||
# find representative h-card. try url, then url's home page, then domain
|
||||
urls = ['http://%s/' % domain]
|
||||
if url:
|
||||
urls = [url, urlparse.urljoin(url, '/')] + urls
|
||||
|
||||
hcard = mf2util.representative_hcard(mf2, resp.url)
|
||||
logging.info('Representative h-card: %s', json.dumps(hcard, indent=2))
|
||||
if not hcard:
|
||||
for candidate in urls:
|
||||
resp = common.requests_get(candidate)
|
||||
parsed = BeautifulSoup(resp.content, from_encoding=resp.encoding)
|
||||
mf2 = mf2py.parse(parsed, url=resp.url)
|
||||
# logging.debug('Parsed mf2 for %s: %s', resp.url, json.dumps(mf2, indent=2))
|
||||
hcard = mf2util.representative_hcard(mf2, resp.url)
|
||||
if hcard:
|
||||
logging.info('Representative h-card: %s', json.dumps(hcard, indent=2))
|
||||
break
|
||||
else:
|
||||
common.error(self, """\
|
||||
Couldn't find a <a href="http://microformats.org/wiki/representative-hcard-parsing">\
|
||||
representative h-card</a> on %s""" % resp.url)
|
||||
|
||||
acct = '%s@%s' % (common.USERNAME, domain)
|
||||
logging.info('Generating WebFinger data for %s', acct)
|
||||
key = models.MagicKey.get_or_create(domain)
|
||||
props = hcard.get('properties', {})
|
||||
urls = util.dedupe_urls(props.get('url', []) + [resp.url])
|
||||
|
|
|
@ -178,7 +178,7 @@ class WebmentionHandler(webapp2.RequestHandler):
|
|||
logging.info('Converted %s to Atom:\n%s', source_url, entry)
|
||||
|
||||
# sign reply and wrap in magic envelope
|
||||
domain = urlparse.urlparse(source_url).netloc.split(':')[0]
|
||||
domain = urlparse.urlparse(source_url).netloc
|
||||
key = models.MagicKey.get_or_create(domain)
|
||||
logging.info('Using key for %s: %s', domain, key)
|
||||
magic_envelope = magicsigs.magic_envelope(
|
||||
|
|
Ładowanie…
Reference in New Issue