Security fix: correct update header; Added some types radios

This commit is contained in:
localhost_frssoft 2022-11-06 04:26:50 +03:00
parent b0d4d3976e
commit ae1cba2e98
2 changed files with 18 additions and 10 deletions

View File

@ -10,9 +10,9 @@ instance = 'fw.ponychord.rocks'
token = auth.get(instance) token = auth.get(instance)
if token: if token:
s.headers.update = { s.headers.update({
"Authorization": "Bearer " + token "Authorization": "Bearer " + token
} })
player.http_header_fields = ['Authorization: ' + 'Bearer ' + token] player.http_header_fields = ['Authorization: ' + 'Bearer ' + token]
else: else:
s.get(f'https://{instance}/') # Get cookies from unauthorized instance for working some functionality (radios) s.get(f'https://{instance}/') # Get cookies from unauthorized instance for working some functionality (radios)
@ -23,13 +23,13 @@ def select_instance(new_instance=None):
global instance global instance
instance = new_instance instance = new_instance
new_token = auth.get(instance) new_token = auth.get(instance)
s.headers.update = {} s.headers.update({"Authorization": None})
player.http_header_fields = [] player.http_header_fields = []
if new_token: if new_token:
s.get(f'https://{instance}') s.get(f'https://{instance}')
s.headers.update = { s.headers.update({
"Authorization": "Bearer " + new_token "Authorization": "Bearer " + new_token
} })
player.http_header_fields = ['Authorization: ' + 'Bearer ' + new_token] player.http_header_fields = ['Authorization: ' + 'Bearer ' + new_token]

View File

@ -1,4 +1,4 @@
from src.fw_api import get_radios, post_radio_session, get_track_radio, concatinate_endpoint from src.fw_api import s, get_radios, post_radio_session, get_track_radio, concatinate_endpoint
from src.utils import download_track from src.utils import download_track
from src.mpv_control import player from src.mpv_control import player
from pyfzf.pyfzf import FzfPrompt from pyfzf.pyfzf import FzfPrompt
@ -20,13 +20,21 @@ def list_radios():
id_radio = i.get('id') id_radio = i.get('id')
name = i.get('name') name = i.get('name')
view.append(f'{index}.{name}') view.append(f'{index}.{name}')
if s.headers.get('Authorization'): # Radios avalaible only for auth user
view.append('Favourites') view.append('Favourites')
view.append('Less listened')
view.append('Random')
view.append('Recently Added')
selected = fzf.prompt(view, f'--header \'Found {count} radios\'')[0].split('.', 1) selected = fzf.prompt(view, f'--header \'Found {count} radios\'')[0].split('.', 1)
if 'Favourites' in selected: if 'Favourites' in selected:
type_radio = 'favorites' radio_load(id_radio, 'favorites')
radio_load(id_radio, type_radio) elif 'Random' in selected:
radio_load(id_radio, 'random')
elif 'Recently Added' in selected:
radio_load(id_radio, 'recently-added')
elif 'Less listened' in selected:
radio_load(id_radio, 'less-listened')
else: else:
id_selected = selected[0] id_selected = selected[0]
id_radio = results[int(id_selected)].get('id') id_radio = results[int(id_selected)].get('id')