client: implement a buggy inifinite scroll on folder view

This commit is contained in:
geoffrey45
2021-12-18 12:09:24 +03:00
parent 5ebe7b0dff
commit 457180ecaf
5 changed files with 86 additions and 35 deletions
+11 -8
View File
@@ -46,18 +46,20 @@ def search_by_title():
else:
query = request.args.get('q')
all_songs = []
songs = all_songs_instance.find_song_by_title(query)
all_songs = convert_to_json(songs)
all_songs.append(convert_to_json(songs))
albums = all_songs_instance.find_songs_by_album(query)
all_songs.append(convert_to_json(albums))
songs_by_albums = all_songs_instance.find_songs_by_album(query)
all_songs.append(convert_to_json(songs_by_albums))
artists = all_songs_instance.find_songs_by_artist(query)
all_songs.append(convert_to_json(artists))
songs_by_artists = all_songs_instance.find_songs_by_artist(query)
all_songs.append(convert_to_json(songs_by_artists))
songs = remove_duplicates(all_songs)
# songs = remove_duplicates(all_songs)
return {'songs': songs}
return {'songs': all_songs}
@bp.route('/populate')
@@ -272,6 +274,7 @@ def getFolderTree():
start = time.time()
req_dir = request.args.get('f')
last_id = request.args.get('last_id')
if req_dir is not None:
requested_dir = home_dir + req_dir
@@ -298,7 +301,7 @@ def getFolderTree():
if entry.is_file():
if isValidFile(entry.name) == True:
songs_array = all_songs_instance.find_songs_by_folder(req_dir)
songs_array = all_songs_instance.find_songs_by_folder(req_dir, last_id)
songs = convert_to_json(songs_array)
for song in songs:
song['artists'] = song['artists'].split(', ')
+10 -5
View File
@@ -45,12 +45,13 @@ class AllSongs(Mongo):
# def drop_db(self):
# self.collection.drop()
def get_song_by_id(self, file_id):
return self.collection.find_one({'_id': ObjectId(file_id)})
def insert_song(self, song_obj):
self.collection.update({'filepath': song_obj['filepath']}, song_obj, upsert=True)
self.collection.update(
{'filepath': song_obj['filepath']}, song_obj, upsert=True)
def find_song_by_title(self, query):
self.collection.create_index([('title', pymongo.TEXT)])
@@ -62,8 +63,12 @@ class AllSongs(Mongo):
def get_all_songs(self):
return self.collection.find()
def find_songs_by_folder(self, query):
return self.collection.find({'folder': query})
def find_songs_by_folder(self, query, last_id=None):
limit = 18
if last_id is None:
return self.collection.find({'folder': query}).limit(limit)
else:
return self.collection.find({'folder': query, '_id': {'$gt': ObjectId(last_id)}}).limit(limit)
def find_songs_by_artist(self, query):
return self.collection.find({'artists': {'$regex': query, '$options': 'i'}})
@@ -79,4 +84,4 @@ class AllSongs(Mongo):
self.collection.remove({'filepath': filepath})
return True
except:
return False
return False