black + added devices

This commit is contained in:
Ben Arc 2021-04-29 08:47:58 +01:00
parent b594281f83
commit 38c2270abf
4 changed files with 23 additions and 14 deletions

View File

@ -39,6 +39,7 @@ async def create_jukebox(
assert jukebox, "Newly created Jukebox couldn't be retrieved"
return jukebox
async def update_jukebox(sp_user: str, **kwargs) -> Optional[Jukebox]:
q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()])
await db.execute(

View File

@ -94,7 +94,7 @@ new Vue({
var url = 'https://accounts.spotify.com/authorize'
url += '?client_id=' + self.jukeboxDialog.data.sp_user
url += '&response_type=code'
url += '&redirect_uri=' + encodeURI(self.locationcbPath + self.jukeboxDialog.data.sp_user)
url += '&redirect_uri=' + encodeURI(self.locationcbPath) + self.jukeboxDialog.data.sp_user
url += "&show_dialog=true"
url += '&scope=user-read-private user-read-email user-modify-playback-state user-read-playback-position user-library-read streaming user-read-playback-state user-read-recently-played playlist-read-private'
console.log(url)
@ -136,7 +136,7 @@ new Vue({
xhr.send(body)
xhr.onload = function() {
let responseObj = JSON.parse(xhr.response)
console.log(responseObj.items)
self.playlists = []
var i;
for (i = 0; i < responseObj.items.length; i++) {
self.playlists.push(responseObj.items[i].name + "-" + responseObj.items[i].id)
@ -155,12 +155,15 @@ new Vue({
xhr.setRequestHeader('Authorization', 'Bearer ' + this.jukeboxDialog.data.sp_access_token)
xhr.send(body)
xhr.onload = function() {
let responseObj = xhr.response
alert(responseObj)
let responseObj = JSON.parse(xhr.response)
console.log(responseObj.devices[0])
self.devices = []
var i;
for (i = 0; i < responseObj.items.length; i++) {
self.devices.push(responseObj.items[i].name + "-" + responseObj.items[i].id)
for (i = 0; i < responseObj.devices.length; i++) {
self.devices.push(responseObj.devices[i].name + "-" + responseObj.devices[i].id)
console.log(responseObj.devices[i].name)
}
}
},
refreshDevices(){
@ -171,7 +174,7 @@ new Vue({
self = this
let body = "grant_type=authorization_code"
body += "&code=" + self.jukeboxDialog.data.sp_access_token
body += '&redirect_uri=' + encodeURI(self.locationcbPath + self.jukeboxDialog.data.sp_user)
body += '&redirect_uri=' + encodeURI(self.locationcbPath) + self.jukeboxDialog.data.sp_user
this.callAuthorizationApi(body)
},
refreshAccessToken(){

View File

@ -11,6 +11,7 @@ from . import jukebox_ext
from .crud import get_jukebox
from urllib.parse import unquote
@jukebox_ext.route("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
@ -22,4 +23,4 @@ async def index():
async def print_qr_codes(juke_id):
jukebox = await get_jukebox(juke_id)
return await render_template("jukebox/jukebox.html", jukebox=jukebox)
return await render_template("jukebox/jukebox.html", jukebox=jukebox)

View File

@ -32,19 +32,23 @@ async def api_check_credentials_callbac(sp_user):
sp_refresh_token = ""
print(request.args)
jukebox = await get_jukebox_by_user(sp_user)
if request.args.get('code'):
sp_code = request.args.get('code')
if request.args.get("code"):
sp_code = request.args.get("code")
jukebox = await update_jukebox(
sp_user=sp_user, sp_secret=jukebox.sp_secret, sp_access_token=sp_code
)
if request.args.get('access_token'):
sp_access_token = request.args.get('access_token')
sp_refresh_token = request.args.get('refresh_token')
if request.args.get("access_token"):
sp_access_token = request.args.get("access_token")
sp_refresh_token = request.args.get("refresh_token")
jukebox = await update_jukebox(
sp_user=sp_user, sp_secret=jukebox.sp_secret, sp_access_token=sp_access_token, sp_refresh_token=sp_refresh_token
sp_user=sp_user,
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>"
@jukebox_ext.route("/api/v1/jukebox/spotify/<sp_id>", methods=["GET"])
@api_check_wallet_key("invoice")
async def api_check_credentials_check(sp_id):