From ae1cba2e98c997e39d2b0addb46a40fecf57232d Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Sun, 6 Nov 2022 04:26:50 +0300 Subject: [PATCH] Security fix: correct update header; Added some types radios --- src/fw_api.py | 10 +++++----- src/fw_radios.py | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/fw_api.py b/src/fw_api.py index 1f1d8b5..5c882f1 100644 --- a/src/fw_api.py +++ b/src/fw_api.py @@ -10,9 +10,9 @@ instance = 'fw.ponychord.rocks' token = auth.get(instance) if token: - s.headers.update = { + s.headers.update({ "Authorization": "Bearer " + token - } + }) player.http_header_fields = ['Authorization: ' + 'Bearer ' + token] else: 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 instance = new_instance new_token = auth.get(instance) - s.headers.update = {} + s.headers.update({"Authorization": None}) player.http_header_fields = [] if new_token: s.get(f'https://{instance}') - s.headers.update = { + s.headers.update({ "Authorization": "Bearer " + new_token - } + }) player.http_header_fields = ['Authorization: ' + 'Bearer ' + new_token] diff --git a/src/fw_radios.py b/src/fw_radios.py index 4f7ca4e..d50f5ec 100644 --- a/src/fw_radios.py +++ b/src/fw_radios.py @@ -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.mpv_control import player from pyfzf.pyfzf import FzfPrompt @@ -20,13 +20,21 @@ def list_radios(): id_radio = i.get('id') name = i.get('name') view.append(f'{index}.{name}') - - view.append('Favourites') + if s.headers.get('Authorization'): # Radios avalaible only for auth user + 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) if 'Favourites' in selected: - type_radio = 'favorites' - radio_load(id_radio, type_radio) + radio_load(id_radio, 'favorites') + 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: id_selected = selected[0] id_radio = results[int(id_selected)].get('id')