Use onion/i2p address for person qr code if it's available

main
Bob Mottram 2022-03-22 10:32:31 +00:00
parent 4d91f5f184
commit 88cea2c678
2 changed files with 18 additions and 7 deletions

View File

@ -13803,12 +13803,21 @@ class PubServer(BaseHTTPRequestHandler):
return True
def _show_qrcode(self, calling_domain: str, path: str,
base_dir: str, domain: str, port: int,
getreq_start_time) -> bool:
base_dir: str, domain: str,
onion_domain: str, i2p_domain: str,
port: int, getreq_start_time) -> bool:
"""Shows a QR code for an account
"""
nickname = get_nickname_from_actor(path)
save_person_qrcode(base_dir, nickname, domain, port)
if onion_domain:
qrcode_domain = onion_domain
port = 80
elif i2p_domain:
qrcode_domain = i2p_domain
port = 80
else:
qrcode_domain = domain
save_person_qrcode(base_dir, nickname, domain, qrcode_domain, port)
qr_filename = \
acct_dir(base_dir, nickname, domain) + '/qrcode.png'
if os.path.isfile(qr_filename):
@ -16146,6 +16155,8 @@ class PubServer(BaseHTTPRequestHandler):
if self._show_qrcode(calling_domain, self.path,
self.server.base_dir,
self.server.domain,
self.server.onion_domain,
self.server.i2p_domain,
self.server.port,
getreq_start_time):
return

View File

@ -582,15 +582,15 @@ def create_group(base_dir: str, nickname: str, domain: str, port: int,
def save_person_qrcode(base_dir: str,
nickname: str, domain: str, port: int,
scale=6) -> None:
nickname: str, domain: str, qrcode_domain: str,
port: int, scale=6) -> None:
"""Saves a qrcode image for the handle of the person
This helps to transfer onion or i2p handles to a mobile device
"""
qrcode_filename = acct_dir(base_dir, nickname, domain) + '/qrcode.png'
if os.path.isfile(qrcode_filename):
return
handle = get_full_domain('@' + nickname + '@' + domain, port)
handle = get_full_domain('@' + nickname + '@' + qrcode_domain, port)
url = pyqrcode.create(handle)
url.png(qrcode_filename, scale)
@ -707,7 +707,7 @@ def create_person(base_dir: str, nickname: str, domain: str, port: int,
registrations_remaining -= 1
set_config_param(base_dir, 'registrationsRemaining',
str(registrations_remaining))
save_person_qrcode(base_dir, nickname, domain, port)
save_person_qrcode(base_dir, nickname, domain, domain, port)
return private_key_pem, public_key_pem, new_person, webfinger_endpoint