]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/server-commands/videos/streaming-playlists-command.ts
Merge branch 'release/4.3.0' into develop
[github/Chocobozzz/PeerTube.git] / shared / server-commands / videos / streaming-playlists-command.ts
CommitLineData
34aa316f 1import { wait } from '@shared/core-utils'
c0e8b12e 2import { HttpStatusCode } from '@shared/models'
34aa316f 3import { unwrapBody, unwrapBodyOrDecodeToJSON, unwrapTextOrDecode } from '../requests'
57f879a5
C
4import { AbstractCommand, OverrideCommandOptions } from '../shared'
5
6export class StreamingPlaylistsCommand extends AbstractCommand {
7
34aa316f 8 async get (options: OverrideCommandOptions & {
57f879a5 9 url: string
34aa316f
C
10 withRetry?: boolean // default false
11 currentRetry?: number
57f879a5 12 }) {
34aa316f 13 const { withRetry, currentRetry = 1 } = options
57f879a5 14
34aa316f
C
15 try {
16 const result = await unwrapTextOrDecode(this.getRawRequest({
17 ...options,
18
19 url: options.url,
20 implicitToken: false,
21 defaultExpectedStatus: HttpStatusCode.OK_200
22 }))
23
24 return result
25 } catch (err) {
26 if (!withRetry || currentRetry > 5) throw err
27
28 await wait(100)
29
30 return this.get({
31 ...options,
32
33 withRetry,
34 currentRetry: currentRetry + 1
35 })
36 }
57f879a5
C
37 }
38
cfd57d2c 39 getFragmentedSegment (options: OverrideCommandOptions & {
57f879a5
C
40 url: string
41 range?: string
42 }) {
dd0ebb71 43 return unwrapBody<Buffer>(this.getRawRequest({
57f879a5
C
44 ...options,
45
46 url: options.url,
47 range: options.range,
48 implicitToken: false,
12edc149 49 defaultExpectedStatus: HttpStatusCode.OK_200
57f879a5
C
50 }))
51 }
52
53 getSegmentSha256 (options: OverrideCommandOptions & {
54 url: string
55 }) {
0305db28 56 return unwrapBodyOrDecodeToJSON<{ [ id: string ]: string }>(this.getRawRequest({
57f879a5
C
57 ...options,
58
59 url: options.url,
60 implicitToken: false,
61 defaultExpectedStatus: HttpStatusCode.OK_200
62 }))
63 }
64}