Compare commits
2 commits
2e7d12b3e6
...
0b1a548ee4
Author | SHA1 | Date | |
---|---|---|---|
0b1a548ee4 | |||
04bd6dd35d |
8 changed files with 67 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "lemoncurry",
|
||||
"version": "1.11.0",
|
||||
"version": "1.12.0",
|
||||
"repository": "https://git.00dani.me/00dani/lemoncurry",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[tool.poetry]
|
||||
name = "lemoncurry"
|
||||
version = "1.11.0"
|
||||
version = "1.12.0"
|
||||
description = "Indieweb-compatible personal website"
|
||||
authors = ["Danielle McLean <dani@00dani.me>"]
|
||||
license = "MIT"
|
||||
|
|
|
@ -20,6 +20,7 @@ class ProfileInline(admin.TabularInline):
|
|||
class UserAdmin(BaseUserAdmin):
|
||||
fieldsets = BaseUserAdmin.fieldsets + (
|
||||
("Profile", {"fields": ("avatar", "xmpp", "note")}),
|
||||
("Nostr", {"fields": ("nostr_key", "nostr_relays")}),
|
||||
)
|
||||
inlines = (
|
||||
PgpKeyInline,
|
||||
|
|
22
users/migrations/0018_auto_20230810_1754.py
Normal file
22
users/migrations/0018_auto_20230810_1754.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
# Generated by Django 3.2.20 on 2023-08-10 07:54
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("users", "0017_rename_key_pgpkey"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="user",
|
||||
name="nostr_key",
|
||||
field=models.CharField(blank=True, max_length=32, null=True, unique=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="user",
|
||||
name="nostr_relays",
|
||||
field=models.JSONField(blank=True, default=list),
|
||||
),
|
||||
]
|
|
@ -81,6 +81,19 @@ class User(ModelMeta, AbstractUser):
|
|||
help_text="SHA-256 hash of the user's OpenID URL, used for Libravatar",
|
||||
)
|
||||
|
||||
nostr_key = models.CharField(
|
||||
max_length=32,
|
||||
unique=True,
|
||||
blank=True,
|
||||
null=True,
|
||||
help_text="A Nostr public key in 32-byte hex format",
|
||||
)
|
||||
nostr_relays = models.JSONField(
|
||||
default=list,
|
||||
blank=True,
|
||||
help_text="An array of Nostr relay URLs that this public key posts to",
|
||||
)
|
||||
|
||||
@property
|
||||
def calc_email_md5(self):
|
||||
return md5(self.email.lower().encode("utf-8")).hexdigest()
|
||||
|
|
|
@ -8,5 +8,6 @@ urlpatterns = [
|
|||
path("host-meta", views.host_meta_xml, name="host-meta"),
|
||||
path("host-meta.json", views.host_meta_json, name="host-meta.json"),
|
||||
path("manifest.json", views.manifest, name="manifest"),
|
||||
path("nostr.json", views.nostr_json, name="nostr.json"),
|
||||
path("webfinger", views.webfinger, name="webfinger"),
|
||||
]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from .static import keybase
|
||||
from .host_meta import host_meta_xml, host_meta_json
|
||||
from .manifest import manifest
|
||||
from .nostr import nostr_json
|
||||
from .webfinger import webfinger
|
||||
|
|
27
wellknowns/views/nostr.py
Normal file
27
wellknowns/views/nostr.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
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)
|
Loading…
Reference in a new issue