mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2024-11-20 10:39:59 +01:00
refactoring & bug fixes
This commit is contained in:
parent
bd4a668d23
commit
128888be92
@ -16,14 +16,15 @@ async def create_subdomain(
|
||||
email: str,
|
||||
ip: str,
|
||||
sats: int,
|
||||
duration: int
|
||||
duration: int,
|
||||
record_type: str
|
||||
) -> Subdomains:
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO subdomain (id, domain, email, subdomain, ip, wallet, sats, duration, paid)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?,?)
|
||||
INSERT INTO subdomain (id, domain, email, subdomain, ip, wallet, sats, duration, paid, record_type)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(payment_hash, domain, email, subdomain, ip, wallet, sats, duration, False),
|
||||
(payment_hash, domain, email, subdomain, ip, wallet, sats, duration, False, record_type),
|
||||
)
|
||||
|
||||
subdomain = await get_subdomain(payment_hash)
|
||||
@ -69,7 +70,7 @@ async def set_subdomain_paid(payment_hash: str) -> Subdomains:
|
||||
url,
|
||||
headers=header,
|
||||
json={
|
||||
"type": "A",
|
||||
"type": subdomain.record_type,
|
||||
"name": aRecord,
|
||||
"content": subdomain.ip,
|
||||
"ttl": 0,
|
||||
@ -90,6 +91,7 @@ async def set_subdomain_paid(payment_hash: str) -> Subdomains:
|
||||
json={
|
||||
"domain": subdomain.domain_name,
|
||||
"subdomain": subdomain.subdomain,
|
||||
"record_type": subdomain.record_type,
|
||||
"email": subdomain.email,
|
||||
"ip": subdomain.ip,
|
||||
"cost:": str(subdomain.sats) + " sats",
|
||||
@ -128,14 +130,14 @@ async def delete_subdomain(subdomain_id: str) -> None:
|
||||
# Domains
|
||||
|
||||
|
||||
async def create_domain(*, wallet: str, domain: str, cf_token: str, cf_zone_id: str, webhook: Optional[str] = None, description: str, cost: int) -> Domains:
|
||||
async def create_domain(*, wallet: str, domain: str, cf_token: str, cf_zone_id: str, webhook: Optional[str] = None, description: str, cost: int, allowed_record_types: str) -> Domains:
|
||||
domain_id = urlsafe_short_hash()
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO domain (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, allowed_record_types)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(domain_id, wallet, domain, webhook, cf_token, cf_zone_id, description, cost, 0),
|
||||
(domain_id, wallet, domain, webhook, cf_token, cf_zone_id, description, cost, 0, allowed_record_types),
|
||||
)
|
||||
|
||||
domain = await get_domain(domain_id)
|
||||
|
@ -12,6 +12,7 @@ async def m001_initial(db):
|
||||
description TEXT NOT NULL,
|
||||
cost INTEGER NOT NULL,
|
||||
amountmade INTEGER NOT NULL,
|
||||
allowed_record_types TEXT NOT NULL,
|
||||
time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
|
||||
);
|
||||
"""
|
||||
@ -29,6 +30,7 @@ async def m001_initial(db):
|
||||
sats INTEGER NOT NULL,
|
||||
duration INTEGER NOT NULL,
|
||||
paid BOOLEAN NOT NULL,
|
||||
record_type TEXT NOT NULL,
|
||||
time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
|
||||
);
|
||||
"""
|
||||
|
@ -12,6 +12,7 @@ class Domains(NamedTuple):
|
||||
cost: int
|
||||
amountmade: int
|
||||
time: int
|
||||
allowed_record_types: str
|
||||
|
||||
|
||||
class Subdomains(NamedTuple):
|
||||
@ -26,3 +27,4 @@ class Subdomains(NamedTuple):
|
||||
duration: int
|
||||
paid: bool
|
||||
time: int
|
||||
record_type: str
|
||||
|
@ -10,15 +10,22 @@
|
||||
<q-form @submit="Invoice()" class="q-gutter-md">
|
||||
<q-input filled dense v-model.trim="formDialog.data.email" type="email"
|
||||
label="Your email (optional, if you want a reply)"></q-input>
|
||||
<q-input filled dense v-model.trim="formDialog.data.subdomain" type="text" label="subdomain you want">
|
||||
<q-select dense filled v-model="formDialog.data.record_type" :options='{{domain_allowed_record_types}}'
|
||||
label="Record type"></q-select>
|
||||
<q-input filled dense v-model.trim="formDialog.data.subdomain" type="text" label="Subdomain you want">
|
||||
</q-input>
|
||||
<q-input filled dense v-model.trim="formDialog.data.ip" type="text" label="ip of your server">
|
||||
<q-input filled dense v-model.trim="formDialog.data.ip" type="text" label="Ip of your server">
|
||||
</q-input>
|
||||
<q-input filled dense v-model.trim="formDialog.data.duration" type="number" label="{{ domain_cost }} sats per day">
|
||||
<q-input filled dense v-model.trim="formDialog.data.duration" type="number" label="Number of days">
|
||||
</q-input>
|
||||
<p>{% raw %}{{amountSats}}{% endraw %}</p>
|
||||
<p>
|
||||
Cost per day: {{ domain_cost }} sats<br />
|
||||
{% raw %}
|
||||
Total cost: {{amountSats}} sats
|
||||
{% endraw %}</p>
|
||||
<div class="row q-mt-lg">
|
||||
<q-btn unelevated color="deep-purple" :disable="formDialog.data.subdomain == '' || formDialog.data.ip == '' || formDialog.data.duration == ''"
|
||||
<q-btn unelevated color="deep-purple"
|
||||
:disable="formDialog.data.subdomain == '' || formDialog.data.ip == '' || formDialog.data.duration == ''"
|
||||
type="submit">Submit</q-btn>
|
||||
<q-btn @click="resetForm" flat color="grey" class="q-ml-auto">Cancel</q-btn>
|
||||
</div>
|
||||
@ -65,6 +72,7 @@
|
||||
subdomain: '',
|
||||
duration: '',
|
||||
email: '',
|
||||
record_type: ''
|
||||
}
|
||||
},
|
||||
receive: {
|
||||
@ -77,12 +85,8 @@
|
||||
computed: {
|
||||
amountSats() {
|
||||
var sats = this.formDialog.data.duration * parseInt('{{ domain_cost }}')
|
||||
if (sats === parseInt('{{ domain_cost }}')) {
|
||||
return '0 Sats to pay'
|
||||
} else {
|
||||
this.formDialog.data.sats = sats
|
||||
return sats + ' Sats to pay'
|
||||
}
|
||||
this.formDialog.data.sats = sats
|
||||
return sats
|
||||
}
|
||||
},
|
||||
|
||||
@ -93,6 +97,7 @@
|
||||
this.formDialog.data.email = ''
|
||||
this.formDialog.data.ip = ''
|
||||
this.formDialog.data.duration = ''
|
||||
this.formDialog.data.record_type = ''
|
||||
},
|
||||
|
||||
closeReceiveDialog: function () {
|
||||
@ -112,6 +117,7 @@
|
||||
email: self.formDialog.data.email,
|
||||
sats: self.formDialog.data.sats,
|
||||
duration: parseInt(self.formDialog.data.duration),
|
||||
record_type: self.formDialog.data.record_type
|
||||
})
|
||||
.then(function (response) {
|
||||
self.paymentReq = response.data.payment_request
|
||||
@ -147,6 +153,7 @@
|
||||
self.formDialog.data.email = ''
|
||||
self.formDialog.data.ip = ''
|
||||
self.formDialog.data.duration = ''
|
||||
self.formDialog.data.record_type = ''
|
||||
self.$q.notify({
|
||||
type: 'positive',
|
||||
message: 'Sent, thank you!',
|
||||
|
@ -117,7 +117,9 @@
|
||||
<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.domain" type="text" label="Domain name "></q-input>
|
||||
<q-select dense filled v-model="domainDialog.data.allowed_record_types" multiple :options="dnsRecordTypes"
|
||||
label="Allowed record types" ></q-select>
|
||||
<q-input filled dense emit-value v-model.trim="domainDialog.data.domain" type="text" label="Domain name "></q-input>
|
||||
<q-input filled dense v-model.trim="domainDialog.data.cf_token" type="text" label="Cloudflare API token">
|
||||
</q-input>
|
||||
<q-input filled dense v-model.trim="domainDialog.data.cf_zone_id" type="text" label="Cloudflare Zone Id">
|
||||
@ -159,10 +161,12 @@
|
||||
return {
|
||||
domains: [],
|
||||
subdomains: [],
|
||||
dnsRecordTypes: ['A', 'AAAA', 'CNAME', 'HTTPS', 'TXT', 'SRV', 'LOC', 'MX', 'NS', 'SPF', 'CERT', 'DNSKEY', 'DS', 'NAPTR', 'SMIMEA', 'SSHFP', 'SVCB', 'TLSA', 'URI'],
|
||||
domainsTable: {
|
||||
columns: [
|
||||
{ name: 'id', align: 'left', label: 'ID', field: 'id' },
|
||||
{ name: 'domain', align: 'left', label: 'Domain name', field: 'domain' },
|
||||
{ name: 'allowed_record_types', align: 'left', label: 'Allowed record types', field: 'allowed_record_types' },
|
||||
{ name: 'wallet', align: 'left', label: 'Wallet', field: 'wallet' },
|
||||
{ name: 'webhook', align: 'left', label: 'Webhook', field: 'webhook' },
|
||||
{
|
||||
@ -186,6 +190,7 @@
|
||||
columns: [
|
||||
{ name: 'subdomain', align: 'left', label: 'Subdomain name', field: 'subdomain' },
|
||||
{ name: 'domain', align: 'left', label: 'Domain name', field: 'domain_name' },
|
||||
{ name: 'record_type', align: 'left', label: 'Record type', field: 'record_type' },
|
||||
{
|
||||
name: 'email',
|
||||
align: 'left',
|
||||
@ -288,7 +293,8 @@
|
||||
id: this.domainDialog.data.wallet
|
||||
})
|
||||
var data = this.domainDialog.data
|
||||
|
||||
data.allowed_record_types = data.allowed_record_types.join(", ")
|
||||
console.log(this.domainDialog)
|
||||
if (data.id) {
|
||||
this.updateDomain(wallet, data)
|
||||
} else {
|
||||
@ -322,6 +328,7 @@
|
||||
this.domainDialog.data.cf_zone_id = link.cf_zone_id
|
||||
this.domainDialog.data.webhook = link.webhook
|
||||
this.domainDialog.data.cost = link.cost
|
||||
this.domainDialog.data.allowed_record_types = link.allowed_record_types.split(", ")
|
||||
this.domainDialog.show = true
|
||||
},
|
||||
updateDomain: function (wallet, data) {
|
||||
|
@ -17,11 +17,13 @@ async def display(domain_id):
|
||||
domain = await get_domain(domain_id)
|
||||
if not domain:
|
||||
abort(HTTPStatus.NOT_FOUND, "Domain does not exist.")
|
||||
|
||||
allowed_records = domain.allowed_record_types.replace("\"","").replace(" ","").split(",")
|
||||
print(allowed_records)
|
||||
return await render_template(
|
||||
"subdomains/display.html",
|
||||
domain_id=domain.id,
|
||||
domain_domain=domain.domain,
|
||||
domain_desc=domain.description,
|
||||
domain_cost=domain.cost,
|
||||
domain_allowed_record_types=allowed_records
|
||||
)
|
||||
|
@ -47,6 +47,7 @@ async def api_domains():
|
||||
"webhook": {"type": "string", "empty": False, "required": False},
|
||||
"description": {"type": "string", "min": 0, "required": True},
|
||||
"cost": {"type": "integer", "min": 0, "required": True},
|
||||
"allowed_record_types": {"type": "string", "required": True},
|
||||
}
|
||||
)
|
||||
async def api_domain_create(domain_id=None):
|
||||
@ -104,6 +105,7 @@ async def api_subdomains():
|
||||
"ip": {"type": "string", "empty": False, "required": True},
|
||||
"sats": {"type": "integer", "min": 0, "required": True},
|
||||
"duration": {"type": "integer", "empty": False, "required": True},
|
||||
"record_type": {"type": "string", "empty": False, "required": True},
|
||||
}
|
||||
)
|
||||
async def api_subdomain_make_subdomain(domain_id):
|
||||
|
Loading…
Reference in New Issue
Block a user