feat: on create save domain for relay

This commit is contained in:
Vlad Stan 2023-02-14 10:27:24 +02:00
parent be606934bf
commit d0c6f1392b
3 changed files with 18 additions and 2 deletions

View file

@ -87,6 +87,8 @@ class WalletSpec(Spec):
class RelayPublicSpec(FilterSpec, EventSpec, StorageSpec, PaymentSpec): class RelayPublicSpec(FilterSpec, EventSpec, StorageSpec, PaymentSpec):
domain: str = ''
@property @property
def is_read_only_relay(self): def is_read_only_relay(self):
self.free_storage_value == 0 and not self.is_paid_relay self.free_storage_value == 0 and not self.is_paid_relay

View file

@ -57,6 +57,18 @@
</div> </div>
<div class="col-3 col-sm-1"></div> <div class="col-3 col-sm-1"></div>
</div> </div>
<div class="row items-center no-wrap q-mb-md">
<div class="col-3 q-pr-lg">Domain:</div>
<div class="col-6 col-sm-8 q-pr-lg">
<q-input
filled
dense
v-model.trim="relay.config.domain"
type="text"
></q-input>
</div>
<div class="col-3 col-sm-1"></div>
</div>
</div> </div>
</q-tab-panel> </q-tab-panel>
<q-tab-panel name="payment"> <q-tab-panel name="payment">

View file

@ -1,7 +1,8 @@
from http import HTTPStatus from http import HTTPStatus
from typing import List, Optional from typing import List, Optional
from fastapi import Depends, WebSocket from urllib.parse import urlparse
from fastapi import Depends, WebSocket, Request
from fastapi.exceptions import HTTPException from fastapi.exceptions import HTTPException
from loguru import logger from loguru import logger
from pydantic.types import UUID4 from pydantic.types import UUID4
@ -48,7 +49,7 @@ async def websocket_endpoint(relay_id: str, websocket: WebSocket):
@nostrrelay_ext.post("/api/v1/relay") @nostrrelay_ext.post("/api/v1/relay")
async def api_create_relay( async def api_create_relay(
data: NostrRelay, wallet: WalletTypeInfo = Depends(require_admin_key) data: NostrRelay, request: Request, wallet: WalletTypeInfo = Depends(require_admin_key)
) -> NostrRelay: ) -> NostrRelay:
if len(data.id): if len(data.id):
await check_admin(UUID4(wallet.wallet.user)) await check_admin(UUID4(wallet.wallet.user))
@ -56,6 +57,7 @@ async def api_create_relay(
data.id = urlsafe_short_hash()[:8] data.id = urlsafe_short_hash()[:8]
try: try:
data.config.domain = urlparse(str(request.url)).netloc
relay = await create_relay(wallet.wallet.user, data) relay = await create_relay(wallet.wallet.user, data)
return relay return relay