Download un-sync fix, playback history

This commit is contained in:
exttex 2020-09-02 14:39:43 +02:00
parent 96db2c3753
commit a77d8437bd
8 changed files with 106 additions and 28 deletions

View File

@ -1,6 +1,6 @@
{
"name": "client",
"version": "0.1.0",
"version": "1.0.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",

View File

@ -0,0 +1,58 @@
<template>
<div>
<div v-if='loading'>
<v-progress-circular indeterminate class='ma-4'></v-progress-circular>
</div>
<v-list v-if='!loading'>
<v-lazy v-for='(track, index) in tracks' :key='track.id' max-height='100'>
<TrackTile :track='track' @click='play(index)'></TrackTile>
</v-lazy>
</v-list>
</div>
</template>
<script>
import TrackTile from '@/components/TrackTile.vue';
export default {
name: 'LibraryHistory',
components: {
TrackTile
},
data() {
return {
loading: true,
tracks: []
}
},
methods: {
async load() {
this.loading = true;
//Fetch
let res = await this.$axios.get('/history');
if (res.data) this.tracks = res.data;
this.loading = false;
},
//Load as queue and play
play(index) {
this.$root.queue.source = {
text: 'History',
source: 'history',
data: null
};
this.$root.replaceQueue(this.tracks);
this.$root.playIndex(index);
}
},
mounted() {
//Load on start
this.load();
}
}
</script>

View File

@ -54,11 +54,11 @@
<v-list-item-title>{{download.track.title}}</v-list-item-title>
<v-list-item-subtitle>{{download.track.artistString}}</v-list-item-subtitle>
</v-list-item-content>
<v-liste-item-action>
<v-list-item-action>
<v-btn icon @click='deleteDownload(index)'>
<v-icon>mdi-delete</v-icon>
</v-btn>
</v-liste-item-action>
</v-list-item-action>
</v-list-item>
</div>
</v-list>
@ -79,7 +79,6 @@ export default {
//Remove download from queue
async deleteDownload(i) {
await this.$axios.delete(`/downloads/${i}`);
this.$root.getDownloads();
}
}
}

View File

@ -15,6 +15,9 @@
<v-tab key='playlists'>
Playlists
</v-tab>
<v-tab key='history'>
History
</v-tab>
</v-tabs>
<v-tabs-items v-model='tab'>
@ -37,6 +40,11 @@
<v-tab-item key='playlists'>
<LibraryPlaylists></LibraryPlaylists>
</v-tab-item>
<!-- History -->
<v-tab-item key='history'>
<LibraryHistory></LibraryHistory>
</v-tab-item>
</v-tabs-items>
</div>
@ -47,11 +55,12 @@ import LibraryTracks from '@/components/LibraryTracks.vue';
import LibraryAlbums from '@/components/LibraryAlbums.vue';
import LibraryArtists from '@/components/LibraryArtists.vue';
import LibraryPlaylists from '@/components/LibraryPlaylists.vue';
import LibraryHistory from '@/components/LibraryHistory.vue';
export default {
name: 'Library',
components: {
LibraryTracks, LibraryAlbums, LibraryArtists, LibraryPlaylists
LibraryTracks, LibraryAlbums, LibraryArtists, LibraryPlaylists, LibraryHistory
},
props: {
routeTab: {

View File

@ -1,7 +1,7 @@
{
"name": "freezer",
"private": true,
"version": "1.0.2",
"version": "1.0.3",
"description": "",
"main": "background.js",
"scripts": {

View File

@ -163,9 +163,11 @@ class Downloads {
if (index == -1) {
this.downloads = [];
await new Promise((res, rej) => {
this.db.remove({state: 0}, {}, (e) => {});
this.db.remove({state: 0}, {multi: true}, (e) => {});
res();
})
});
if (this.qucb) this.qucb();
return;
}
@ -176,6 +178,8 @@ class Downloads {
res();
});
this.downloads.splice(index, 1);
if (this.qucb) this.qucb();
}
}

View File

@ -193,6 +193,17 @@ app.get('/albums/:id', async (req, res) => {
res.send(albums);
})
//Get tracks from listening history
app.get('/history', async (req, res) => {
let data = await deezer.callApi('deezer.pageProfile', {
nb: 200,
tab: "history",
user_id: deezer.userId.toString()
});
let tracks = data.results.TAB.history.data.map((t) => new Track(t));
res.send(tracks);
});
//Search, q as query parameter
app.get('/search', async (req, res) => {
let data = await deezer.callApi('deezer.pageSearch', {query: req.query.q, nb: 100});
@ -496,7 +507,8 @@ async function createServer(electron = false, ecb) {
downloads: downloads.downloads
});
});
});
await downloads.load();
//Emit download progress updates
setInterval(() => {
sockets.forEach((s) => {
@ -504,7 +516,6 @@ async function createServer(electron = false, ecb) {
s.emit('download', null);
return;
}
s.emit('download', {
id: downloads.download.id,
size: downloads.download.size,
@ -513,10 +524,7 @@ async function createServer(electron = false, ecb) {
path: downloads.download.path
});
});
}, 500);
});
await downloads.load();
}, 350);
//Start server
server.on('error', (e) => {

View File

@ -1,7 +1,7 @@
{
"name": "freezer",
"private": true,
"version": "1.0.2",
"version": "1.0.3",
"description": "",
"scripts": {
"pack": "electron-builder --dir",