feat: partial NIP11

This commit is contained in:
Vlad Stan 2023-02-03 16:37:27 +02:00
parent 9b9e2623be
commit cbbabf2ce8
2 changed files with 23 additions and 0 deletions

View file

@ -20,6 +20,16 @@ class NostrRelay(BaseModel):
def from_row(cls, row: Row) -> "NostrRelay": def from_row(cls, row: Row) -> "NostrRelay":
return cls(**dict(row)) return cls(**dict(row))
class NostrRelayInfo(BaseModel):
name: Optional[str]
description: Optional[str]
pubkey: Optional[str]
contact: Optional[str] = "https://t.me/lnbits"
supported_nips: List[str] = ["NIP01", "NIP09", "NIP11"]
software: Optional[str] = "LNbist"
version: Optional[str]
class NostrEventType(str, Enum): class NostrEventType(str, Enum):
EVENT = "EVENT" EVENT = "EVENT"
REQ = "REQ" REQ = "REQ"

View file

@ -1,10 +1,12 @@
from http import HTTPStatus from http import HTTPStatus
from fastapi import Query, WebSocket from fastapi import Query, WebSocket
from fastapi.responses import JSONResponse
from loguru import logger from loguru import logger
from . import nostrrelay_ext from . import nostrrelay_ext
from .client_manager import NostrClientConnection, NostrClientManager from .client_manager import NostrClientConnection, NostrClientManager
from .models import NostrRelayInfo
client_manager = NostrClientManager() client_manager = NostrClientManager()
@ -20,6 +22,17 @@ async def websocket_endpoint(websocket: WebSocket):
client_manager.remove_client(client) client_manager.remove_client(client)
@nostrrelay_ext.get("/client", status_code=HTTPStatus.OK)
async def api_nostrrelay_info():
headers = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"Access-Control-Allow-Methods": "GET"
}
info = NostrRelayInfo()
return JSONResponse(content=dict(info), headers=headers)
@nostrrelay_ext.get("/api/v1/enable", status_code=HTTPStatus.OK) @nostrrelay_ext.get("/api/v1/enable", status_code=HTTPStatus.OK)
async def api_nostrrelay(enable: bool = Query(True)): async def api_nostrrelay(enable: bool = Query(True)):
return await enable_relay(enable) return await enable_relay(enable)