aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/live/live-segment-sha-store.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-10-19 10:43:53 +0200
committerChocobozzz <chocobozzz@cpy.re>2022-10-24 14:48:24 +0200
commit9ab330b90decf4edf152ff8e1d2948c065766b2c (patch)
tree29d924f50f7307e8e828a57ecb9ea78623487ce0 /server/lib/live/live-segment-sha-store.ts
parent3545e72c686ff1725bbdfd8d16d693e2f4aa75a3 (diff)
downloadPeerTube-9ab330b90decf4edf152ff8e1d2948c065766b2c.tar.gz
PeerTube-9ab330b90decf4edf152ff8e1d2948c065766b2c.tar.zst
PeerTube-9ab330b90decf4edf152ff8e1d2948c065766b2c.zip
Use private ACL for private videos in s3
Diffstat (limited to 'server/lib/live/live-segment-sha-store.ts')
-rw-r--r--server/lib/live/live-segment-sha-store.ts27
1 files changed, 17 insertions, 10 deletions
diff --git a/server/lib/live/live-segment-sha-store.ts b/server/lib/live/live-segment-sha-store.ts
index faf03dccf..4d03754a9 100644
--- a/server/lib/live/live-segment-sha-store.ts
+++ b/server/lib/live/live-segment-sha-store.ts
@@ -5,6 +5,7 @@ import { logger, loggerTagsFactory } from '@server/helpers/logger'
5import { MStreamingPlaylistVideo } from '@server/types/models' 5import { MStreamingPlaylistVideo } from '@server/types/models'
6import { buildSha256Segment } from '../hls' 6import { buildSha256Segment } from '../hls'
7import { storeHLSFileFromPath } from '../object-storage' 7import { storeHLSFileFromPath } from '../object-storage'
8import PQueue from 'p-queue'
8 9
9const lTags = loggerTagsFactory('live') 10const lTags = loggerTagsFactory('live')
10 11
@@ -16,6 +17,7 @@ class LiveSegmentShaStore {
16 private readonly sha256Path: string 17 private readonly sha256Path: string
17 private readonly streamingPlaylist: MStreamingPlaylistVideo 18 private readonly streamingPlaylist: MStreamingPlaylistVideo
18 private readonly sendToObjectStorage: boolean 19 private readonly sendToObjectStorage: boolean
20 private readonly writeQueue = new PQueue({ concurrency: 1 })
19 21
20 constructor (options: { 22 constructor (options: {
21 videoUUID: string 23 videoUUID: string
@@ -37,7 +39,11 @@ class LiveSegmentShaStore {
37 const segmentName = basename(segmentPath) 39 const segmentName = basename(segmentPath)
38 this.segmentsSha256.set(segmentName, shaResult) 40 this.segmentsSha256.set(segmentName, shaResult)
39 41
40 await this.writeToDisk() 42 try {
43 await this.writeToDisk()
44 } catch (err) {
45 logger.error('Cannot write sha segments to disk.', { err })
46 }
41 } 47 }
42 48
43 async removeSegmentSha (segmentPath: string) { 49 async removeSegmentSha (segmentPath: string) {
@@ -55,19 +61,20 @@ class LiveSegmentShaStore {
55 await this.writeToDisk() 61 await this.writeToDisk()
56 } 62 }
57 63
58 private async writeToDisk () { 64 private writeToDisk () {
59 await writeJson(this.sha256Path, mapToJSON(this.segmentsSha256)) 65 return this.writeQueue.add(async () => {
66 await writeJson(this.sha256Path, mapToJSON(this.segmentsSha256))
60 67
61 if (this.sendToObjectStorage) { 68 if (this.sendToObjectStorage) {
62 const url = await storeHLSFileFromPath(this.streamingPlaylist, this.sha256Path) 69 const url = await storeHLSFileFromPath(this.streamingPlaylist, this.sha256Path)
63 70
64 if (this.streamingPlaylist.segmentsSha256Url !== url) { 71 if (this.streamingPlaylist.segmentsSha256Url !== url) {
65 this.streamingPlaylist.segmentsSha256Url = url 72 this.streamingPlaylist.segmentsSha256Url = url
66 await this.streamingPlaylist.save() 73 await this.streamingPlaylist.save()
74 }
67 } 75 }
68 } 76 })
69 } 77 }
70
71} 78}
72 79
73export { 80export {