aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-25 15:40:59 +0200
committerChocobozzz <me@florianbigard.com>2021-06-25 15:40:59 +0200
commitc6bfbaebe759caa679f23674fed2ba5c9aee5217 (patch)
tree950c38d9948f4d6647499b944c368e3116fbb83e /client/src
parent2b58ca796df4969622c32e4f34f4e02112e577d7 (diff)
downloadPeerTube-c6bfbaebe759caa679f23674fed2ba5c9aee5217.tar.gz
PeerTube-c6bfbaebe759caa679f23674fed2ba5c9aee5217.tar.zst
PeerTube-c6bfbaebe759caa679f23674fed2ba5c9aee5217.zip
Fix error when cookies are disabled
Diffstat (limited to 'client/src')
-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)