do not use regex to parse instances, and add count of instances to default page

This commit is contained in:
Tristan Mahé 2018-11-01 14:49:48 -07:00
parent 388bd8d946
commit ee7f1cc190

View file

@ -1,11 +1,13 @@
import aiohttp.web import aiohttp.web
import re import urllib.parse
from . import app, CONFIG from . import app, CONFIG
from .database import DATABASE from .database import DATABASE
host = CONFIG['ap']['host'] host = CONFIG['ap']['host']
note = CONFIG['note'] note = CONFIG['note']
targets = '<br>'.join([re.search('https://(.*)/inbox',target).group(1) for target in DATABASE.get('relay-list', [])])
inboxes = DATABASE.get('relay-list', [])
targets = '<br>'.join([urllib.parse.urlsplit(target).hostname for target in inboxes])
async def default(request): async def default(request):
return aiohttp.web.Response( return aiohttp.web.Response(
@ -26,9 +28,9 @@ async def default(request):
<p>For Mastodon instances, you may subscribe to this relay with the address: <a href="https://{host}/inbox">https://{host}/inbox</a></p> <p>For Mastodon instances, you may subscribe to this relay with the address: <a href="https://{host}/inbox">https://{host}/inbox</a></p>
<p>For Pleroma and other instances, you may subscribe to this relay with the address: <a href="https://{host}/actor">https://{host}/actor</a></p> <p>For Pleroma and other instances, you may subscribe to this relay with the address: <a href="https://{host}/actor">https://{host}/actor</a></p>
<p>To host your own relay, you may download the code at this address: <a href="https://git.pleroma.social/pleroma/relay">https://git.pleroma.social/pleroma/relay</a></p> <p>To host your own relay, you may download the code at this address: <a href="https://git.pleroma.social/pleroma/relay">https://git.pleroma.social/pleroma/relay</a></p>
<br><p>List of registered instances:<br>{targets}</p> <br><p>List of {count} registered instances:<br>{targets}</p>
</body></html> </body></html>
""".format(host=host, note=note,targets=targets)) """.format(host=host, note=note,targets=targets,count=len(inboxes)))
app.router.add_get('/', default) app.router.add_get('/', default)