feat: ass basic test api

This commit is contained in:
Vlad Stan 2023-05-05 11:10:23 +03:00
parent 977ee84d9e
commit 7adc33b729
2 changed files with 31 additions and 1 deletions

View file

@ -50,6 +50,16 @@ class Filters(BaseModel):
__root__: List[Filter]
class TestMessage(BaseModel):
sender_private_key: Optional[str]
reciever_public_key: str
message: str
class TestMessageResponse(BaseModel):
private_key: str
public_key: str
event: Event
# class nostrKeys(BaseModel):
# pubkey: str
# privkey: str

View file

@ -11,7 +11,7 @@ from lnbits.helpers import urlsafe_short_hash
from . import nostrclient_ext, scheduled_tasks
from .crud import add_relay, delete_relay, get_relays
from .models import Relay, RelayList
from .models import Relay, RelayList, TestMessage, TestMessageResponse
from .services import NostrRouter, nostr
from .tasks import init_relays
@ -75,6 +75,26 @@ async def api_delete_relay(relay: Relay) -> None:
await delete_relay(relay)
@nostrclient_ext.put(
"/api/v1/relay/test", status_code=HTTPStatus.OK, dependencies=[Depends(check_admin)]
)
async def api_test_endpoint(test_message: TestMessage) -> TestMessageResponse:
try:
print("### api_test_endpoint", test_message)
except (ValueError, AssertionError) as ex:
raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST,
detail=str(ex),
)
except Exception as ex:
logger.warning(ex)
raise HTTPException(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
detail="Cannot generate test event",
)
@nostrclient_ext.delete(
"/api/v1", status_code=HTTPStatus.OK, dependencies=[Depends(check_admin)]
)