fix: separate relay update from activete/deactivate
This commit is contained in:
parent
63be2b5b2d
commit
67dda89c81
1 changed files with 35 additions and 1 deletions
36
views_api.py
36
views_api.py
|
|
@ -76,7 +76,7 @@ async def api_create_relay(
|
|||
)
|
||||
|
||||
|
||||
@nostrrelay_ext.put("/api/v1/relay/{relay_id}")
|
||||
@nostrrelay_ext.patch("/api/v1/relay/{relay_id}")
|
||||
async def api_update_relay(
|
||||
relay_id: str, data: NostrRelay, wallet: WalletTypeInfo = Depends(require_admin_key)
|
||||
) -> NostrRelay:
|
||||
|
|
@ -95,6 +95,8 @@ async def api_update_relay(
|
|||
)
|
||||
updated_relay = NostrRelay.parse_obj({**dict(relay), **dict(data)})
|
||||
updated_relay = await update_relay(wallet.wallet.user, updated_relay)
|
||||
# activate & deactivate have their own endpoint
|
||||
updated_relay.active = relay.active
|
||||
|
||||
if updated_relay.active:
|
||||
await client_manager.enable_relay(relay_id, updated_relay.config)
|
||||
|
|
@ -113,6 +115,38 @@ async def api_update_relay(
|
|||
)
|
||||
|
||||
|
||||
@nostrrelay_ext.put("/api/v1/relay/{relay_id}")
|
||||
async def api_toggle_relay(
|
||||
relay_id: str, wallet: WalletTypeInfo = Depends(require_admin_key)
|
||||
) -> NostrRelay:
|
||||
|
||||
try:
|
||||
relay = await get_relay(wallet.wallet.user,relay_id)
|
||||
if not relay:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND,
|
||||
detail="Relay not found",
|
||||
)
|
||||
relay.active = not relay.active
|
||||
updated_relay = await update_relay(wallet.wallet.user, relay)
|
||||
|
||||
if relay.active:
|
||||
await client_manager.enable_relay(relay_id, relay.config)
|
||||
else:
|
||||
await client_manager.disable_relay(relay_id)
|
||||
|
||||
return updated_relay
|
||||
|
||||
except HTTPException as ex:
|
||||
raise ex
|
||||
except Exception as ex:
|
||||
logger.warning(ex)
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||
detail="Cannot update relay",
|
||||
)
|
||||
|
||||
|
||||
@nostrrelay_ext.get("/api/v1/relay")
|
||||
async def api_get_relays(
|
||||
wallet: WalletTypeInfo = Depends(require_invoice_key),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue