Update pre-existing watch history.

Closes #567
This commit is contained in:
FireMaskterK 2021-10-27 00:49:56 +01:00
parent 4ec67a4884
commit 6ee9592218
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD

View file

@ -216,19 +216,29 @@ export default {
mounted() { mounted() {
this.getVideoData().then(() => { this.getVideoData().then(() => {
(async () => { (async () => {
const videoId = this.getVideoId();
const instance = this;
if (window.db) { if (window.db) {
var tx = window.db.transaction("watch_history", "readwrite"); var tx = window.db.transaction("watch_history", "readwrite");
var store = tx.objectStore("watch_history"); var store = tx.objectStore("watch_history");
var video = { var request = store.get(videoId);
videoId: this.getVideoId(), request.onsuccess = function(event) {
title: this.video.title, var video = event.target.result;
duration: this.video.duration, if (video) {
thumbnail: this.video.thumbnailUrl, video.watchedAt = Date.now();
uploaderUrl: this.video.uploaderUrl, } else {
uploaderName: this.video.uploader, video = {
watchedAt: Date.now(), videoId: videoId,
title: instance.video.title,
duration: instance.video.duration,
thumbnail: instance.video.thumbnailUrl,
uploaderUrl: instance.video.uploaderUrl,
uploaderName: instance.video.uploader,
watchedAt: Date.now(),
};
}
store.put(video);
}; };
store.add(video);
} }
})(); })();
if (this.active) this.$refs.videoPlayer.loadVideo(); if (this.active) this.$refs.videoPlayer.loadVideo();