diff --git a/README.md b/README.md index e609b6c..5f9bfbc 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,4 @@ `nostrclient` is an always-on extension that can open multiple connections to nostr relays and act as a multiplexer for other clients: You open a single websocket to `nostrclient` which then sends the data to multiple relays. The responses from these relays are then sent back to the client. - - ![2023-03-08 18 11 07](https://user-images.githubusercontent.com/93376500/225265727-369f0f8a-196e-41df-a0d1-98b50a0228be.jpg) diff --git a/__init__.py b/__init__.py index 90da4ec..60d8e23 100644 --- a/__init__.py +++ b/__init__.py @@ -1,8 +1,9 @@ from fastapi import APIRouter +from starlette.staticfiles import StaticFiles + from lnbits.db import Database from lnbits.helpers import template_renderer from lnbits.tasks import catch_everything_and_restart -from starlette.staticfiles import StaticFiles db = Database("ext_nostrclient") diff --git a/crud.py b/crud.py index 497fcd7..780642d 100644 --- a/crud.py +++ b/crud.py @@ -1,6 +1,7 @@ from typing import List, Optional, Union import shortuuid + from lnbits.helpers import urlsafe_short_hash from . import db diff --git a/models.py b/models.py index 75a086d..4ed1e30 100644 --- a/models.py +++ b/models.py @@ -3,9 +3,10 @@ from typing import Dict, List, Optional from fastapi import Request from fastapi.param_functions import Query -from lnbits.helpers import urlsafe_short_hash from pydantic import BaseModel, Field +from lnbits.helpers import urlsafe_short_hash + class Relay(BaseModel): id: Optional[str] = None diff --git a/services.py b/services.py index 09e9235..ab65dae 100644 --- a/services.py +++ b/services.py @@ -3,16 +3,16 @@ import json from typing import List, Union from fastapi import WebSocket, WebSocketDisconnect + from lnbits.helpers import urlsafe_short_hash -from .nostr.client.client import NostrClient as NostrClientLib from .models import Event, Filter, Filters, Relay, RelayList +from .nostr.client.client import NostrClient as NostrClientLib from .nostr.event import Event as NostrEvent from .nostr.filter import Filter as NostrFilter from .nostr.filter import Filters as NostrFilters from .nostr.message_pool import EndOfStoredEventsMessage, EventMessage, NoticeMessage - received_subscription_events: dict[str, list[Event]] = {} received_subscription_notices: dict[str, list[NoticeMessage]] = {} received_subscription_eosenotices: dict[str, EndOfStoredEventsMessage] = {} diff --git a/tasks.py b/tasks.py index 7894e40..1566f65 100644 --- a/tasks.py +++ b/tasks.py @@ -2,20 +2,18 @@ import asyncio import ssl import threading +from .crud import get_relays from .nostr.event import Event from .nostr.key import PublicKey from .nostr.message_pool import EndOfStoredEventsMessage, EventMessage, NoticeMessage from .nostr.relay_manager import RelayManager from .services import ( nostr, - received_subscription_events, received_subscription_eosenotices, + received_subscription_events, ) -from .crud import get_relays - - async def init_relays(): # reinitialize the entire client nostr.__init__() diff --git a/templates/nostrclient/index.html b/templates/nostrclient/index.html index 2a6cf60..abe5a87 100644 --- a/templates/nostrclient/index.html +++ b/templates/nostrclient/index.html @@ -75,12 +75,17 @@ - -
Your endpoint: - -
+
+ Your endpoint: + +
@@ -88,7 +93,13 @@
- +
Add relay @@ -104,17 +115,20 @@
Nostrclient Extension

This extension is a always-on nostr client that other extensions can - use to send and receive events on nostr. - - Add multiple nostr relays to connect to. The extension then opens a websocket for you to use - at -

- - -

- Only Admin users can manage - this extension. + use to send and receive events on nostr. Add multiple nostr relays to + connect to. The extension then opens a websocket for you to use at

+ +

+ + +

+ Only Admin users can manage this extension. @@ -217,7 +231,7 @@ message: `Invalid relay URL.`, caption: "Should start with 'wss://'' or 'ws://'" }) - return false; + return false } console.log('ADD RELAY ' + this.relayToAdd) let that = this @@ -229,7 +243,7 @@ {url: this.relayToAdd} ) .then(function (response) { - console.log("response:", response) + console.log('response:', response) if (response.data) { response.data.map(maplrelays) that.nostrrelayLinks = response.data @@ -239,7 +253,7 @@ .catch(function (error) { LNbits.utils.notifyApiError(error) }) - return false; + return false }, deleteRelay(url) { console.log('DELETE RELAY ' + url) diff --git a/views.py b/views.py index ce30b3b..a05f956 100644 --- a/views.py +++ b/views.py @@ -6,11 +6,12 @@ from fastapi import Request from fastapi.param_functions import Query from fastapi.params import Depends from fastapi.templating import Jinja2Templates +from starlette.responses import HTMLResponse + from lnbits.core.crud import update_payment_status from lnbits.core.models import User from lnbits.core.views.api import api_payment from lnbits.decorators import check_admin, check_user_exists -from starlette.responses import HTMLResponse from . import nostr_renderer, nostrclient_ext diff --git a/views_api.py b/views_api.py index c3da200..15cc3ab 100644 --- a/views_api.py +++ b/views_api.py @@ -3,11 +3,12 @@ from http import HTTPStatus from typing import Optional from fastapi import Depends, WebSocket -from lnbits.decorators import check_admin -from lnbits.helpers import urlsafe_short_hash from loguru import logger from starlette.exceptions import HTTPException +from lnbits.decorators import check_admin +from lnbits.helpers import urlsafe_short_hash + from . import nostrclient_ext from .crud import add_relay, delete_relay, get_relays from .models import Relay, RelayList