feat: add basic block/allow actions
This commit is contained in:
parent
d8ca9f830a
commit
2c5dfbbf92
3 changed files with 20 additions and 17 deletions
|
|
@ -532,7 +532,7 @@
|
||||||
<q-input
|
<q-input
|
||||||
filled
|
filled
|
||||||
dense
|
dense
|
||||||
v-model.trim="allowedPubkey"
|
v-model.trim="accountPubkey"
|
||||||
type="text"
|
type="text"
|
||||||
></q-input>
|
></q-input>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -541,7 +541,7 @@
|
||||||
unelevated
|
unelevated
|
||||||
color="green"
|
color="green"
|
||||||
class="float-right"
|
class="float-right"
|
||||||
@click="allowPublicKey()"
|
@click="allowPublicKey(true)"
|
||||||
>Allow</q-btn
|
>Allow</q-btn
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -550,7 +550,7 @@
|
||||||
unelevated
|
unelevated
|
||||||
color="pink"
|
color="pink"
|
||||||
class="float-right"
|
class="float-right"
|
||||||
@click="blockPublicKey()"
|
@click="blockPublicKey(true)"
|
||||||
>Block</q-btn
|
>Block</q-btn
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,7 @@ async function relayDetails(path) {
|
||||||
return {
|
return {
|
||||||
tab: 'info',
|
tab: 'info',
|
||||||
relay: null,
|
relay: null,
|
||||||
blockedPubkey: '',
|
accountPubkey: '',
|
||||||
allowedPubkey: '',
|
|
||||||
formDialogItem: {
|
formDialogItem: {
|
||||||
show: false,
|
show: false,
|
||||||
data: {
|
data: {
|
||||||
|
|
@ -114,33 +113,35 @@ async function relayDetails(path) {
|
||||||
this.relay.config.wallet =
|
this.relay.config.wallet =
|
||||||
this.relay.config.wallet || this.walletOptions[0].value
|
this.relay.config.wallet || this.walletOptions[0].value
|
||||||
},
|
},
|
||||||
allowPublicKey: async function () {
|
allowPublicKey: async function (allowed) {
|
||||||
|
await this.updatePublicKey({allowed})
|
||||||
|
},
|
||||||
|
blockPublicKey: async function (blocked = true) {
|
||||||
|
await this.updatePublicKey({blocked})
|
||||||
|
},
|
||||||
|
updatePublicKey: async function (ops) {
|
||||||
try {
|
try {
|
||||||
const {data} = await LNbits.api.request(
|
await LNbits.api.request(
|
||||||
'PUT',
|
'PUT',
|
||||||
'/nostrrelay/api/v1/account',
|
'/nostrrelay/api/v1/account',
|
||||||
this.adminkey,
|
this.adminkey,
|
||||||
{
|
{
|
||||||
pubkey: this.allowedPubkey,
|
relay_id: this.relay.id,
|
||||||
allowed: true
|
pubkey: this.accountPubkey,
|
||||||
|
allowed: ops.allowed,
|
||||||
|
blocked: ops.blocked
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
this.relay = data
|
|
||||||
this.$emit('relay-updated', this.relay)
|
|
||||||
this.$q.notify({
|
this.$q.notify({
|
||||||
type: 'positive',
|
type: 'positive',
|
||||||
message: 'Account Updated',
|
message: 'Account Updated',
|
||||||
timeout: 5000
|
timeout: 5000
|
||||||
})
|
})
|
||||||
this.allowedPubkey = ''
|
this.accountPubkey = ''
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
blockPublicKey: function () {
|
|
||||||
this.relay.config.blockedPublicKeys.push(this.blockedPubkey)
|
|
||||||
this.blockedPubkey = ''
|
|
||||||
},
|
|
||||||
deleteAllowedPublicKey: function (pubKey) {
|
deleteAllowedPublicKey: function (pubKey) {
|
||||||
this.relay.config.allowedPublicKeys =
|
this.relay.config.allowedPublicKeys =
|
||||||
this.relay.config.allowedPublicKeys.filter(p => p !== pubKey)
|
this.relay.config.allowedPublicKeys.filter(p => p !== pubKey)
|
||||||
|
|
|
||||||
|
|
@ -155,12 +155,14 @@ async def api_create_or_update_account(
|
||||||
data.pubkey = normalize_public_key(data.pubkey)
|
data.pubkey = normalize_public_key(data.pubkey)
|
||||||
account = await get_account(data.relay_id, data.pubkey)
|
account = await get_account(data.relay_id, data.pubkey)
|
||||||
if not account:
|
if not account:
|
||||||
return await create_account(data.relay_id, NostrAccount.parse_obj(data.dict()))
|
account = NostrAccount(pubkey=data.pubkey, blocked = data.blocked or False, allowed = data.allowed or False)
|
||||||
|
return await create_account(data.relay_id, account)
|
||||||
|
|
||||||
if data.blocked is not None:
|
if data.blocked is not None:
|
||||||
account.blocked = data.blocked
|
account.blocked = data.blocked
|
||||||
if data.allowed is not None:
|
if data.allowed is not None:
|
||||||
account.allowed = data.allowed
|
account.allowed = data.allowed
|
||||||
|
|
||||||
return await update_account(data.relay_id, account)
|
return await update_account(data.relay_id, account)
|
||||||
|
|
||||||
except ValueError as ex:
|
except ValueError as ex:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue