feat: save relay extra config
This commit is contained in:
parent
f689e829eb
commit
25dde9571c
4 changed files with 28 additions and 21 deletions
10
crud.py
10
crud.py
|
|
@ -11,10 +11,10 @@ from .models import NostrEvent, NostrFilter, NostrRelay
|
||||||
async def create_relay(user_id: str, r: NostrRelay) -> NostrRelay:
|
async def create_relay(user_id: str, r: NostrRelay) -> NostrRelay:
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO nostrrelay.relays (user_id, id, name, description, pubkey, contact)
|
INSERT INTO nostrrelay.relays (user_id, id, name, description, pubkey, contact, meta)
|
||||||
VALUES (?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(user_id, r.id, r.name, r.description, r.pubkey, r.contact,),
|
(user_id, r.id, r.name, r.description, r.pubkey, r.contact, json.dumps(dict(r.config))),
|
||||||
)
|
)
|
||||||
relay = await get_relay(user_id, r.id)
|
relay = await get_relay(user_id, r.id)
|
||||||
assert relay, "Created relay cannot be retrieved"
|
assert relay, "Created relay cannot be retrieved"
|
||||||
|
|
@ -24,10 +24,10 @@ async def update_relay(user_id: str, r: NostrRelay) -> NostrRelay:
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
UPDATE nostrrelay.relays
|
UPDATE nostrrelay.relays
|
||||||
SET (name, description, pubkey, contact, active) = (?, ?, ?, ?, ?)
|
SET (name, description, pubkey, contact, active, meta) = (?, ?, ?, ?, ?, ?)
|
||||||
WHERE user_id = ? AND id = ?
|
WHERE user_id = ? AND id = ?
|
||||||
""",
|
""",
|
||||||
(r.name, r.description, r.pubkey, r.contact, r.active, user_id, r.id),
|
(r.name, r.description, r.pubkey, r.contact, r.active, json.dumps(dict(r.config)), user_id, r.id),
|
||||||
)
|
)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
|
||||||
25
models.py
25
models.py
|
|
@ -8,6 +8,19 @@ from pydantic import BaseModel, Field
|
||||||
from secp256k1 import PublicKey
|
from secp256k1 import PublicKey
|
||||||
|
|
||||||
|
|
||||||
|
class RelayConfig(BaseModel):
|
||||||
|
is_paid_relay = Field(False, alias="isPaidRelay")
|
||||||
|
wallet = Field("")
|
||||||
|
cost_to_join = Field(0, alias="costToJoin")
|
||||||
|
free_storage = Field(0, alias="freeStorage")
|
||||||
|
storage_cost_per_kb = Field(0, alias="storageCostPerKb")
|
||||||
|
max_client_filters = Field(0, alias="maxClientFilters")
|
||||||
|
allowed_public_keys = Field([], alias="allowedPublicKeys")
|
||||||
|
blocked_public_keys = Field([], alias="blockedPublicKeys")
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
allow_population_by_field_name = True
|
||||||
|
|
||||||
class NostrRelay(BaseModel):
|
class NostrRelay(BaseModel):
|
||||||
id: str
|
id: str
|
||||||
name: str
|
name: str
|
||||||
|
|
@ -16,7 +29,14 @@ class NostrRelay(BaseModel):
|
||||||
contact: Optional[str]
|
contact: Optional[str]
|
||||||
active: bool = False
|
active: bool = False
|
||||||
|
|
||||||
# meta: Optional[str]
|
config: "RelayConfig" = RelayConfig()
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_row(cls, row: Row) -> "NostrRelay":
|
||||||
|
relay = cls(**dict(row))
|
||||||
|
relay.config = RelayConfig(**json.loads(row["meta"]))
|
||||||
|
return relay
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def info(cls,) -> dict:
|
def info(cls,) -> dict:
|
||||||
|
|
@ -28,9 +48,6 @@ class NostrRelay(BaseModel):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_row(cls, row: Row) -> "NostrRelay":
|
|
||||||
return cls(**dict(row))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -162,14 +162,14 @@
|
||||||
<q-input
|
<q-input
|
||||||
filled
|
filled
|
||||||
dense
|
dense
|
||||||
v-model.trim="relay.config.maxFilters"
|
v-model.trim="relay.config.maxClientFilters"
|
||||||
type="number"
|
type="number"
|
||||||
min="0"
|
min="0"
|
||||||
></q-input>
|
></q-input>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<q-badge
|
<q-badge
|
||||||
v-if="relay.config.maxFilters == 0"
|
v-if="relay.config.maxClientFilters == 0"
|
||||||
color="green"
|
color="green"
|
||||||
class="float-left"
|
class="float-left"
|
||||||
><span>Unlimited Filters</span>
|
><span>Unlimited Filters</span>
|
||||||
|
|
|
||||||
|
|
@ -56,16 +56,6 @@ async function relayDetails(path) {
|
||||||
'/nostrrelay/api/v1/relay/' + this.relayId,
|
'/nostrrelay/api/v1/relay/' + this.relayId,
|
||||||
this.inkey
|
this.inkey
|
||||||
)
|
)
|
||||||
data.config = {
|
|
||||||
isPaidRelay: true,
|
|
||||||
wallet: '',
|
|
||||||
costToJoin: 0,
|
|
||||||
freeStorage: 0,
|
|
||||||
storageCostPerKb: 0,
|
|
||||||
maxFilters: 0,
|
|
||||||
allowedPublicKeys: [],
|
|
||||||
blockedPublicKeys: []
|
|
||||||
}
|
|
||||||
this.relay = data
|
this.relay = data
|
||||||
|
|
||||||
console.log('### this.relay', this.relay)
|
console.log('### this.relay', this.relay)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue