mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-21 22:11:59 +01:00
jukebox working(ish)
This commit is contained in:
parent
a33b24d6dc
commit
cace0892f2
8 changed files with 149 additions and 177 deletions
|
@ -1,22 +1,13 @@
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from . import db
|
from . import db
|
||||||
from .models import Jukebox, JukeboxPayment
|
from .models import Jukebox, JukeboxPayment, CreateJukeLinkData
|
||||||
from lnbits.helpers import urlsafe_short_hash
|
from lnbits.helpers import urlsafe_short_hash
|
||||||
|
|
||||||
|
|
||||||
async def create_jukebox(
|
async def create_jukebox(
|
||||||
inkey: str,
|
data: CreateJukeLinkData,
|
||||||
user: str,
|
inkey: Optional[str] = "",
|
||||||
wallet: str,
|
|
||||||
title: str,
|
|
||||||
price: int,
|
|
||||||
sp_user: str,
|
|
||||||
sp_secret: str,
|
|
||||||
sp_access_token: Optional[str] = "",
|
|
||||||
sp_refresh_token: Optional[str] = "",
|
|
||||||
sp_device: Optional[str] = "",
|
|
||||||
sp_playlists: Optional[str] = "",
|
|
||||||
) -> Jukebox:
|
) -> Jukebox:
|
||||||
juke_id = urlsafe_short_hash()
|
juke_id = urlsafe_short_hash()
|
||||||
result = await db.execute(
|
result = await db.execute(
|
||||||
|
@ -26,16 +17,16 @@ async def create_jukebox(
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
juke_id,
|
juke_id,
|
||||||
user,
|
data.user,
|
||||||
title,
|
data.title,
|
||||||
wallet,
|
data.wallet,
|
||||||
sp_user,
|
data.sp_user,
|
||||||
sp_secret,
|
data.sp_secret,
|
||||||
sp_access_token,
|
data.sp_access_token,
|
||||||
sp_refresh_token,
|
data.sp_refresh_token,
|
||||||
sp_device,
|
data.sp_device,
|
||||||
sp_playlists,
|
data.sp_playlists,
|
||||||
int(price),
|
data.price,
|
||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -44,11 +35,15 @@ async def create_jukebox(
|
||||||
return jukebox
|
return jukebox
|
||||||
|
|
||||||
|
|
||||||
async def update_jukebox(juke_id: str, **kwargs) -> Optional[Jukebox]:
|
async def update_jukebox(
|
||||||
q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()])
|
data: CreateJukeLinkData, juke_id: Optional[str] = ""
|
||||||
await db.execute(
|
) -> Optional[Jukebox]:
|
||||||
f"UPDATE jukebox.jukebox SET {q} WHERE id = ?", (*kwargs.values(), juke_id)
|
q = ", ".join([f"{field[0]} = ?" for field in data])
|
||||||
)
|
items = [f"{field[1]}" for field in data]
|
||||||
|
items.append(juke_id)
|
||||||
|
print(q)
|
||||||
|
print(items)
|
||||||
|
await db.execute(f"UPDATE jukebox.jukebox SET {q} WHERE id = ?", (items))
|
||||||
row = await db.fetchone("SELECT * FROM jukebox.jukebox WHERE id = ?", (juke_id,))
|
row = await db.fetchone("SELECT * FROM jukebox.jukebox WHERE id = ?", (juke_id,))
|
||||||
return Jukebox(**row) if row else None
|
return Jukebox(**row) if row else None
|
||||||
|
|
||||||
|
@ -66,10 +61,13 @@ async def get_jukebox_by_user(user: str) -> Optional[Jukebox]:
|
||||||
async def get_jukeboxs(user: str) -> List[Jukebox]:
|
async def get_jukeboxs(user: str) -> List[Jukebox]:
|
||||||
rows = await db.fetchall("SELECT * FROM jukebox.jukebox WHERE user = ?", (user,))
|
rows = await db.fetchall("SELECT * FROM jukebox.jukebox WHERE user = ?", (user,))
|
||||||
for row in rows:
|
for row in rows:
|
||||||
if row.sp_playlists == "":
|
|
||||||
|
if row.sp_playlists == None:
|
||||||
|
print("cunt")
|
||||||
await delete_jukebox(row.id)
|
await delete_jukebox(row.id)
|
||||||
rows = await db.fetchall("SELECT * FROM jukebox.jukebox WHERE user = ?", (user,))
|
rows = await db.fetchall("SELECT * FROM jukebox.jukebox WHERE user = ?", (user,))
|
||||||
return [Jukebox.from_row(row) for row in rows]
|
|
||||||
|
return [Jukebox(**row) for row in rows]
|
||||||
|
|
||||||
|
|
||||||
async def delete_jukebox(juke_id: str):
|
async def delete_jukebox(juke_id: str):
|
||||||
|
|
|
@ -2,6 +2,8 @@ from typing import NamedTuple
|
||||||
from sqlite3 import Row
|
from sqlite3 import Row
|
||||||
from fastapi.param_functions import Query
|
from fastapi.param_functions import Query
|
||||||
from pydantic.main import BaseModel
|
from pydantic.main import BaseModel
|
||||||
|
from pydantic import BaseModel
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
class CreateJukeLinkData(BaseModel):
|
class CreateJukeLinkData(BaseModel):
|
||||||
|
@ -17,32 +19,24 @@ class CreateJukeLinkData(BaseModel):
|
||||||
price: str = Query(None)
|
price: str = Query(None)
|
||||||
|
|
||||||
|
|
||||||
class Jukebox(NamedTuple):
|
class Jukebox(BaseModel):
|
||||||
id: str
|
id: Optional[str]
|
||||||
user: str
|
user: Optional[str]
|
||||||
title: str
|
title: Optional[str]
|
||||||
wallet: str
|
wallet: Optional[str]
|
||||||
inkey: str
|
inkey: Optional[str]
|
||||||
sp_user: str
|
sp_user: Optional[str]
|
||||||
sp_secret: str
|
sp_secret: Optional[str]
|
||||||
sp_access_token: str
|
sp_access_token: Optional[str]
|
||||||
sp_refresh_token: str
|
sp_refresh_token: Optional[str]
|
||||||
sp_device: str
|
sp_device: Optional[str]
|
||||||
sp_playlists: str
|
sp_playlists: Optional[str]
|
||||||
price: int
|
price: Optional[int]
|
||||||
profit: int
|
profit: Optional[int]
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_row(cls, row: Row) -> "Jukebox":
|
|
||||||
return cls(**dict(row))
|
|
||||||
|
|
||||||
|
|
||||||
class JukeboxPayment(NamedTuple):
|
class JukeboxPayment(BaseModel):
|
||||||
payment_hash: str
|
payment_hash: str
|
||||||
juke_id: str
|
juke_id: str
|
||||||
song_id: str
|
song_id: str
|
||||||
paid: bool
|
paid: bool
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_row(cls, row: Row) -> "JukeboxPayment":
|
|
||||||
return cls(**dict(row))
|
|
||||||
|
|
|
@ -3,17 +3,25 @@
|
||||||
Vue.component(VueQrcode.name, VueQrcode)
|
Vue.component(VueQrcode.name, VueQrcode)
|
||||||
|
|
||||||
var mapJukebox = obj => {
|
var mapJukebox = obj => {
|
||||||
obj._data = _.clone(obj)
|
if(obj.sp_device){
|
||||||
obj.sp_id = obj.id
|
obj._data = _.clone(obj)
|
||||||
obj.device = obj.sp_device.split('-')[0]
|
|
||||||
playlists = obj.sp_playlists.split(',')
|
obj.sp_id = obj._data.id
|
||||||
var i
|
obj.device = obj._data.sp_device.split('-')[0]
|
||||||
playlistsar = []
|
playlists = obj._data.sp_playlists.split(',')
|
||||||
for (i = 0; i < playlists.length; i++) {
|
var i
|
||||||
playlistsar.push(playlists[i].split('-')[0])
|
playlistsar = []
|
||||||
|
for (i = 0; i < playlists.length; i++) {
|
||||||
|
playlistsar.push(playlists[i].split('-')[0])
|
||||||
|
}
|
||||||
|
obj.playlist = playlistsar.join()
|
||||||
|
console.log(obj)
|
||||||
|
return obj
|
||||||
}
|
}
|
||||||
obj.playlist = playlistsar.join()
|
else {
|
||||||
return obj
|
return
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
new Vue({
|
new Vue({
|
||||||
|
@ -79,13 +87,14 @@ new Vue({
|
||||||
var link = _.findWhere(this.JukeboxLinks, {id: linkId})
|
var link = _.findWhere(this.JukeboxLinks, {id: linkId})
|
||||||
|
|
||||||
this.qrCodeDialog.data = _.clone(link)
|
this.qrCodeDialog.data = _.clone(link)
|
||||||
console.log(this.qrCodeDialog.data)
|
|
||||||
this.qrCodeDialog.data.url =
|
this.qrCodeDialog.data.url =
|
||||||
window.location.protocol + '//' + window.location.host
|
window.location.protocol + '//' + window.location.host
|
||||||
this.qrCodeDialog.show = true
|
this.qrCodeDialog.show = true
|
||||||
},
|
},
|
||||||
getJukeboxes() {
|
getJukeboxes() {
|
||||||
self = this
|
self = this
|
||||||
|
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'GET',
|
'GET',
|
||||||
|
@ -93,10 +102,11 @@ new Vue({
|
||||||
self.g.user.wallets[0].adminkey
|
self.g.user.wallets[0].adminkey
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
self.JukeboxLinks = response.data.map(mapJukebox)
|
self.JukeboxLinks = response.data.map(function (obj) {
|
||||||
})
|
|
||||||
.catch(err => {
|
return mapJukebox(obj)
|
||||||
LNbits.utils.notifyApiError(err)
|
})
|
||||||
|
console.log(self.JukeboxLinks)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
deleteJukebox(juke_id) {
|
deleteJukebox(juke_id) {
|
||||||
|
@ -125,7 +135,6 @@ new Vue({
|
||||||
self = this
|
self = this
|
||||||
var link = _.findWhere(self.JukeboxLinks, {id: linkId})
|
var link = _.findWhere(self.JukeboxLinks, {id: linkId})
|
||||||
self.jukeboxDialog.data = _.clone(link._data)
|
self.jukeboxDialog.data = _.clone(link._data)
|
||||||
console.log(this.jukeboxDialog.data.sp_access_token)
|
|
||||||
|
|
||||||
self.refreshDevices()
|
self.refreshDevices()
|
||||||
self.refreshPlaylists()
|
self.refreshPlaylists()
|
||||||
|
@ -145,7 +154,7 @@ new Vue({
|
||||||
submitSpotifyKeys() {
|
submitSpotifyKeys() {
|
||||||
self = this
|
self = this
|
||||||
self.jukeboxDialog.data.user = self.g.user.id
|
self.jukeboxDialog.data.user = self.g.user.id
|
||||||
|
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'POST',
|
'POST',
|
||||||
|
@ -193,9 +202,6 @@ new Vue({
|
||||||
if (self.jukeboxDialog.data.sp_access_token) {
|
if (self.jukeboxDialog.data.sp_access_token) {
|
||||||
self.refreshPlaylists()
|
self.refreshPlaylists()
|
||||||
self.refreshDevices()
|
self.refreshDevices()
|
||||||
console.log('this.devices')
|
|
||||||
console.log(self.devices)
|
|
||||||
console.log('this.devices')
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
if (self.devices.length < 1 || self.playlists.length < 1) {
|
if (self.devices.length < 1 || self.playlists.length < 1) {
|
||||||
self.$q.notify({
|
self.$q.notify({
|
||||||
|
@ -259,16 +265,14 @@ new Vue({
|
||||||
},
|
},
|
||||||
updateDB() {
|
updateDB() {
|
||||||
self = this
|
self = this
|
||||||
console.log(self.jukeboxDialog.data)
|
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'PUT',
|
'PUT',
|
||||||
'/jukebox/api/v1/jukebox/' + this.jukeboxDialog.data.sp_id,
|
'/jukebox/api/v1/jukebox/' + self.jukeboxDialog.data.sp_id,
|
||||||
self.g.user.wallets[0].adminkey,
|
self.g.user.wallets[0].adminkey,
|
||||||
self.jukeboxDialog.data
|
self.jukeboxDialog.data
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
console.log(response.data)
|
|
||||||
if (
|
if (
|
||||||
self.jukeboxDialog.data.sp_playlists &&
|
self.jukeboxDialog.data.sp_playlists &&
|
||||||
self.jukeboxDialog.data.sp_devices
|
self.jukeboxDialog.data.sp_devices
|
||||||
|
@ -307,7 +311,6 @@ new Vue({
|
||||||
responseObj.items[i].name + '-' + responseObj.items[i].id
|
responseObj.items[i].name + '-' + responseObj.items[i].id
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
console.log(self.playlists)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
refreshPlaylists() {
|
refreshPlaylists() {
|
||||||
|
@ -372,13 +375,6 @@ new Vue({
|
||||||
},
|
},
|
||||||
callAuthorizationApi(body) {
|
callAuthorizationApi(body) {
|
||||||
self = this
|
self = this
|
||||||
console.log(
|
|
||||||
btoa(
|
|
||||||
self.jukeboxDialog.data.sp_user +
|
|
||||||
':' +
|
|
||||||
self.jukeboxDialog.data.sp_secret
|
|
||||||
)
|
|
||||||
)
|
|
||||||
let xhr = new XMLHttpRequest()
|
let xhr = new XMLHttpRequest()
|
||||||
xhr.open('POST', 'https://accounts.spotify.com/api/token', true)
|
xhr.open('POST', 'https://accounts.spotify.com/api/token', true)
|
||||||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
|
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
|
||||||
|
@ -403,7 +399,6 @@ new Vue({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
console.log(this.g.user.wallets[0])
|
|
||||||
var getJukeboxes = this.getJukeboxes
|
var getJukeboxes = this.getJukeboxes
|
||||||
getJukeboxes()
|
getJukeboxes()
|
||||||
this.selectedWallet = this.g.user.wallets[0]
|
this.selectedWallet = this.g.user.wallets[0]
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
/* globals Quasar, Vue, _, VueQrcode, windowMixin, LNbits, LOCALE */
|
|
||||||
|
|
||||||
Vue.component(VueQrcode.name, VueQrcode)
|
|
||||||
|
|
||||||
new Vue({
|
|
||||||
el: '#vue',
|
|
||||||
mixins: [windowMixin],
|
|
||||||
data() {
|
|
||||||
return {}
|
|
||||||
},
|
|
||||||
computed: {},
|
|
||||||
methods: {},
|
|
||||||
created() {}
|
|
||||||
})
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% extends "public.html" %} {% block page %} {% raw %}
|
{% extends "public.html" %} {% block page %}
|
||||||
<div class="row q-col-gutter-md justify-center">
|
<div class="row q-col-gutter-md justify-center">
|
||||||
<div class="col-12 col-sm-6 col-md-5 col-lg-4">
|
<div class="col-12 col-sm-6 col-md-5 col-lg-4">
|
||||||
<q-card class="q-pa-lg">
|
<q-card class="q-pa-lg">
|
||||||
|
@ -9,10 +9,12 @@
|
||||||
<img style="width: 100px" :src="currentPlay.image" />
|
<img style="width: 100px" :src="currentPlay.image" />
|
||||||
</div>
|
</div>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
|
{% raw %}
|
||||||
<strong style="font-size: 20px">{{ currentPlay.name }}</strong
|
<strong style="font-size: 20px">{{ currentPlay.name }}</strong
|
||||||
><br />
|
><br />
|
||||||
<strong style="font-size: 15px">{{ currentPlay.artist }}</strong>
|
<strong style="font-size: 15px">{{ currentPlay.artist }}</strong>
|
||||||
</div>
|
</div>
|
||||||
|
{% endraw %}
|
||||||
</div>
|
</div>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
@ -46,7 +48,7 @@
|
||||||
>
|
>
|
||||||
<q-item-section>
|
<q-item-section>
|
||||||
<q-item-label>
|
<q-item-label>
|
||||||
{{ item.name }} - ({{ item.artist }})
|
{% raw %} {{ item.name }} - ({{ item.artist }}){% endraw %}
|
||||||
</q-item-label>
|
</q-item-label>
|
||||||
</q-item-section>
|
</q-item-section>
|
||||||
</q-item>
|
</q-item>
|
||||||
|
@ -54,49 +56,48 @@
|
||||||
</q-virtual-scroll>
|
</q-virtual-scroll>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
</div>
|
|
||||||
|
|
||||||
<q-dialog v-model="receive.dialogues.first" position="top">
|
<q-dialog v-model="receive.dialogues.first" position="top">
|
||||||
<q-card class="q-pa-lg lnbits__dialog-card">
|
<q-card class="q-pa-lg lnbits__dialog-card">
|
||||||
<q-card-section class="q-pa-none">
|
<q-card-section class="q-pa-none">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
<img style="width: 100px" :src="receive.image" />
|
<img style="width: 100px" :src="receive.image" />
|
||||||
</div>
|
</div>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<strong style="font-size: 20px">{{ receive.name }}</strong><br />
|
{% raw %}
|
||||||
<strong style="font-size: 15px">{{ receive.artist }}</strong>
|
<strong style="font-size: 20px">{{ receive.name }}</strong><br />
|
||||||
|
<strong style="font-size: 15px">{{ receive.artist }}</strong>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</q-card-section>
|
||||||
|
<br />
|
||||||
|
<div class="row q-mt-lg q-gutter-sm">
|
||||||
|
<q-btn outline color="grey" @click="getInvoice(receive.id)"
|
||||||
|
>Play for {% endraw %}{{ price }}sats
|
||||||
|
</q-btn>
|
||||||
</div>
|
</div>
|
||||||
</q-card-section>
|
</q-card>
|
||||||
<br />
|
</q-dialog>
|
||||||
<div class="row q-mt-lg q-gutter-sm">
|
<q-dialog v-model="receive.dialogues.second" position="top">
|
||||||
<q-btn outline color="grey" @click="getInvoice(receive.id)"
|
<q-card class="q-pa-lg lnbits__dialog-card">
|
||||||
>Play for {% endraw %}{{ price }}{% raw %} sats
|
<q-responsive :ratio="1" class="q-mx-xl q-mb-md">
|
||||||
</q-btn>
|
<qrcode
|
||||||
</div>
|
:value="'lightning:' + receive.paymentReq"
|
||||||
</q-card>
|
:options="{width: 800}"
|
||||||
</q-dialog>
|
class="rounded-borders"
|
||||||
<q-dialog v-model="receive.dialogues.second" position="top">
|
></qrcode>
|
||||||
<q-card class="q-pa-lg lnbits__dialog-card">
|
</q-responsive>
|
||||||
<q-responsive :ratio="1" class="q-mx-xl q-mb-md">
|
<div class="row q-mt-lg q-gutter-sm">
|
||||||
<qrcode
|
<q-btn outline color="grey" @click="copyText(receive.paymentReq)"
|
||||||
:value="'lightning:' + receive.paymentReq"
|
>Copy invoice</q-btn
|
||||||
:options="{width: 800}"
|
>
|
||||||
class="rounded-borders"
|
</div>
|
||||||
></qrcode>
|
</q-card>
|
||||||
</q-responsive>
|
</q-dialog>
|
||||||
<div class="row q-mt-lg q-gutter-sm">
|
</div>
|
||||||
<q-btn outline color="grey" @click="copyText(receive.paymentReq)"
|
|
||||||
>Copy invoice</q-btn
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
</q-card>
|
|
||||||
</q-dialog>
|
|
||||||
</div>
|
</div>
|
||||||
{% endraw %} {% endblock %} {% block scripts %}
|
{% endblock %} {% block scripts %}
|
||||||
<script src="{{ url_for('static', filename='vendor/vue-qrcode@1.0.2/vue-qrcode.min.js') }}"></script>
|
|
||||||
<style></style>
|
|
||||||
<script>
|
<script>
|
||||||
Vue.component(VueQrcode.name, VueQrcode)
|
Vue.component(VueQrcode.name, VueQrcode)
|
||||||
|
|
||||||
|
|
|
@ -31,15 +31,13 @@ async def connect_to_jukebox(request: Request, juke_id):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.NOT_FOUND, detail="Jukebox does not exist."
|
status_code=HTTPStatus.NOT_FOUND, detail="Jukebox does not exist."
|
||||||
)
|
)
|
||||||
deviceCheck = await api_get_jukebox_device_check(juke_id)
|
devices = await api_get_jukebox_device_check(juke_id)
|
||||||
devices = json.loads(deviceCheck[0].text)
|
|
||||||
deviceConnected = False
|
|
||||||
for device in devices["devices"]:
|
for device in devices["devices"]:
|
||||||
if device["id"] == jukebox.sp_device.split("-")[1]:
|
if device["id"] == jukebox.sp_device.split("-")[1]:
|
||||||
deviceConnected = True
|
deviceConnected = True
|
||||||
if deviceConnected:
|
if deviceConnected:
|
||||||
return jukebox_renderer().TemplateResponse(
|
return jukebox_renderer().TemplateResponse(
|
||||||
"jukebox/display.html",
|
"jukebox/jukebox.html",
|
||||||
{
|
{
|
||||||
"request": request,
|
"request": request,
|
||||||
"playlists": jukebox.sp_playlists.split(","),
|
"playlists": jukebox.sp_playlists.split(","),
|
||||||
|
|
|
@ -38,11 +38,10 @@ async def api_get_jukeboxs(
|
||||||
):
|
):
|
||||||
wallet_user = wallet.wallet.user
|
wallet_user = wallet.wallet.user
|
||||||
|
|
||||||
|
jukeboxs = [jukebox.dict() for jukebox in await get_jukeboxs(wallet_user)]
|
||||||
|
print(jukeboxs)
|
||||||
try:
|
try:
|
||||||
return [
|
return jukeboxs
|
||||||
{**jukebox.dict(), "jukebox": jukebox.jukebox(req)}
|
|
||||||
for jukebox in await get_jukeboxs(wallet_user)
|
|
||||||
]
|
|
||||||
|
|
||||||
except:
|
except:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
@ -54,7 +53,7 @@ async def api_get_jukeboxs(
|
||||||
##################SPOTIFY AUTH#####################
|
##################SPOTIFY AUTH#####################
|
||||||
|
|
||||||
|
|
||||||
@jukebox_ext.get("/api/v1/jukebox/spotify/cb/<juke_id>")
|
@jukebox_ext.get("/api/v1/jukebox/spotify/cb/{juke_id}", response_class=HTMLResponse)
|
||||||
async def api_check_credentials_callbac(
|
async def api_check_credentials_callbac(
|
||||||
juke_id: str = Query(None),
|
juke_id: str = Query(None),
|
||||||
code: str = Query(None),
|
code: str = Query(None),
|
||||||
|
@ -69,19 +68,12 @@ async def api_check_credentials_callbac(
|
||||||
except:
|
except:
|
||||||
raise HTTPException(detail="No Jukebox", status_code=HTTPStatus.FORBIDDEN)
|
raise HTTPException(detail="No Jukebox", status_code=HTTPStatus.FORBIDDEN)
|
||||||
if code:
|
if code:
|
||||||
sp_code = code
|
jukebox.sp_access_token = code
|
||||||
jukebox = await update_jukebox(
|
jukebox = await update_jukebox(jukebox, juke_id=juke_id)
|
||||||
juke_id=juke_id, sp_secret=jukebox.sp_secret, sp_access_token=sp_code
|
|
||||||
)
|
|
||||||
if access_token:
|
if access_token:
|
||||||
sp_access_token = access_token
|
jukebox.sp_access_token = access_token
|
||||||
sp_refresh_token = refresh_token
|
jukebox.sp_refresh_token = refresh_token
|
||||||
jukebox = await update_jukebox(
|
jukebox = await update_jukebox(jukebox, juke_id=juke_id)
|
||||||
juke_id=juke_id,
|
|
||||||
sp_secret=jukebox.sp_secret,
|
|
||||||
sp_access_token=sp_access_token,
|
|
||||||
sp_refresh_token=sp_refresh_token,
|
|
||||||
)
|
|
||||||
return "<h1>Success!</h1><h2>You can close this window</h2>"
|
return "<h1>Success!</h1><h2>You can close this window</h2>"
|
||||||
|
|
||||||
|
|
||||||
|
@ -103,11 +95,10 @@ async def api_create_update_jukebox(
|
||||||
wallet: WalletTypeInfo = Depends(get_key_type),
|
wallet: WalletTypeInfo = Depends(get_key_type),
|
||||||
):
|
):
|
||||||
if juke_id:
|
if juke_id:
|
||||||
jukebox = await update_jukebox(juke_id=juke_id, inkey=g.wallet.inkey, **g.data)
|
jukebox = await update_jukebox(data, juke_id=juke_id)
|
||||||
else:
|
else:
|
||||||
jukebox = await create_jukebox(inkey=g.wallet.inkey, **g.data)
|
jukebox = await create_jukebox(data, inkey=wallet.wallet.inkey)
|
||||||
|
return jukebox
|
||||||
return jukebox.dict()
|
|
||||||
|
|
||||||
|
|
||||||
@jukebox_ext.delete("/api/v1/jukebox/{juke_id}")
|
@jukebox_ext.delete("/api/v1/jukebox/{juke_id}")
|
||||||
|
@ -117,7 +108,7 @@ async def api_delete_item(
|
||||||
):
|
):
|
||||||
await delete_jukebox(juke_id)
|
await delete_jukebox(juke_id)
|
||||||
try:
|
try:
|
||||||
return [{**jukebox.dict()} for jukebox in await get_jukeboxs(g.wallet.user)]
|
return [{**jukebox} for jukebox in await get_jukeboxs(wallet.wallet.user)]
|
||||||
except:
|
except:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.NO_CONTENT,
|
status_code=HTTPStatus.NO_CONTENT,
|
||||||
|
@ -212,9 +203,8 @@ async def api_get_token(juke_id=None):
|
||||||
if "access_token" not in r.json():
|
if "access_token" not in r.json():
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
await update_jukebox(
|
jukebox.sp_access_token = r.json()["access_token"]
|
||||||
juke_id=juke_id, sp_access_token=r.json()["access_token"]
|
await update_jukebox(jukebox, juke_id=juke_id)
|
||||||
)
|
|
||||||
except:
|
except:
|
||||||
something = None
|
something = None
|
||||||
return True
|
return True
|
||||||
|
@ -241,9 +231,8 @@ async def api_get_jukebox_device_check(
|
||||||
timeout=40,
|
timeout=40,
|
||||||
headers={"Authorization": "Bearer " + jukebox.sp_access_token},
|
headers={"Authorization": "Bearer " + jukebox.sp_access_token},
|
||||||
)
|
)
|
||||||
|
|
||||||
if rDevice.status_code == 204 or rDevice.status_code == 200:
|
if rDevice.status_code == 204 or rDevice.status_code == 200:
|
||||||
return rDevice
|
return json.loads(rDevice.text)
|
||||||
elif rDevice.status_code == 401 or rDevice.status_code == 403:
|
elif rDevice.status_code == 401 or rDevice.status_code == 403:
|
||||||
token = await api_get_token(juke_id)
|
token = await api_get_token(juke_id)
|
||||||
if token == False:
|
if token == False:
|
||||||
|
@ -275,14 +264,14 @@ async def api_get_jukebox_invoice(
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
jukebox = await get_jukebox(juke_id)
|
jukebox = await get_jukebox(juke_id)
|
||||||
|
print(jukebox)
|
||||||
except:
|
except:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.FORBIDDEN,
|
status_code=HTTPStatus.FORBIDDEN,
|
||||||
detail="No jukebox",
|
detail="No jukebox",
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
deviceCheck = await api_get_jukebox_device_check(juke_id)
|
devices = await api_get_jukebox_device_check(juke_id)
|
||||||
devices = json.loads(deviceCheck[0].text)
|
|
||||||
deviceConnected = False
|
deviceConnected = False
|
||||||
for device in devices["devices"]:
|
for device in devices["devices"]:
|
||||||
if device["id"] == jukebox.sp_device.split("-")[1]:
|
if device["id"] == jukebox.sp_device.split("-")[1]:
|
||||||
|
|
|
@ -133,6 +133,15 @@
|
||||||
</div>
|
</div>
|
||||||
</q-card>
|
</q-card>
|
||||||
</q-dialog>
|
</q-dialog>
|
||||||
|
|
||||||
|
<q-dialog v-model="complete.show" position="top">
|
||||||
|
<q-icon
|
||||||
|
name="check_circle"
|
||||||
|
transition-show="fade"
|
||||||
|
class="text-green"
|
||||||
|
style="font-size: 20em"
|
||||||
|
></q-icon
|
||||||
|
></q-dialog>
|
||||||
</q-page>
|
</q-page>
|
||||||
</q-page-container>
|
</q-page-container>
|
||||||
{% endblock %} {% block styles %}
|
{% endblock %} {% block styles %}
|
||||||
|
@ -172,6 +181,9 @@
|
||||||
},
|
},
|
||||||
urlDialog: {
|
urlDialog: {
|
||||||
show: false
|
show: false
|
||||||
|
},
|
||||||
|
complete: {
|
||||||
|
show: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -234,11 +246,10 @@
|
||||||
dialog.dismissMsg()
|
dialog.dismissMsg()
|
||||||
dialog.show = false
|
dialog.show = false
|
||||||
|
|
||||||
self.$q.notify({
|
self.complete.show = true
|
||||||
type: 'positive',
|
setTimeout(function () {
|
||||||
message: self.fsat + ' sat received!',
|
self.complete.show = false
|
||||||
icon: null
|
}, 5000)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}, 3000)
|
}, 3000)
|
||||||
|
|
Loading…
Add table
Reference in a new issue