clean up
This commit is contained in:
parent
c90cf6ee1b
commit
73b8bd682c
5 changed files with 9 additions and 121 deletions
|
|
@ -6,7 +6,7 @@ from . import db
|
|||
from .models import CreateScrubLink, ScrubLink
|
||||
|
||||
|
||||
async def create_scrub_link(wallet_id: str, data: CreateScrubLink) -> ScrubLink:
|
||||
async def create_scrub_link(data: CreateScrubLink) -> ScrubLink:
|
||||
scrub_id = urlsafe_short_hash()
|
||||
await db.execute(
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,47 +0,0 @@
|
|||
{% extends "public.html" %} {% block page %}
|
||||
<div class="row q-col-gutter-md justify-center">
|
||||
<div class="col-12 col-sm-6 col-md-5 col-lg-4">
|
||||
<q-card class="q-pa-lg">
|
||||
<q-card-section class="q-pa-none">
|
||||
<div class="text-center">
|
||||
<a href="lightning:{{ lnurl }}">
|
||||
<q-responsive :ratio="1" class="q-mx-md">
|
||||
<qrcode
|
||||
value="{{ lnurl }}"
|
||||
:options="{width: 800}"
|
||||
class="rounded-borders"
|
||||
></qrcode>
|
||||
</q-responsive>
|
||||
</a>
|
||||
</div>
|
||||
<div class="row q-mt-lg">
|
||||
<q-btn outline color="grey" @click="copyText('{{ lnurl }}')"
|
||||
>Copy LNURL</q-btn
|
||||
>
|
||||
</div>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
</div>
|
||||
<div class="col-12 col-sm-6 col-md-5 col-lg-4 q-gutter-y-md">
|
||||
<q-card>
|
||||
<q-card-section>
|
||||
<h6 class="text-subtitle1 q-mb-sm q-mt-none">LNbits LNURL-pay link</h6>
|
||||
<p class="q-my-none">Use an LNURL compatible bitcoin wallet to pay.</p>
|
||||
</q-card-section>
|
||||
<q-card-section class="q-pa-none">
|
||||
<q-separator></q-separator>
|
||||
<q-list> {% include "scrub/_lnurl.html" %} </q-list>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %} {% block scripts %}
|
||||
<script>
|
||||
Vue.component(VueQrcode.name, VueQrcode)
|
||||
|
||||
new Vue({
|
||||
el: '#vue',
|
||||
mixins: [windowMixin]
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
{% extends "print.html" %} {% block page %}
|
||||
<div class="row justify-center">
|
||||
<div class="qr">
|
||||
<qrcode value="{{ lnurl }}" :options="{width}"></qrcode>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %} {% block styles %}
|
||||
<style>
|
||||
.qr {
|
||||
margin: auto;
|
||||
}
|
||||
</style>
|
||||
{% endblock %} {% block scripts %}
|
||||
<script>
|
||||
Vue.component(VueQrcode.name, VueQrcode)
|
||||
|
||||
new Vue({
|
||||
el: '#vue',
|
||||
created: function () {
|
||||
window.print()
|
||||
},
|
||||
data: function () {
|
||||
return {width: window.innerWidth * 0.5}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
@ -1,16 +1,12 @@
|
|||
from http import HTTPStatus
|
||||
|
||||
from fastapi import Request
|
||||
from fastapi.params import Depends
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from starlette.exceptions import HTTPException
|
||||
from starlette.responses import HTMLResponse
|
||||
|
||||
from lnbits.core.models import User
|
||||
from lnbits.decorators import check_user_exists
|
||||
|
||||
from . import scrub_ext, scrub_renderer
|
||||
from .crud import get_scrub_link
|
||||
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
|
||||
|
|
@ -20,25 +16,3 @@ async def index(request: Request, user: User = Depends(check_user_exists)):
|
|||
return scrub_renderer().TemplateResponse(
|
||||
"scrub/index.html", {"request": request, "user": user.dict()}
|
||||
)
|
||||
|
||||
# DO WE NEED THIS ?!
|
||||
@scrub_ext.get("/{link_id}", response_class=HTMLResponse)
|
||||
async def display(request: Request, link_id):
|
||||
link = await get_scrub_link(link_id)
|
||||
if not link:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="Scrub link does not exist."
|
||||
)
|
||||
ctx = {"request": request, "lnurl": link.lnurl(req=request)}
|
||||
return scrub_renderer().TemplateResponse("scrub/display.html", ctx)
|
||||
|
||||
# DO WE NEED THIS ?!
|
||||
@scrub_ext.get("/print/{link_id}", response_class=HTMLResponse)
|
||||
async def print_qr(request: Request, link_id):
|
||||
link = await get_scrub_link(link_id)
|
||||
if not link:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="Scrub link does not exist."
|
||||
)
|
||||
ctx = {"request": request, "lnurl": link.lnurl(req=request)}
|
||||
return scrub_renderer().TemplateResponse("scrub/print_qr.html", ctx)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ from .crud import (
|
|||
delete_scrub_link,
|
||||
get_scrub_link,
|
||||
get_scrub_links,
|
||||
unique_scrubed_wallet,
|
||||
update_scrub_link,
|
||||
)
|
||||
from .models import CreateScrubLink
|
||||
|
|
@ -44,25 +45,6 @@ async def api_links(
|
|||
)
|
||||
|
||||
|
||||
@scrub_ext.get("/api/v1/links/{link_id}", status_code=HTTPStatus.OK)
|
||||
async def api_link_retrieve(
|
||||
r: Request, link_id, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||
):
|
||||
link = await get_scrub_link(link_id)
|
||||
|
||||
if not link:
|
||||
raise HTTPException(
|
||||
detail="Scrub link does not exist.", status_code=HTTPStatus.NOT_FOUND
|
||||
)
|
||||
|
||||
if link.wallet != wallet.wallet.id:
|
||||
raise HTTPException(
|
||||
detail="Not your pay link.", status_code=HTTPStatus.FORBIDDEN
|
||||
)
|
||||
|
||||
return {**link.dict(), **{"lnurl": link.lnurl(r)}}
|
||||
|
||||
|
||||
@scrub_ext.post("/api/v1/links", status_code=HTTPStatus.CREATED)
|
||||
@scrub_ext.put("/api/v1/links/{link_id}", status_code=HTTPStatus.OK)
|
||||
async def api_scrub_create_or_update(
|
||||
|
|
@ -85,7 +67,13 @@ async def api_scrub_create_or_update(
|
|||
|
||||
link = await update_scrub_link(**data.dict(), link_id=link_id)
|
||||
else:
|
||||
link = await create_scrub_link(wallet_id=wallet.wallet.id, data=data)
|
||||
wallet_has_scrub = await unique_scrubed_wallet(wallet_id=data.wallet)
|
||||
print("HAS", wallet_has_scrub)
|
||||
if wallet_has_scrub > 0:
|
||||
raise HTTPException(
|
||||
detail="Wallet is already being Scrubbed", status_code=HTTPStatus.FORBIDDEN
|
||||
)
|
||||
link = await create_scrub_link(data=data)
|
||||
|
||||
return link
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue