mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-18 14:18:03 +00:00
feat: cache track details, lyrics and album
This commit is contained in:
parent
3d29bb5ca1
commit
7781ac8ec2
3 changed files with 139 additions and 25 deletions
|
|
@ -5,6 +5,12 @@ import store from '@/store';
|
|||
|
||||
const db = new Dexie('yesplaymusic');
|
||||
|
||||
db.version(4).stores({
|
||||
trackDetail: '&id, updateTime',
|
||||
lyric: '&id, updateTime',
|
||||
album: '&id, updateTime',
|
||||
});
|
||||
|
||||
db.version(3)
|
||||
.stores({
|
||||
trackSources: '&id, createTime',
|
||||
|
|
@ -78,6 +84,65 @@ export function getTrackSource(id) {
|
|||
});
|
||||
}
|
||||
|
||||
export function cacheTrackDetail(track, privileges) {
|
||||
db.trackDetail.put({
|
||||
id: track.id,
|
||||
detail: track,
|
||||
privileges: privileges,
|
||||
updateTime: new Date().getTime(),
|
||||
});
|
||||
}
|
||||
|
||||
export function getTrackDetailFromCache(ids) {
|
||||
return db.trackDetail
|
||||
.filter(track => {
|
||||
return ids.includes(String(track.id));
|
||||
})
|
||||
.toArray()
|
||||
.then(tracks => {
|
||||
const result = { songs: [], privileges: [] };
|
||||
ids.map(id => {
|
||||
const one = tracks.find(t => String(t.id) === id);
|
||||
result.songs.push(one?.detail);
|
||||
result.privileges.push(one?.privileges);
|
||||
});
|
||||
if (result.songs.includes(undefined)) {
|
||||
return undefined;
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
export function cacheLyric(id, lyrics) {
|
||||
db.lyric.put({
|
||||
id,
|
||||
lyrics,
|
||||
updateTime: new Date().getTime(),
|
||||
});
|
||||
}
|
||||
|
||||
export function getLyricFromCache(id) {
|
||||
return db.lyric.get(Number(id)).then(result => {
|
||||
if (!result) return undefined;
|
||||
return result.lyrics;
|
||||
});
|
||||
}
|
||||
|
||||
export function cacheAlbum(id, album) {
|
||||
db.album.put({
|
||||
id,
|
||||
album,
|
||||
updateTime: new Date().getTime(),
|
||||
});
|
||||
}
|
||||
|
||||
export function getAlbumFromCache(id) {
|
||||
return db.album.get(Number(id)).then(result => {
|
||||
if (!result) return undefined;
|
||||
return result.album;
|
||||
});
|
||||
}
|
||||
|
||||
export function countDBSize() {
|
||||
const trackSizes = [];
|
||||
return db.trackSources
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue