aboutsummaryrefslogtreecommitdiffhomepage
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/src/assets/player/peertube-player-local-storage.ts13
1 files changed, 9 insertions, 4 deletions
diff --git a/client/src/assets/player/peertube-player-local-storage.ts b/client/src/assets/player/peertube-player-local-storage.ts
index 80aceb239..d4cbda3a9 100644
--- a/client/src/assets/player/peertube-player-local-storage.ts
+++ b/client/src/assets/player/peertube-player-local-storage.ts
@@ -69,9 +69,10 @@ function getStoredLastSubtitle () {
69 return getLocalStorage('last-subtitle') 69 return getLocalStorage('last-subtitle')
70} 70}
71 71
72function saveVideoWatchHistory(videoUUID: string, duration: number) { 72function saveVideoWatchHistory (videoUUID: string, duration: number) {
73 return setLocalStorage(`video-watch-history`, JSON.stringify({ 73 return setLocalStorage(`video-watch-history`, JSON.stringify({
74 ...getStoredVideoWatchHistory(), 74 ...getStoredVideoWatchHistory(),
75
75 [videoUUID]: { 76 [videoUUID]: {
76 duration, 77 duration,
77 date: `${(new Date()).toISOString()}` 78 date: `${(new Date()).toISOString()}`
@@ -79,11 +80,14 @@ function saveVideoWatchHistory(videoUUID: string, duration: number) {
79 })) 80 }))
80} 81}
81 82
82function getStoredVideoWatchHistory(videoUUID?: string) { 83function getStoredVideoWatchHistory (videoUUID?: string) {
83 let data 84 let data
84 85
85 try { 86 try {
86 data = JSON.parse(getLocalStorage('video-watch-history')) 87 const value = getLocalStorage('video-watch-history')
88 if (!value) return {}
89
90 data = JSON.parse(value)
87 } catch (error) { 91 } catch (error) {
88 console.error('Cannot parse video watch history from local storage: ', error) 92 console.error('Cannot parse video watch history from local storage: ', error)
89 } 93 }
@@ -95,8 +99,9 @@ function getStoredVideoWatchHistory(videoUUID?: string) {
95 return data 99 return data
96} 100}
97 101
98function cleanupVideoWatch() { 102function cleanupVideoWatch () {
99 const data = getStoredVideoWatchHistory() 103 const data = getStoredVideoWatchHistory()
104 if (!data) return
100 105
101 const newData = Object.keys(data).reduce((acc, videoUUID) => { 106 const newData = Object.keys(data).reduce((acc, videoUUID) => {
102 const date = Date.parse(data[videoUUID].date) 107 const date = Date.parse(data[videoUUID].date)