code refactor
This commit is contained in:
parent
2eb44674d0
commit
e96ec08f44
|
@ -102,8 +102,8 @@ async def create_domain(*, wallet: str, domain: str, cfToken: str, cfZoneId: str
|
|||
domain_id = urlsafe_short_hash()
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO domains (id, wallet, domain, webhook, cf_token, cf_zone_id, description, cost, amountmade)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?. ?, ?)
|
||||
INSERT INTO domain (id, wallet, domain, webhook, cf_token, cf_zone_id, description, cost, amountmade)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(domain_id, wallet, domain, webhook, cfToken, cfZoneId, description, cost, 0),
|
||||
)
|
||||
|
|
|
@ -5,8 +5,8 @@ class Domains(NamedTuple):
|
|||
id: str
|
||||
wallet: str
|
||||
domain: str
|
||||
cfToken: str
|
||||
cfZoneId: str
|
||||
cf_token: str
|
||||
cf_zone_id: str
|
||||
webhook: str
|
||||
description: str
|
||||
cost: int
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
<q-select filled dense emit-value v-model="domainDialog.data.wallet" :options="g.user.walletOptions"
|
||||
label="Wallet *">
|
||||
</q-select>
|
||||
<q-input filled dense v-model.trim="domainDialog.data.domainName" type="name" label="Domain name "></q-input>
|
||||
<q-input filled dense v-model.trim="domainDialog.data.domain" type="text" label="Domain name "></q-input>
|
||||
<q-input filled dense v-model.trim="domainDialog.data.cfToken" type="text" label="Cloudflare API token">
|
||||
</q-input>
|
||||
<q-input filled dense v-model.trim="domainDialog.data.cfZoneId" type="text" label="Cloudflare Zone Id">
|
||||
|
@ -73,7 +73,7 @@
|
|||
<div class="row q-mt-lg">
|
||||
<q-btn v-if="domainDialog.data.id" unelevated color="deep-purple" type="submit">Update Form</q-btn>
|
||||
<q-btn v-else unelevated color="deep-purple"
|
||||
:disable="domainDialog.data.cost == null || domainDialog.data.cost < 0 || domainDialog.data.domainName == null"
|
||||
:disable="domainDialog.data.cost == null || domainDialog.data.cost < 0 || domainDialog.data.domain == null"
|
||||
type="submit">Create Domain</q-btn>
|
||||
<q-btn v-close-popup flat color="grey" class="q-ml-auto">Cancel</q-btn>
|
||||
</div>
|
||||
|
@ -104,7 +104,7 @@
|
|||
domainsTable: {
|
||||
columns: [
|
||||
{name: 'id', align: 'left', label: 'ID', field: 'id'},
|
||||
{name: 'domainName', align: 'left', label: 'Domain name', field: 'name'},
|
||||
{name: 'domain', align: 'left', label: 'Domain name', field: 'domain'},
|
||||
{name: 'wallet', align: 'left', label: 'Wallet', field: 'wallet'},
|
||||
{name: 'webhook', align: 'left', label: 'Webhook', field: 'webhook'},
|
||||
{
|
||||
|
@ -133,33 +133,32 @@
|
|||
methods: {
|
||||
getSubdomains: function () {
|
||||
var self = this
|
||||
/*
|
||||
|
||||
LNbits.api
|
||||
.request(
|
||||
'GET',
|
||||
'/lnticket/api/v1/tickets?all_wallets',
|
||||
'/subdomains/api/v1/subdomains?all_wallets',
|
||||
this.g.user.wallets[0].inkey
|
||||
)
|
||||
.then(function (response) {
|
||||
self.tickets = response.data.map(function (obj) {
|
||||
return mapLNTicket(obj)
|
||||
return mapLNSubdomain(obj)
|
||||
})
|
||||
})
|
||||
*/
|
||||
|
||||
},
|
||||
deleteSubdomain: function (subdomainId) {
|
||||
var self = this
|
||||
var tickets = _.findWhere(this.tickets, {id: ticketId})
|
||||
/*
|
||||
|
||||
LNbits.utils
|
||||
.confirmDialog('Are you sure you want to delete this ticket')
|
||||
.onOk(function () {
|
||||
LNbits.api
|
||||
.request(
|
||||
'DELETE',
|
||||
'/lnticket/api/v1/tickets/' + ticketId,
|
||||
_.findWhere(self.g.user.wallets, {id: tickets.wallet}).inkey
|
||||
'/subdomain/api/v1/subdomains/' + subdomainId,
|
||||
_.findWhere(self.g.user.wallets, {id: subdomains.wallet}).inkey
|
||||
)
|
||||
.then(function (response) {
|
||||
self.tickets = _.reject(self.tickets, function (obj) {
|
||||
|
@ -170,7 +169,7 @@
|
|||
LNbits.utils.notifyApiError(error)
|
||||
})
|
||||
})
|
||||
*/
|
||||
|
||||
},
|
||||
exportSubdomainsCSV: function () {
|
||||
LNbits.utils.exportCSV(this.domainsTable.columns, this.tickets)
|
||||
|
@ -178,19 +177,19 @@
|
|||
|
||||
getDomains: function () {
|
||||
var self = this
|
||||
/*
|
||||
|
||||
LNbits.api
|
||||
.request(
|
||||
'GET',
|
||||
'/lnticket/api/v1/forms?all_wallets',
|
||||
'/subdomains/api/v1/domains?all_wallets',
|
||||
this.g.user.wallets[0].inkey
|
||||
)
|
||||
.then(function (response) {
|
||||
self.forms = response.data.map(function (obj) {
|
||||
return mapLNTicket(obj)
|
||||
self.domains = response.data.map(function (obj) {
|
||||
return mapLNDomain(obj)
|
||||
})
|
||||
})
|
||||
*/
|
||||
|
||||
},
|
||||
sendFormData: function () {
|
||||
var wallet = _.findWhere(this.g.user.wallets, {
|
||||
|
@ -199,9 +198,9 @@
|
|||
var data = this.domainDialog.data
|
||||
|
||||
if (data.id) {
|
||||
this.updateForm(wallet, data)
|
||||
this.updateDomain(wallet, data)
|
||||
} else {
|
||||
this.createForm(wallet, data)
|
||||
this.createDomain(wallet, data)
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -211,7 +210,7 @@
|
|||
LNbits.api
|
||||
.request('POST', '/subdomains/api/v1/domains', wallet.inkey, data)
|
||||
.then(function (response) {
|
||||
self.forms.push(mapLNDomain(response.data))
|
||||
self.domains.push(mapLNDomain(response.data))
|
||||
self.domainDialog.show = false
|
||||
self.domainDialog.data = {}
|
||||
})
|
||||
|
@ -221,13 +220,13 @@
|
|||
|
||||
},
|
||||
updateDomainDialog: function (formId) {
|
||||
var link = _.findWhere(this.forms, {id: formId})
|
||||
var link = _.findWhere(this.domains, {id: formId})
|
||||
console.log(link.id)
|
||||
this.domainDialog.data.id = link.id
|
||||
this.domainDialog.data.wallet = link.wallet
|
||||
this.domainDialog.data.domainName = link.domainName
|
||||
this.domainDialog.data.domain = link.domain
|
||||
this.domainDialog.data.description = link.description
|
||||
this.domainDialog.domainDialog.data.cfToken = link.cfToken
|
||||
this.domainDialog.data.cfToken = link.cfToken
|
||||
this.domainDialog.cfZoneId = link.cfZoneId
|
||||
this.domainDialog.data.cost = link.cost
|
||||
this.domainDialog.show = true
|
||||
|
@ -235,51 +234,51 @@
|
|||
updateDomain: function (wallet, data) {
|
||||
var self = this
|
||||
console.log(data)
|
||||
/*
|
||||
|
||||
|
||||
LNbits.api
|
||||
.request(
|
||||
'PUT',
|
||||
'/lnticket/api/v1/forms/' + data.id,
|
||||
'/subdomains/api/v1/domains/' + data.id,
|
||||
wallet.inkey,
|
||||
data
|
||||
)
|
||||
.then(function (response) {
|
||||
self.forms = _.reject(self.forms, function (obj) {
|
||||
self.domains = _.reject(self.domains, function (obj) {
|
||||
return obj.id == data.id
|
||||
})
|
||||
self.forms.push(mapLNTicket(response.data))
|
||||
self.domains.push(mapLNDomain(response.data))
|
||||
self.domainDialog.show = false
|
||||
self.domainDialog.data = {}
|
||||
})
|
||||
.catch(function (error) {
|
||||
LNbits.utils.notifyApiError(error)
|
||||
})
|
||||
*/
|
||||
|
||||
},
|
||||
deleteDomain: function (formsId) {
|
||||
deleteDomain: function (domainId) {
|
||||
var self = this
|
||||
var forms = _.findWhere(this.forms, {id: formsId})
|
||||
/*
|
||||
var domains = _.findWhere(this.domains, {id: domainId})
|
||||
|
||||
LNbits.utils
|
||||
.confirmDialog('Are you sure you want to delete this form link?')
|
||||
.confirmDialog('Are you sure you want to delete this domain link?')
|
||||
.onOk(function () {
|
||||
LNbits.api
|
||||
.request(
|
||||
'DELETE',
|
||||
'/lnticket/api/v1/forms/' + formsId,
|
||||
_.findWhere(self.g.user.wallets, {id: forms.wallet}).inkey
|
||||
'/subdomains/api/v1/domains/' + domainId,
|
||||
_.findWhere(self.g.user.wallets, {id: domains.wallet}).inkey
|
||||
)
|
||||
.then(function (response) {
|
||||
self.forms = _.reject(self.forms, function (obj) {
|
||||
return obj.id == formsId
|
||||
self.domains = _.reject(self.domains, function (obj) {
|
||||
return obj.id == domainId
|
||||
})
|
||||
})
|
||||
.catch(function (error) {
|
||||
LNbits.utils.notifyApiError(error)
|
||||
})
|
||||
})
|
||||
*/
|
||||
|
||||
},
|
||||
exportDomainsCSV: function () {
|
||||
LNbits.utils.exportCSV(this.domainsTable.columns, this.domains)
|
||||
|
|
|
@ -6,7 +6,7 @@ from lnbits.core.crud import get_user, get_wallet
|
|||
from lnbits.core.services import create_invoice, check_invoice_status
|
||||
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
|
||||
|
||||
from . import lnsubdomain_ext
|
||||
from . import subdomains_ext
|
||||
from .crud import (
|
||||
create_subdomain,
|
||||
set_subdomain_paid,
|
||||
|
@ -24,7 +24,7 @@ from .crud import (
|
|||
# domainS
|
||||
|
||||
|
||||
@lnsubdomain_ext.route("/api/v1/domains", methods=["GET"])
|
||||
@subdomains_ext.route("/api/v1/domains", methods=["GET"])
|
||||
@api_check_wallet_key("invoice")
|
||||
async def api_domains():
|
||||
wallet_ids = [g.wallet.id]
|
||||
|
@ -35,8 +35,8 @@ async def api_domains():
|
|||
return jsonify([domain._asdict() for domain in await get_domains(wallet_ids)]), HTTPStatus.OK
|
||||
|
||||
|
||||
@lnsubdomain_ext.route("/api/v1/domains", methods=["POST"])
|
||||
@lnsubdomain_ext.route("/api/v1/domains/<domain_id>", methods=["PUT"])
|
||||
@subdomains_ext.route("/api/v1/domains", methods=["POST"])
|
||||
@subdomains_ext.route("/api/v1/domains/<domain_id>", methods=["PUT"])
|
||||
@api_check_wallet_key("invoice")
|
||||
@api_validate_post_request(
|
||||
schema={
|
||||
|
@ -65,7 +65,7 @@ async def api_domain_create(domain_id=None):
|
|||
return jsonify(domain._asdict()), HTTPStatus.CREATED
|
||||
|
||||
|
||||
@lnsubdomain_ext.route("/api/v1/domains/<domain_id>", methods=["DELETE"])
|
||||
@subdomains_ext.route("/api/v1/domains/<domain_id>", methods=["DELETE"])
|
||||
@api_check_wallet_key("invoice")
|
||||
async def api_domain_delete(domain_id):
|
||||
domain = await get_domain(domain_id)
|
||||
|
@ -84,7 +84,7 @@ async def api_domain_delete(domain_id):
|
|||
#########subdomains##########
|
||||
|
||||
|
||||
@lnsubdomain_ext.route("/api/v1/subdomains", methods=["GET"])
|
||||
@subdomains_ext.route("/api/v1/subdomains", methods=["GET"])
|
||||
@api_check_wallet_key("invoice")
|
||||
async def api_subdomains():
|
||||
wallet_ids = [g.wallet.id]
|
||||
|
@ -95,7 +95,7 @@ async def api_subdomains():
|
|||
return jsonify([domain._asdict() for domain in await get_subdomains(wallet_ids)]), HTTPStatus.OK
|
||||
|
||||
|
||||
@lnsubdomain_ext.route("/api/v1/subdomains/<domain_id>", methods=["POST"])
|
||||
@subdomains_ext.route("/api/v1/subdomains/<domain_id>", methods=["POST"])
|
||||
@api_validate_post_request(
|
||||
schema={
|
||||
"domain": {"type": "string", "empty": False, "required": True},
|
||||
|
@ -127,7 +127,7 @@ async def api_subdomain_make_subdomain(domain_id):
|
|||
return jsonify({"payment_hash": payment_hash, "payment_request": payment_request}), HTTPStatus.OK
|
||||
|
||||
|
||||
@lnsubdomain_ext.route("/api/v1/subdomains/<payment_hash>", methods=["GET"])
|
||||
@subdomains_ext.route("/api/v1/subdomains/<payment_hash>", methods=["GET"])
|
||||
async def api_subdomain_send_subdomain(payment_hash):
|
||||
subdomain = await get_subdomain(payment_hash)
|
||||
try:
|
||||
|
@ -146,7 +146,7 @@ async def api_subdomain_send_subdomain(payment_hash):
|
|||
return jsonify({"paid": False}), HTTPStatus.OK
|
||||
|
||||
|
||||
@lnsubdomain_ext.route("/api/v1/subdomains/<subdomain_id>", methods=["DELETE"])
|
||||
@subdomains_ext.route("/api/v1/subdomains/<subdomain_id>", methods=["DELETE"])
|
||||
@api_check_wallet_key("invoice")
|
||||
async def api_subdomain_delete(subdomain_id):
|
||||
subdomain = await get_subdomain(subdomain_id)
|
||||
|
|
Loading…
Reference in New Issue
Block a user