diff --git a/lnbits/extensions/jukebox/crud.py b/lnbits/extensions/jukebox/crud.py index 238ed083d..272d3e1a5 100644 --- a/lnbits/extensions/jukebox/crud.py +++ b/lnbits/extensions/jukebox/crud.py @@ -21,8 +21,8 @@ async def create_jukebox( juke_id = urlsafe_short_hash() result = await db.execute( """ - INSERT INTO jukebox (id, user, title, wallet, sp_user, sp_secret, sp_access_token, sp_refresh_token, sp_device, sp_playlists, price, profit) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + INSERT INTO jukebox (id, user, title, wallet, sp_user, sp_secret, sp_access_token, sp_refresh_token, sp_device, sp_playlists, price, profit, queue) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( juke_id, @@ -37,6 +37,7 @@ async def create_jukebox( sp_playlists, int(price), 0, + "[]", ), ) jukebox = await get_jukebox(juke_id) @@ -84,14 +85,17 @@ async def delete_jukebox(juke_id: str): #####################################PAYMENTS -async def create_jukebox_payment(song_id: str, payment_hash: str) -> JukeboxPayment: +async def create_jukebox_payment( + song_id: str, payment_hash: str, juke_id: str +) -> JukeboxPayment: result = await db.execute( """ - INSERT INTO jukebox_payment (payment_hash, song_id, paid) - VALUES (?, ?, ?) + INSERT INTO jukebox_payment (payment_hash, juke_id, song_id, paid) + VALUES (?, ?, ?, ?) """, ( payment_hash, + juke_id, song_id, False, ), diff --git a/lnbits/extensions/jukebox/migrations.py b/lnbits/extensions/jukebox/migrations.py index 53be21036..946620140 100644 --- a/lnbits/extensions/jukebox/migrations.py +++ b/lnbits/extensions/jukebox/migrations.py @@ -19,7 +19,7 @@ async def m001_initial(db): price INTEGER, profit INTEGER, queue TEXT, - last_checked + last_checked TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now')) ); """ ) diff --git a/lnbits/extensions/jukebox/templates/jukebox/jukebox.html b/lnbits/extensions/jukebox/templates/jukebox/jukebox.html index 1f947283e..2cafd32ad 100644 --- a/lnbits/extensions/jukebox/templates/jukebox/jukebox.html +++ b/lnbits/extensions/jukebox/templates/jukebox/jukebox.html @@ -184,7 +184,7 @@ LNbits.api .request( 'GET', - '/api/v1/jukebox/jb/invoicepaid/' + self.receive.paymentHash + '/{{ juke_id }}') + '/jukebox/api/v1/jukebox/jb/invoicep/{{ juke_id }}/' + self.receive.paymentHash) .then(function (response) { self.$q.notify({ color: 'green', diff --git a/lnbits/extensions/jukebox/views.py b/lnbits/extensions/jukebox/views.py index 23673bafd..9223a1b97 100644 --- a/lnbits/extensions/jukebox/views.py +++ b/lnbits/extensions/jukebox/views.py @@ -5,6 +5,7 @@ from http import HTTPStatus import trio from lnbits.decorators import check_user_exists, validate_uuids from lnbits.core.models import Payment +from functools import wraps import json from . import jukebox_ext diff --git a/lnbits/extensions/jukebox/views_api.py b/lnbits/extensions/jukebox/views_api.py index 72438784b..c76c35e54 100644 --- a/lnbits/extensions/jukebox/views_api.py +++ b/lnbits/extensions/jukebox/views_api.py @@ -203,32 +203,37 @@ async def api_get_jukebox_invoice(juke_id, song_id): extra={"tag": "jukebox"}, ) - jukebox_payment = await create_jukebox_payment(song_id, invoice[0]) + jukebox_payment = await create_jukebox_payment(song_id, invoice[0], juke_id) return jsonify(invoice, jukebox_payment) -@jukebox_ext.route( - "/api/v1/jukebox/jb/invoicep//", methods=["GET"] -) -async def api_get_jukebox_invoice_paid(payment_hash, juke_id): +@jukebox_ext.route("/api/v1/jukebox/jb/invoicep//", methods=["GET"]) +async def api_get_jukebox_invoice_paid(juke_id, pay_hash): jukebox = await get_jukebox(juke_id) print(jukebox) - paid = await check_invoice_status(jukebox.wallet, payment_hash) - if paid: - jukebox_payment = await update_jukebox_payment(payment_hash, paid=True) + paid = await check_invoice_status(jukebox.wallet, pay_hash) + if paid.paid: + jukebox_payment = await update_jukebox_payment(pay_hash, paid=True) else: return jsonify({"error": "Invoice not paid"}) queue = await add_to_song_queue(jukebox_payment.song_id, jukebox_payment.juke_id) return queue +@jukebox_ext.route("/api/v1/jukebox/jb/invoicep/", methods=["GET"]) +async def api_get_jukebox_invoice_cunt(cunt): + + return cunt + + ############################QUEUE SONG async def add_to_song_queue(song_id, juke_id): jukebox = await get_jukebox(juke_id) queue = jukebox.queue + print(queue[0]) queue.append(song_id) # Add song to back of queue jukebox = await update_jukebox(juke_id=juke_id, queue=queue)