client: improve quick access

- default to opened sidebar
This commit is contained in:
geoffrey45
2021-12-25 20:36:28 +03:00
parent ff0381122e
commit dc4b87a942
8 changed files with 91 additions and 53 deletions
+28 -8
View File
@@ -1,5 +1,4 @@
import typing
from app.models import Folders, Artists
from app.models import Artists
from app.helpers import (
all_songs_instance,
@@ -30,7 +29,6 @@ from flask import Blueprint, request, send_from_directory
bp = Blueprint('api', __name__, url_prefix='')
artist_instance = Artists()
folder_instance = Folders()
img_path = "http://127.0.0.1:8900/images/thumbnails/"
@@ -190,11 +188,12 @@ def populate_images():
return {'sample': artists_in_db_array[:25]}
@bp.route("/artist")
def getArtistData():
artist = urllib.parse.unquote(request.args.get('q'))
artist_obj = artist_instance.find_artists_by_name(artist)
@bp.route("/artist/<artist>")
@cache.cached()
def getArtistData(artist: str):
print(artist)
artist = urllib.parse.unquote(artist)
artist_obj = artist_instance.get_artists_by_name(artist)
artist_obj_json = convert_to_json(artist_obj)
def getArtistSongs():
@@ -340,3 +339,24 @@ def post():
return {'songs': songs_array}
return {'msg': 'ok'}
@bp.route('/qwerty')
def populateArtists():
all_songs = all_songs_instance.get_all_songs()
songs = convert_to_json(all_songs)
artists = []
for song in songs:
artist = song['artists'].split(', ')
for a in artist:
a_obj = {
"name": a,
}
if a_obj not in artists:
artists.append(a_obj)
return {'songs': artists}
+2 -15
View File
@@ -7,19 +7,6 @@ class Mongo:
mongo_uri = pymongo.MongoClient()
self.db = mongo_uri[database]
class Folders(Mongo):
def __init__(self):
super(Folders, self).__init__('LOCAL_FOLDERS')
self.collection = self.db['LOCAL_FOLDERS']
def insert_folder(self, folder):
self.collection.insert_one(folder)
def find_folder(self, folder_id):
return self.collection.find_one({'_id': ObjectId(folder_id)})
class Artists(Mongo):
def __init__(self):
super(Artists, self).__init__('ALL_ARTISTS')
@@ -34,8 +21,8 @@ class Artists(Mongo):
def get_artist_by_id(self, artist_id):
return self.collection.find_one({'_id': ObjectId(artist_id)})
def find_artists_by_name(self, query):
return self.collection.find({'name': {'$regex': query, '$options': 'i'}})
def get_artists_by_name(self, query):
return self.collection.find({'name': query}).limit(20)
class AllSongs(Mongo):