28 lines
833 B
Python
28 lines
833 B
Python
|
from django.http import JsonResponse
|
||
|
from users.models import User
|
||
|
|
||
|
aliases = {"00dani": ("_", "dani")}
|
||
|
unaliases = {alias: name for (name, aliases) in aliases.items() for alias in aliases}
|
||
|
|
||
|
|
||
|
def nostr_json(request) -> JsonResponse:
|
||
|
users = User.objects.filter(nostr_key__isnull=False)
|
||
|
|
||
|
if "name" in request.GET:
|
||
|
name = request.GET["name"]
|
||
|
if name in unaliases:
|
||
|
name = unaliases[name]
|
||
|
users = users.filter(username=name)
|
||
|
|
||
|
names = {u.username: u.nostr_key for u in users}
|
||
|
for name in list(names.keys()):
|
||
|
for alias in aliases.get(name, []):
|
||
|
names[alias] = names[name]
|
||
|
|
||
|
relays = {u.nostr_key: u.nostr_relays for u in users if u.nostr_relays}
|
||
|
|
||
|
response = {"names": names}
|
||
|
if relays:
|
||
|
response["relays"] = relays
|
||
|
return JsonResponse(response)
|