Merge remote-tracking branch 'origin/main' into SCRUB
This commit is contained in:
commit
b0db8d8f5a
3 changed files with 33 additions and 12 deletions
|
|
@ -30,7 +30,7 @@ async def api_lnurl_response(request: Request, unique_hash):
|
||||||
)
|
)
|
||||||
|
|
||||||
if link.is_spent:
|
if link.is_spent:
|
||||||
raise HTTPException(detail="Withdraw is spent.")
|
raise HTTPException(status_code=HTTPStatus.NOT_FOUND, detail="Withdraw is spent.")
|
||||||
url = request.url_for("withdraw.api_lnurl_callback", unique_hash=link.unique_hash)
|
url = request.url_for("withdraw.api_lnurl_callback", unique_hash=link.unique_hash)
|
||||||
withdrawResponse = {
|
withdrawResponse = {
|
||||||
"tag": "withdrawRequest",
|
"tag": "withdrawRequest",
|
||||||
|
|
@ -48,7 +48,7 @@ async def api_lnurl_response(request: Request, unique_hash):
|
||||||
|
|
||||||
@withdraw_ext.get("/api/v1/lnurl/cb/{unique_hash}", name="withdraw.api_lnurl_callback")
|
@withdraw_ext.get("/api/v1/lnurl/cb/{unique_hash}", name="withdraw.api_lnurl_callback")
|
||||||
async def api_lnurl_callback(
|
async def api_lnurl_callback(
|
||||||
unique_hash, request: Request, k1: str = Query(...), pr: str = Query(...)
|
unique_hash, request: Request, k1: str = Query(...), pr: str = Query(...), id_unique_hash=None
|
||||||
):
|
):
|
||||||
link = await get_withdraw_link_by_hash(unique_hash)
|
link = await get_withdraw_link_by_hash(unique_hash)
|
||||||
now = int(datetime.now().timestamp())
|
now = int(datetime.now().timestamp())
|
||||||
|
|
@ -58,21 +58,36 @@ async def api_lnurl_callback(
|
||||||
)
|
)
|
||||||
|
|
||||||
if link.is_spent:
|
if link.is_spent:
|
||||||
raise HTTPException(status_code=HTTPStatus.OK, detail="Withdraw is spent.")
|
raise HTTPException(status_code=HTTPStatus.NOT_FOUND, detail="Withdraw is spent.")
|
||||||
|
|
||||||
if link.k1 != k1:
|
if link.k1 != k1:
|
||||||
raise HTTPException(status_code=HTTPStatus.OK, detail="Bad request.")
|
raise HTTPException(status_code=HTTPStatus.NOT_FOUND, detail="Bad request.")
|
||||||
|
|
||||||
if now < link.open_time:
|
if now < link.open_time:
|
||||||
return {"status": "ERROR", "reason": f"Wait {link.open_time - now} seconds."}
|
return {"status": "ERROR", "reason": f"Wait {link.open_time - now} seconds."}
|
||||||
|
|
||||||
|
usescsv = ""
|
||||||
try:
|
try:
|
||||||
usescsv = ""
|
|
||||||
for x in range(1, link.uses - link.used):
|
for x in range(1, link.uses - link.used):
|
||||||
usecv = link.usescsv.split(",")
|
usecv = link.usescsv.split(",")
|
||||||
usescsv += "," + str(usecv[x])
|
usescsv += "," + str(usecv[x])
|
||||||
usecsvback = usescsv
|
usecsvback = usescsv
|
||||||
usescsv = usescsv[1:]
|
|
||||||
|
found = False
|
||||||
|
if id_unique_hash is not None:
|
||||||
|
useslist = link.usescsv.split(",")
|
||||||
|
for ind, x in enumerate(useslist):
|
||||||
|
tohash = link.id + link.unique_hash + str(x)
|
||||||
|
if id_unique_hash == shortuuid.uuid(name=tohash):
|
||||||
|
found = True
|
||||||
|
useslist.pop(ind)
|
||||||
|
usescsv = ','.join(useslist)
|
||||||
|
if not found:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.NOT_FOUND, detail="LNURL-withdraw not found."
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
usescsv = usescsv[1:]
|
||||||
|
|
||||||
changesback = {
|
changesback = {
|
||||||
"open_time": link.wait_time,
|
"open_time": link.wait_time,
|
||||||
|
|
@ -115,11 +130,11 @@ async def api_lnurl_multi_response(request: Request, unique_hash, id_unique_hash
|
||||||
|
|
||||||
if not link:
|
if not link:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.OK, detail="LNURL-withdraw not found."
|
status_code=HTTPStatus.NOT_FOUND, detail="LNURL-withdraw not found."
|
||||||
)
|
)
|
||||||
|
|
||||||
if link.is_spent:
|
if link.is_spent:
|
||||||
raise HTTPException(status_code=HTTPStatus.OK, detail="Withdraw is spent.")
|
raise HTTPException(status_code=HTTPStatus.NOT_FOUND, detail="Withdraw is spent.")
|
||||||
|
|
||||||
useslist = link.usescsv.split(",")
|
useslist = link.usescsv.split(",")
|
||||||
found = False
|
found = False
|
||||||
|
|
@ -127,15 +142,16 @@ async def api_lnurl_multi_response(request: Request, unique_hash, id_unique_hash
|
||||||
tohash = link.id + link.unique_hash + str(x)
|
tohash = link.id + link.unique_hash + str(x)
|
||||||
if id_unique_hash == shortuuid.uuid(name=tohash):
|
if id_unique_hash == shortuuid.uuid(name=tohash):
|
||||||
found = True
|
found = True
|
||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.OK, detail="LNURL-withdraw not found."
|
status_code=HTTPStatus.NOT_FOUND, detail="LNURL-withdraw not found."
|
||||||
)
|
)
|
||||||
|
|
||||||
url = request.url_for("withdraw.api_lnurl_callback", unique_hash=link.unique_hash)
|
url = request.url_for("withdraw.api_lnurl_callback", unique_hash=link.unique_hash)
|
||||||
withdrawResponse = {
|
withdrawResponse = {
|
||||||
"tag": "withdrawRequest",
|
"tag": "withdrawRequest",
|
||||||
"callback": url,
|
"callback": url + "?id_unique_hash=" + id_unique_hash,
|
||||||
"k1": link.k1,
|
"k1": link.k1,
|
||||||
"minWithdrawable": link.min_withdrawable * 1000,
|
"minWithdrawable": link.min_withdrawable * 1000,
|
||||||
"maxWithdrawable": link.max_withdrawable * 1000,
|
"maxWithdrawable": link.max_withdrawable * 1000,
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@
|
||||||
<q-input filled dense v-model.trim="formDialog.data.title" type="text" label="Link title *"></q-input>
|
<q-input filled dense v-model.trim="formDialog.data.title" type="text" label="Link title *"></q-input>
|
||||||
<q-input filled dense v-model.number="formDialog.data.min_withdrawable" type="number" min="10" label="Min withdrawable (sat, at least 10) *"></q-input>
|
<q-input filled dense v-model.number="formDialog.data.min_withdrawable" type="number" min="10" label="Min withdrawable (sat, at least 10) *"></q-input>
|
||||||
<q-input filled dense v-model.number="formDialog.data.max_withdrawable" type="number" min="10" label="Max withdrawable (sat, at least 10) *"></q-input>
|
<q-input filled dense v-model.number="formDialog.data.max_withdrawable" type="number" min="10" label="Max withdrawable (sat, at least 10) *"></q-input>
|
||||||
<q-input filled dense v-model.number="formDialog.data.uses" type="number" :default="1" label="Amount of uses *"></q-input>
|
<q-input filled dense v-model.number="formDialog.data.uses" type="number" max="250" :default="1" label="Amount of uses *"></q-input>
|
||||||
<div class="row q-col-gutter-none">
|
<div class="row q-col-gutter-none">
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<q-input filled dense v-model.number="formDialog.data.wait_time" type="number" :default="1" label="Time between withdrawals *">
|
<q-input filled dense v-model.number="formDialog.data.wait_time" type="number" :default="1" label="Time between withdrawals *">
|
||||||
|
|
@ -180,7 +180,7 @@
|
||||||
<q-select filled dense emit-value v-model="simpleformDialog.data.wallet" :options="g.user.walletOptions" label="Wallet *">
|
<q-select filled dense emit-value v-model="simpleformDialog.data.wallet" :options="g.user.walletOptions" label="Wallet *">
|
||||||
</q-select>
|
</q-select>
|
||||||
<q-input filled dense v-model.number="simpleformDialog.data.max_withdrawable" type="number" min="10" label="Withdraw amount per voucher (sat, at least 10)"></q-input>
|
<q-input filled dense v-model.number="simpleformDialog.data.max_withdrawable" type="number" min="10" label="Withdraw amount per voucher (sat, at least 10)"></q-input>
|
||||||
<q-input filled dense v-model.number="simpleformDialog.data.uses" type="number" :default="1" label="Number of vouchers"></q-input>
|
<q-input filled dense v-model.number="simpleformDialog.data.uses" type="number" max="250" :default="1" label="Number of vouchers"></q-input>
|
||||||
|
|
||||||
<div class="row q-mt-lg">
|
<div class="row q-mt-lg">
|
||||||
<q-btn unelevated color="primary" :disable="
|
<q-btn unelevated color="primary" :disable="
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,11 @@ async def api_link_create_or_update(
|
||||||
link_id: str = None,
|
link_id: str = None,
|
||||||
wallet: WalletTypeInfo = Depends(require_admin_key),
|
wallet: WalletTypeInfo = Depends(require_admin_key),
|
||||||
):
|
):
|
||||||
|
if data.uses > 250:
|
||||||
|
raise HTTPException(
|
||||||
|
detail="250 uses max.", status_code=HTTPStatus.BAD_REQUEST
|
||||||
|
)
|
||||||
|
|
||||||
if data.min_withdrawable < 1:
|
if data.min_withdrawable < 1:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
detail="Min must be more than 1.", status_code=HTTPStatus.BAD_REQUEST
|
detail="Min must be more than 1.", status_code=HTTPStatus.BAD_REQUEST
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue