aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/assets')
-rw-r--r--client/src/assets/player/peertube-chunk-store.ts59
1 files changed, 35 insertions, 24 deletions
diff --git a/client/src/assets/player/peertube-chunk-store.ts b/client/src/assets/player/peertube-chunk-store.ts
index 84fbaf146..e14e31c04 100644
--- a/client/src/assets/player/peertube-chunk-store.ts
+++ b/client/src/assets/player/peertube-chunk-store.ts
@@ -155,17 +155,17 @@ export class PeertubeChunkStore extends EventEmitter {
155 this.cleanerInterval = null 155 this.cleanerInterval = null
156 } 156 }
157 157
158 if (this.db) {
159 await this.db.close()
160
161 await this.dropDatabase(this.databaseName)
162 }
163
158 if (this.expirationDB) { 164 if (this.expirationDB) {
159 await this.expirationDB.close() 165 await this.expirationDB.close()
160 this.expirationDB = null 166 this.expirationDB = null
161 } 167 }
162 168
163 if (this.db) {
164 console.log('Destroying IndexDB database %s.', this.databaseName)
165 await this.db.close()
166 await this.db.delete()
167 }
168
169 return cb() 169 return cb()
170 } catch (err) { 170 } catch (err) {
171 console.error('Cannot destroy peertube chunk store.', err) 171 console.error('Cannot destroy peertube chunk store.', err)
@@ -181,31 +181,42 @@ export class PeertubeChunkStore extends EventEmitter {
181 }, PeertubeChunkStore.CLEANER_INTERVAL_MS) 181 }, PeertubeChunkStore.CLEANER_INTERVAL_MS)
182 } 182 }
183 183
184 private checkExpiration () { 184 private async checkExpiration () {
185 this.expirationDB.transaction('rw', this.expirationDB.databases, async () => { 185 let databasesToDeleteInfo: { name: string }[] = []
186 // Update our database expiration since we are alive
187 await this.expirationDB.databases.put({
188 name: this.databaseName,
189 expiration: new Date().getTime() + PeertubeChunkStore.CLEANER_EXPIRATION_MS
190 })
191 186
192 const now = new Date().getTime() 187 try {
193 const databasesToDeleteInfo = await this.expirationDB.databases.where('expiration').below(now).toArray() 188 await this.expirationDB.transaction('rw', this.expirationDB.databases, async () => {
189 // Update our database expiration since we are alive
190 await this.expirationDB.databases.put({
191 name: this.databaseName,
192 expiration: new Date().getTime() + PeertubeChunkStore.CLEANER_EXPIRATION_MS
193 })
194 194
195 for (const databaseToDeleteInfo of databasesToDeleteInfo) { 195 const now = new Date().getTime()
196 await this.dropDatabase(databaseToDeleteInfo.name) 196 databasesToDeleteInfo = await this.expirationDB.databases.where('expiration').below(now).toArray()
197 })
198 } catch (err) {
199 console.error('Cannot update expiration of fetch expired databases.', err)
200 }
197 201
198 await this.expirationDB.databases.where({ name: databaseToDeleteInfo.name }).delete() 202 for (const databaseToDeleteInfo of databasesToDeleteInfo) {
199 } 203 await this.dropDatabase(databaseToDeleteInfo.name)
200 }).catch(err => console.error('Cannot check expiration.', err)) 204 }
201 } 205 }
202 206
203 private dropDatabase (databaseName: string) { 207 private async dropDatabase (databaseName: string) {
204 const dbToDelete = new ChunkDatabase(databaseName) 208 const dbToDelete = new ChunkDatabase(databaseName)
209 console.log('Destroying IndexDB database %s.', databaseName)
205 210
206 console.log('Deleting %s.', databaseName) 211 try {
207 return dbToDelete.delete() 212 await dbToDelete.delete()
208 .catch(err => console.error('Cannot delete %s.', databaseName)) 213
214 await this.expirationDB.transaction('rw', this.expirationDB.databases, () => {
215 return this.expirationDB.databases.where({ name: databaseName }).delete()
216 })
217 } catch (err) {
218 console.error('Cannot delete %s.', databaseName, err)
219 }
209 } 220 }
210 221
211 private nextTick (cb, err, val?) { 222 private nextTick (cb, err, val?) {