aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
Diffstat (limited to 'shared')
-rw-r--r--shared/server-commands/videos/live-command.ts2
-rw-r--r--shared/server-commands/videos/streaming-playlists-command.ts78
2 files changed, 60 insertions, 20 deletions
diff --git a/shared/server-commands/videos/live-command.ts b/shared/server-commands/videos/live-command.ts
index dc3c5a86e..2e4bc10b5 100644
--- a/shared/server-commands/videos/live-command.ts
+++ b/shared/server-commands/videos/live-command.ts
@@ -224,7 +224,7 @@ export class LiveCommand extends AbstractCommand {
224 const video = await server.videos.get({ id: videoUUID }) 224 const video = await server.videos.get({ id: videoUUID })
225 const hlsPlaylist = video.streamingPlaylists[0] 225 const hlsPlaylist = video.streamingPlaylists[0]
226 226
227 const shaBody = await server.streamingPlaylists.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url }) 227 const shaBody = await server.streamingPlaylists.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url, withRetry: objectStorage })
228 228
229 if (!shaBody[segmentName]) { 229 if (!shaBody[segmentName]) {
230 throw new Error('Segment SHA does not exist') 230 throw new Error('Segment SHA does not exist')
diff --git a/shared/server-commands/videos/streaming-playlists-command.ts b/shared/server-commands/videos/streaming-playlists-command.ts
index 7b92dcc0a..950808b60 100644
--- a/shared/server-commands/videos/streaming-playlists-command.ts
+++ b/shared/server-commands/videos/streaming-playlists-command.ts
@@ -44,31 +44,71 @@ export class StreamingPlaylistsCommand extends AbstractCommand {
44 } 44 }
45 } 45 }
46 46
47 getFragmentedSegment (options: OverrideCommandOptions & { 47 async getFragmentedSegment (options: OverrideCommandOptions & {
48 url: string 48 url: string
49 range?: string 49 range?: string
50
51 withRetry?: boolean // default false
52 currentRetry?: number
50 }) { 53 }) {
51 return unwrapBody<Buffer>(this.getRawRequest({ 54 const { withRetry, currentRetry = 1 } = options
52 ...options, 55
53 56 try {
54 url: options.url, 57 const result = await unwrapBody<Buffer>(this.getRawRequest({
55 range: options.range, 58 ...options,
56 implicitToken: false, 59
57 responseType: 'application/octet-stream', 60 url: options.url,
58 defaultExpectedStatus: HttpStatusCode.OK_200 61 range: options.range,
59 })) 62 implicitToken: false,
63 responseType: 'application/octet-stream',
64 defaultExpectedStatus: HttpStatusCode.OK_200
65 }))
66
67 return result
68 } catch (err) {
69 if (!withRetry || currentRetry > 5) throw err
70
71 await wait(100)
72
73 return this.getFragmentedSegment({
74 ...options,
75
76 withRetry,
77 currentRetry: currentRetry + 1
78 })
79 }
60 } 80 }
61 81
62 getSegmentSha256 (options: OverrideCommandOptions & { 82 async getSegmentSha256 (options: OverrideCommandOptions & {
63 url: string 83 url: string
84
85 withRetry?: boolean // default false
86 currentRetry?: number
64 }) { 87 }) {
65 return unwrapBodyOrDecodeToJSON<{ [ id: string ]: string }>(this.getRawRequest({ 88 const { withRetry, currentRetry = 1 } = options
66 ...options, 89
67 90 try {
68 url: options.url, 91 const result = await unwrapBodyOrDecodeToJSON<{ [ id: string ]: string }>(this.getRawRequest({
69 contentType: 'application/json', 92 ...options,
70 implicitToken: false, 93
71 defaultExpectedStatus: HttpStatusCode.OK_200 94 url: options.url,
72 })) 95 contentType: 'application/json',
96 implicitToken: false,
97 defaultExpectedStatus: HttpStatusCode.OK_200
98 }))
99
100 return result
101 } catch (err) {
102 if (!withRetry || currentRetry > 5) throw err
103
104 await wait(100)
105
106 return this.getSegmentSha256({
107 ...options,
108
109 withRetry,
110 currentRetry: currentRetry + 1
111 })
112 }
73 } 113 }
74} 114}