diff options
author | Chocobozzz <me@florianbigard.com> | 2022-10-19 10:43:53 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2022-10-24 14:48:24 +0200 |
commit | 9ab330b90decf4edf152ff8e1d2948c065766b2c (patch) | |
tree | 29d924f50f7307e8e828a57ecb9ea78623487ce0 /server/lib/live/live-segment-sha-store.ts | |
parent | 3545e72c686ff1725bbdfd8d16d693e2f4aa75a3 (diff) | |
download | PeerTube-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.ts | 27 |
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' | |||
5 | import { MStreamingPlaylistVideo } from '@server/types/models' | 5 | import { MStreamingPlaylistVideo } from '@server/types/models' |
6 | import { buildSha256Segment } from '../hls' | 6 | import { buildSha256Segment } from '../hls' |
7 | import { storeHLSFileFromPath } from '../object-storage' | 7 | import { storeHLSFileFromPath } from '../object-storage' |
8 | import PQueue from 'p-queue' | ||
8 | 9 | ||
9 | const lTags = loggerTagsFactory('live') | 10 | const 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 | ||
73 | export { | 80 | export { |