mirror of
https://github.com/TeamPiped/Piped.git
synced 2024-11-26 07:27:22 +00:00
Simplify local playlist indexeddb queries
This commit is contained in:
parent
d044accf5e
commit
ee57a0c348
30
src/main.js
30
src/main.js
@ -194,9 +194,6 @@ const mixin = {
|
||||
timeAgo(time) {
|
||||
return timeAgo.format(time);
|
||||
},
|
||||
async delay(millis) {
|
||||
return await new Promise(r => setTimeout(r, millis));
|
||||
},
|
||||
urlify(string) {
|
||||
if (!string) return "";
|
||||
const urlRegex = /(((https?:\/\/)|(www\.))[^\s]+)/g;
|
||||
@ -296,18 +293,17 @@ const mixin = {
|
||||
store.delete(groupName);
|
||||
},
|
||||
async getLocalPlaylist(playlistId) {
|
||||
return await new Promise(resolve => {
|
||||
var tx = window.db.transaction("playlists", "readonly");
|
||||
var store = tx.objectStore("playlists");
|
||||
const req = store.openCursor(playlistId);
|
||||
let playlist = null;
|
||||
req.onsuccess = e => {
|
||||
playlist = e.target.result.value;
|
||||
};
|
||||
while (playlist == null) {
|
||||
await this.delay(10);
|
||||
}
|
||||
playlist.videos = JSON.parse(playlist.videoIds).length;
|
||||
return playlist;
|
||||
resolve(playlist);
|
||||
};
|
||||
});
|
||||
},
|
||||
createOrUpdateLocalPlaylist(playlist) {
|
||||
var tx = window.db.transaction("playlists", "readwrite");
|
||||
@ -336,22 +332,19 @@ const mixin = {
|
||||
store.put(video);
|
||||
},
|
||||
async getLocalPlaylistVideo(videoId) {
|
||||
return await new Promise(resolve => {
|
||||
var tx = window.db.transaction("playlist_videos", "readonly");
|
||||
var store = tx.objectStore("playlist_videos");
|
||||
const req = store.openCursor(videoId);
|
||||
let video = null;
|
||||
req.onsuccess = e => {
|
||||
video = e.target.result.value;
|
||||
resolve(e.target.result.value);
|
||||
};
|
||||
while (video == null) {
|
||||
await this.delay(10);
|
||||
}
|
||||
return video;
|
||||
});
|
||||
},
|
||||
async getPlaylists() {
|
||||
if (!this.authenticated) {
|
||||
if (!window.db) return [];
|
||||
let finished = false;
|
||||
return await new Promise(resolve => {
|
||||
let playlists = [];
|
||||
var tx = window.db.transaction("playlists", "readonly");
|
||||
var store = tx.objectStore("playlists");
|
||||
@ -364,13 +357,10 @@ const mixin = {
|
||||
playlists.push(playlist);
|
||||
cursor.continue();
|
||||
} else {
|
||||
finished = true;
|
||||
resolve(playlists);
|
||||
}
|
||||
};
|
||||
while (!finished) {
|
||||
await this.delay(10);
|
||||
}
|
||||
return playlists;
|
||||
});
|
||||
}
|
||||
|
||||
return await this.fetchJson(this.authApiUrl() + "/user/playlists", null, {
|
||||
|
Loading…
Reference in New Issue
Block a user