diff --git a/src/App.vue b/src/App.vue index 331a2065..21938271 100644 --- a/src/App.vue +++ b/src/App.vue @@ -55,7 +55,7 @@ export default { }); if ("indexedDB" in window) { - const request = indexedDB.open("piped-db", 4); + const request = indexedDB.open("piped-db", 5); request.onupgradeneeded = ev => { const db = request.result; console.log("Upgrading object store."); @@ -77,6 +77,12 @@ export default { const store = db.createObjectStore("channel_groups", { keyPath: "groupName" }); store.createIndex("groupName", "groupName", { unique: true }); } + if (!db.objectStoreNames.contains("playlists")) { + const playlistStore = db.createObjectStore("playlists", { keyPath: "playlistId" }); + playlistStore.createIndex("playlistId", "playlistId", { unique: true }); + const playlistVideosStore = db.createObjectStore("playlist_videos", { keyPath: "videoId" }); + playlistVideosStore.createIndex("videoId", "videoId", { unique: true }); + } }; request.onsuccess = e => { window.db = e.target.result; diff --git a/src/components/PlaylistAddModal.vue b/src/components/PlaylistAddModal.vue index 3e3a4aac..d155e72a 100644 --- a/src/components/PlaylistAddModal.vue +++ b/src/components/PlaylistAddModal.vue @@ -23,6 +23,10 @@ export default { ModalComponent, }, props: { + videoInfo: { + type: Object, + required: true, + }, videoId: { type: String, required: true, @@ -62,28 +66,14 @@ export default { this.$refs.addButton.disabled = true; this.processing = true; - this.fetchJson(this.authApiUrl() + "/user/playlists/add", null, { - method: "POST", - body: JSON.stringify({ - playlistId: playlistId, - videoId: this.videoId, - }), - headers: { - Authorization: this.getAuthToken(), - "Content-Type": "application/json", - }, - }).then(json => { + this.addVideosToPlaylist(playlistId, [this.videoId], [this.videoInfo]).then(json => { this.setPreference("selectedPlaylist" + this.hashCode(this.authApiUrl()), playlistId); this.$emit("close"); if (json.error) alert(json.error); }); }, async fetchPlaylists() { - this.fetchJson(this.authApiUrl() + "/user/playlists", null, { - headers: { - Authorization: this.getAuthToken(), - }, - }).then(json => { + this.getPlaylists().then(json => { this.playlists = json; }); }, diff --git a/src/components/PlaylistPage.vue b/src/components/PlaylistPage.vue index 212a22ef..546c10a2 100644 --- a/src/components/PlaylistPage.vue +++ b/src/components/PlaylistPage.vue @@ -86,14 +86,11 @@ export default { mounted() { const playlistId = this.$route.query.list; if (this.authenticated && playlistId?.length == 36) - this.fetchJson(this.authApiUrl() + "/user/playlists", null, { - headers: { - Authorization: this.getAuthToken(), - }, - }).then(json => { + this.getPlaylists().then(json => { if (json.error) alert(json.error); else if (json.some(playlist => playlist.id === playlistId)) this.admin = true; }); + else if (playlistId.startsWith("local")) this.admin = true; this.isPlaylistBookmarked(); }, activated() { @@ -106,6 +103,11 @@ export default { }, methods: { async fetchPlaylist() { + const playlistId = this.$route.query.list; + if (playlistId.startsWith("local")) { + return this.getPlaylist(playlistId); + } + return await await this.fetchJson(this.authApiUrl() + "/playlists/" + this.$route.query.list); }, async getPlaylistData() { diff --git a/src/components/PlaylistsPage.vue b/src/components/PlaylistsPage.vue index 0dda0efe..06f4da30 100644 --- a/src/components/PlaylistsPage.vue +++ b/src/components/PlaylistsPage.vue @@ -1,7 +1,7 @@