From 4e051eb97cf10842eabf2e7e1d59c8ced04a1d8f Mon Sep 17 00:00:00 2001 From: booploops <49113086+booploops@users.noreply.github.com> Date: Sat, 4 Dec 2021 13:09:15 -0800 Subject: [PATCH] downloads entire library in songs view --- resources/cider-ui-tests/index.html | 29 +++++++++++++--------- resources/cider-ui-tests/index.js | 38 ++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/resources/cider-ui-tests/index.html b/resources/cider-ui-tests/index.html index c9c11a94..5af66a71 100644 --- a/resources/cider-ui-tests/index.html +++ b/resources/cider-ui-tests/index.html @@ -252,20 +252,27 @@ - + diff --git a/resources/cider-ui-tests/index.js b/resources/cider-ui-tests/index.js index d00b8d5f..ba120aec 100644 --- a/resources/cider-ui-tests/index.js +++ b/resources/cider-ui-tests/index.js @@ -107,7 +107,8 @@ const app = new Vue({ library: { songs: { listing: [], - meta: {total: 0} + meta: {total: 0, progress: 0}, + downloadState: 0 // 0 = not started, 1 = in progress, 2 = complete }, albums: { listing: [], @@ -174,6 +175,41 @@ const app = new Vue({ return await this.mkapi(method, library, term, params, params2, attempts + 1) } }, + async getLibrarySongsFull () { + let self = this + let library = [] + let downloaded = null; + if(this.library.songs.downloadState == 2 || this.library.songs.downloadState == 1) { + return + } + this.library.songs.downloadState = 1 + function downloadChunk () { + if(downloaded == null) { + app.mk.api.library.songs("", {limit: 100}, {includeResponseMeta: !0}).then((response)=>{ + processChunk(response) + }) + }else{ + downloaded.next("", {limit: 100}, {includeResponseMeta: !0}).then((response)=>{ + processChunk(response) + }) + } + } + function processChunk (response) { + downloaded = response + library = library.concat(downloaded.data) + self.library.songs.meta.total = downloaded.meta.total + self.library.songs.meta.progress = library.length + if (downloaded.meta.total > library.length) { + console.log(`downloading next chunk - ${library.length} songs so far`) + downloadChunk() + } else { + self.library.songs.listing = library + self.library.songs.downloadState = 2 + console.log(library) + } + } + downloadChunk() + }, async getLibrarySongs() { var response = await this.mkapi("songs", true, "", {limit: 100}, {includeResponseMeta: !0}) this.library.songs.listing = response.data