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