]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/assets/player/webtorrent/peertube-chunk-store.ts
Better display redundancy pies
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / webtorrent / peertube-chunk-store.ts
index 54cc0ea64d0669ccc80086ed67a5b881ec1f0195..81378c2777ccac5debb6d46ad2fbf3e1005f0f99 100644 (file)
@@ -36,7 +36,7 @@ export class PeertubeChunkStore extends EventEmitter {
 
   chunkLength: number
 
-  private pendingPut: { id: number, buf: Buffer, cb: Function }[] = []
+  private pendingPut: { id: number, buf: Buffer, cb: (err?: Error) => void }[] = []
   // If the store is full
   private memoryChunks: { [ id: number ]: Buffer | true } = {}
   private databaseName: string
@@ -54,7 +54,7 @@ export class PeertubeChunkStore extends EventEmitter {
     this.databaseName = 'webtorrent-chunks-'
 
     if (!opts) opts = {}
-    if (opts.torrent && opts.torrent.infoHash) this.databaseName += opts.torrent.infoHash
+    if (opts.torrent?.infoHash) this.databaseName += opts.torrent.infoHash
     else this.databaseName += '-default'
 
     this.setMaxListeners(100)
@@ -106,7 +106,9 @@ export class PeertubeChunkStore extends EventEmitter {
       } catch (err) {
         console.log('Cannot bulk insert chunks. Store them in memory.', { err })
 
-        processing.forEach(p => this.memoryChunks[ p.id ] = p.buf)
+        processing.forEach(p => {
+          this.memoryChunks[p.id] = p.buf
+        })
       } finally {
         processing.forEach(p => p.cb())
       }
@@ -131,7 +133,7 @@ export class PeertubeChunkStore extends EventEmitter {
     // Chunk in store
     this.db.transaction('r', this.db.chunks, async () => {
       const result = await this.db.chunks.get({ id: index })
-      if (result === undefined) return cb(null, new Buffer(0))
+      if (result === undefined) return cb(null, Buffer.alloc(0))
 
       const buf = result.buf
       if (!opts) return this.nextTick(cb, null, buf)
@@ -162,13 +164,13 @@ export class PeertubeChunkStore extends EventEmitter {
       }
 
       if (this.db) {
-        await this.db.close()
+        this.db.close()
 
         await this.dropDatabase(this.databaseName)
       }
 
       if (this.expirationDB) {
-        await this.expirationDB.close()
+        this.expirationDB.close()
         this.expirationDB = null
       }
 
@@ -182,7 +184,7 @@ export class PeertubeChunkStore extends EventEmitter {
   private runCleaner () {
     this.checkExpiration()
 
-    this.cleanerInterval = setInterval(async () => {
+    this.cleanerInterval = setInterval(() => {
       this.checkExpiration()
     }, PeertubeChunkStore.CLEANER_INTERVAL_MS)
   }