kopia lustrzana https://github.com/snarfed/bridgy-fed
bring back HOST_URL override to fed.brid.gy, for URLs emitted into AP
rodzic
2082dd7a85
commit
ee7b324525
|
@ -6,11 +6,12 @@ import logging
|
|||
from google.cloud import ndb
|
||||
from granary import as2, microformats2
|
||||
import mf2util
|
||||
from oauth_dropins.webutil import appengine_info, util
|
||||
from oauth_dropins.webutil import util
|
||||
from oauth_dropins.webutil.handlers import cache_response
|
||||
from oauth_dropins.webutil.util import json_dumps, json_loads
|
||||
import webapp2
|
||||
|
||||
from appengine_config import HOST, HOST_URL
|
||||
import common
|
||||
from models import Follower, MagicKey
|
||||
from httpsig.requests_auth import HTTPSignatureAuth
|
||||
|
@ -84,10 +85,10 @@ Couldn't find a representative h-card (http://microformats.org/wiki/representati
|
|||
obj = common.postprocess_as2(as2.from_as1(microformats2.json_to_object(hcard)),
|
||||
key=key)
|
||||
obj.update({
|
||||
'inbox': '%s/%s/inbox' % (appengine_info.HOST_URL, domain),
|
||||
'outbox': '%s/%s/outbox' % (appengine_info.HOST_URL, domain),
|
||||
'following': '%s/%s/following' % (appengine_info.HOST_URL, domain),
|
||||
'followers': '%s/%s/followers' % (appengine_info.HOST_URL, domain),
|
||||
'inbox': '%s/%s/inbox' % (HOST_URL, domain),
|
||||
'outbox': '%s/%s/outbox' % (HOST_URL, domain),
|
||||
'following': '%s/%s/following' % (HOST_URL, domain),
|
||||
'followers': '%s/%s/followers' % (HOST_URL, domain),
|
||||
})
|
||||
logging.info('Returning: %s', json_dumps(obj, indent=2))
|
||||
|
||||
|
@ -172,7 +173,7 @@ class InboxHandler(webapp2.RequestHandler):
|
|||
# send AP Accept
|
||||
accept = {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': util.tag_uri(appengine_info.HOST, 'accept/%s/%s' % (
|
||||
'id': util.tag_uri(HOST, 'accept/%s/%s' % (
|
||||
(user_domain, follow.get('id')))),
|
||||
'type': 'Accept',
|
||||
'actor': followee,
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
import datetime
|
||||
import urllib.parse
|
||||
|
||||
from oauth_dropins.webutil import appengine_info
|
||||
from oauth_dropins.webutil.handlers import cache_response
|
||||
import requests
|
||||
import webapp2
|
||||
|
||||
from appengine_config import HOST, HOST_URL
|
||||
import common
|
||||
|
||||
LINK_HEADER = '<%s>; rel="webmention"'
|
||||
|
@ -35,7 +35,7 @@ class AddWebmentionHandler(webapp2.RequestHandler):
|
|||
self.response.write(resp.content)
|
||||
|
||||
endpoint = LINK_HEADER % (str(self.request.get('endpoint')) or
|
||||
appengine_info.HOST_URL + '/webmention')
|
||||
HOST_URL + '/webmention')
|
||||
self.response.headers.clear()
|
||||
self.response.headers.update(resp.headers)
|
||||
self.response.headers.add('Link', endpoint)
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
"""Bridgy App Engine config.
|
||||
"""
|
||||
# import os
|
||||
import os
|
||||
|
||||
# if os.environ.get('SERVER_SOFTWARE', '').startswith('Google App Engine/'):
|
||||
# HOST = 'fed.brid.gy'
|
||||
# HOST_URL = '%s://%s' % (SCHEME, HOST)
|
||||
from oauth_dropins.webutil.appengine_info import HOST, HOST_URL
|
||||
|
||||
if os.environ.get('SERVER_SOFTWARE', '').startswith('Google App Engine/'):
|
||||
HOST = 'fed.brid.gy'
|
||||
HOST_URL = '%s://%s' % (SCHEME, HOST)
|
||||
|
||||
# suppresses these INFO logs:
|
||||
# Sandbox prevented access to file "/usr/local/Caskroom/google-cloud-sdk"
|
||||
|
|
10
common.py
10
common.py
|
@ -7,12 +7,12 @@ import re
|
|||
import urllib.parse
|
||||
|
||||
from granary import as2
|
||||
from oauth_dropins.webutil import appengine_info
|
||||
from oauth_dropins.webutil import handlers, util
|
||||
import requests
|
||||
from webmentiontools import send
|
||||
from webob import exc
|
||||
|
||||
from appengine_config import HOST, HOST_URL
|
||||
import common
|
||||
from models import Response
|
||||
|
||||
|
@ -22,7 +22,7 @@ HEADERS = {
|
|||
'User-Agent': 'Bridgy Fed (https://fed.brid.gy/)',
|
||||
}
|
||||
# see redirect_wrap() and redirect_unwrap()
|
||||
REDIRECT_PREFIX = urllib.parse.urljoin(appengine_info.HOST_URL, '/r/')
|
||||
REDIRECT_PREFIX = urllib.parse.urljoin(HOST_URL, '/r/')
|
||||
XML_UTF8 = "<?xml version='1.0' encoding='UTF-8'?>\n"
|
||||
# USERNAME = 'me'
|
||||
# USERNAME_EMOJI = '🌎' # globe
|
||||
|
@ -181,7 +181,7 @@ def send_webmentions(handler, activity_wrapped, proxy=None, **response_props):
|
|||
for tag in tags:
|
||||
if tag.get('objectType') == 'mention':
|
||||
url = tag.get('url')
|
||||
if url and url.startswith(appengine_info.HOST_URL):
|
||||
if url and url.startswith(HOST_URL):
|
||||
targets.append(redirect_unwrap(url))
|
||||
|
||||
if verb in ('follow', 'like', 'share'):
|
||||
|
@ -338,7 +338,7 @@ def postprocess_as2_actor(actor):
|
|||
if url:
|
||||
domain = urllib.parse.urlparse(url).netloc
|
||||
actor.setdefault('preferredUsername', domain)
|
||||
actor['id'] = '%s/%s' % (appengine_info.HOST_URL, domain)
|
||||
actor['id'] = '%s/%s' % (HOST_URL, domain)
|
||||
actor['url'] = redirect_wrap(url)
|
||||
|
||||
# required by pixelfed. https://github.com/snarfed/bridgy-fed/issues/39
|
||||
|
@ -377,7 +377,7 @@ def redirect_unwrap(val):
|
|||
elif isinstance(val, str):
|
||||
if val.startswith(REDIRECT_PREFIX):
|
||||
return val[len(REDIRECT_PREFIX):]
|
||||
elif val.startswith(appengine_info.HOST_URL):
|
||||
elif val.startswith(HOST_URL):
|
||||
return util.follow_redirects(
|
||||
util.domain_from_link(urllib.parse.urlparse(val).path.strip('/'))).url
|
||||
|
||||
|
|
|
@ -8,9 +8,10 @@ import urllib.parse
|
|||
from Crypto.PublicKey import RSA
|
||||
from django_salmon import magicsigs
|
||||
from google.cloud import ndb
|
||||
from oauth_dropins.webutil import appengine_info
|
||||
from oauth_dropins.webutil.models import StringIdModel
|
||||
|
||||
from appengine_config import HOST, HOST_URL
|
||||
|
||||
|
||||
class MagicKey(StringIdModel):
|
||||
"""Stores a user's public/private key pair used for Magic Signatures.
|
||||
|
@ -108,7 +109,7 @@ class Response(StringIdModel):
|
|||
"""Returns the Bridgy Fed proxy URL to render this response as HTML."""
|
||||
if self.source_mf2 or self.source_as2 or self.source_atom:
|
||||
source, target = self.key.id().split(' ')
|
||||
return '%s/render?%s' % (appengine_info.HOST_URL, urllib.parse.urlencode({
|
||||
return '%s/render?%s' % (HOST_URL, urllib.parse.urlencode({
|
||||
'source': source,
|
||||
'target': target,
|
||||
}))
|
||||
|
|
|
@ -16,10 +16,11 @@ import urllib.parse
|
|||
import urllib.parse
|
||||
|
||||
import mf2util
|
||||
from oauth_dropins.webutil import appengine_info, handlers, util
|
||||
from oauth_dropins.webutil import handlers, util
|
||||
from oauth_dropins.webutil.util import json_dumps
|
||||
import webapp2
|
||||
|
||||
from appengine_config import HOST, HOST_URL
|
||||
import common
|
||||
import models
|
||||
|
||||
|
@ -123,11 +124,11 @@ Couldn't find a representative h-card (http://microformats.org/wiki/representati
|
|||
# use HOST_URL instead of e.g. request.host_url because it
|
||||
# sometimes lost port, e.g. http://localhost:8080 would become
|
||||
# just http://localhost. no clue how or why.
|
||||
'href': '%s/%s' % (appengine_info.HOST_URL, domain),
|
||||
'href': '%s/%s' % (HOST_URL, domain),
|
||||
}, {
|
||||
'rel': 'inbox',
|
||||
'type': common.CONTENT_TYPE_AS2,
|
||||
'href': '%s/%s/inbox' % (appengine_info.HOST_URL, domain),
|
||||
'href': '%s/%s/inbox' % (HOST_URL, domain),
|
||||
},
|
||||
|
||||
# OStatus
|
||||
|
@ -143,7 +144,7 @@ Couldn't find a representative h-card (http://microformats.org/wiki/representati
|
|||
'href': key.href(),
|
||||
}, {
|
||||
'rel': 'salmon',
|
||||
'href': '%s/%s/salmon' % (appengine_info.HOST_URL, domain),
|
||||
'href': '%s/%s/salmon' % (HOST_URL, domain),
|
||||
}]
|
||||
})
|
||||
logging.info('Returning WebFinger data: %s', json_dumps(data, indent=2))
|
||||
|
|
|
@ -36,7 +36,7 @@ class WebmentionHandler(webapp2.RequestHandler):
|
|||
target_resp = None # requests.Response
|
||||
|
||||
def post(self):
|
||||
logging.info('(Params: %s )', self.request.params.items())
|
||||
logging.info('Params: %s', list(self.request.params.items()))
|
||||
|
||||
# fetch source page
|
||||
source = util.get_required_param(self, 'source')
|
||||
|
|
Ładowanie…
Reference in New Issue