From db3ad2e32fd4bc0d2d4b29f509dbbfed2b78ac2d Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 10 Feb 2023 14:47:48 +0200 Subject: [PATCH] feat: public relay page updates --- crud.py | 3 +- models.py | 22 +++++--- templates/nostrrelay/public.html | 96 ++++++++++++++++++++++++++++---- views.py | 1 + 4 files changed, 102 insertions(+), 20 deletions(-) diff --git a/crud.py b/crud.py index 8689a12..b945537 100644 --- a/crud.py +++ b/crud.py @@ -2,7 +2,7 @@ import json from typing import Any, List, Optional, Tuple from . import db -from .models import NostrEvent, NostrFilter, NostrRelay, RelaySpec +from .models import NostrEvent, NostrFilter, NostrRelay, RelayPublicSpec, RelaySpec ########################## RELAYS #################### @@ -100,6 +100,7 @@ async def get_public_relay(relay_id: str) -> Optional[dict]: "description": relay.description, "pubkey": relay.pubkey, "contact": relay.contact, + "config": dict(RelayPublicSpec(**dict(relay.config))) } diff --git a/models.py b/models.py index 75cec3b..44647d5 100644 --- a/models.py +++ b/models.py @@ -8,11 +8,14 @@ from pydantic import BaseModel, Field from secp256k1 import PublicKey -class FilterSpec(BaseModel): +class Spec(BaseModel): + class Config: + allow_population_by_field_name = True +class FilterSpec(Spec): max_client_filters = Field(0, alias="maxClientFilters") limit_per_filter = Field(1000, alias="limitPerFilter") -class EventSpec(BaseModel): +class EventSpec(Spec): max_events_per_second = Field(0, alias="maxEventsPerSecond") created_at_days_past = Field(0, alias="createdAtDaysPast") @@ -44,7 +47,7 @@ class EventSpec(BaseModel): + self.created_at_seconds_future ) -class StorageSpec(BaseModel): +class StorageSpec(Spec): free_storage_value = Field(1, alias="freeStorageValue") free_storage_unit = Field("MB", alias="freeStorageUnit") full_storage_action = Field("prune", alias="fullStorageAction") @@ -56,7 +59,7 @@ class StorageSpec(BaseModel): value *= 1024 return value -class AuthorSpec(BaseModel): +class AuthorSpec(Spec): allowed_public_keys = Field([], alias="allowedPublicKeys") blocked_public_keys = Field([], alias="blockedPublicKeys") @@ -68,18 +71,21 @@ class AuthorSpec(BaseModel): # todo: check payment return p in self.allowed_public_keys + class PaymentSpec(BaseModel): is_paid_relay = Field(False, alias="isPaidRelay") - wallet = Field("") cost_to_join = Field(0, alias="costToJoin") storage_cost_value = Field(0, alias="storageCostValue") storage_cost_unit = Field("MB", alias="storageCostUnit") +class WalletSpec(Spec): + wallet = Field("") -class RelaySpec(FilterSpec, EventSpec, StorageSpec, AuthorSpec, PaymentSpec): - class Config: - allow_population_by_field_name = True +class RelaySpec(FilterSpec, EventSpec, StorageSpec, AuthorSpec, PaymentSpec, WalletSpec): + pass +class RelayPublicSpec(FilterSpec, EventSpec, StorageSpec, PaymentSpec): + pass class NostrRelay(BaseModel): id: str diff --git a/templates/nostrrelay/public.html b/templates/nostrrelay/public.html index e5e5cea..ec65d42 100644 --- a/templates/nostrrelay/public.html +++ b/templates/nostrrelay/public.html @@ -1,16 +1,88 @@ -{% extends "public.html" %} {% block toolbar_title %} {{ relay.name }} - +{% extends "public.html" %} {% block toolbar_title %} LNbits Relay + {% endblock %} {% block footer %}{% endblock %} {% block page_container %} + -

Shareable public page on relay to go here!

+
+
+
+ + + +
+
+ + + + + + + + + + GET + /lnurlp/api/v1/links +
Headers
+ {"X-Api-Key": <invoice_key>}
+
+ Body (application/json) +
+
+ Returns 200 OK (application/json) +
+ [<pay_link_object>, ...] +
Curl example
+
+
+
+ + + + + + + + + + + + + + + +
+
+
+
+
{% endblock %} {% block scripts %} @@ -21,7 +93,9 @@ el: '#vue', mixins: [windowMixin], data: function () { - return {} + return { + relay: JSON.parse('{{relay | tojson | safe}}') + } }, methods: {} }) diff --git a/views.py b/views.py index e68923d..2f85ed6 100644 --- a/views.py +++ b/views.py @@ -24,6 +24,7 @@ async def index(request: Request, user: User = Depends(check_user_exists)): @nostrrelay_ext.get("/{relay_id}") async def nostrrelay(request: Request, relay_id: str): relay_public_data = await get_public_relay(relay_id) + if not relay_public_data: raise HTTPException( status_code=HTTPStatus.NOT_FOUND,