]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - 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
1 import { wait } from '@shared/core-utils'
2 import { HttpStatusCode } from '@shared/models'
3 import { unwrapBody, unwrapBodyOrDecodeToJSON, unwrapTextOrDecode } from '../requests'
4 import { AbstractCommand, OverrideCommandOptions } from '../shared'
5
6 export class StreamingPlaylistsCommand extends AbstractCommand {
7
8 async get (options: OverrideCommandOptions & {
9 url: string
10 withRetry?: boolean // default false
11 currentRetry?: number
12 }) {
13 const { withRetry, currentRetry = 1 } = options
14
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 }
37 }
38
39 getFragmentedSegment (options: OverrideCommandOptions & {
40 url: string
41 range?: string
42 }) {
43 return unwrapBody<Buffer>(this.getRawRequest({
44 ...options,
45
46 url: options.url,
47 range: options.range,
48 implicitToken: false,
49 defaultExpectedStatus: HttpStatusCode.OK_200
50 }))
51 }
52
53 getSegmentSha256 (options: OverrideCommandOptions & {
54 url: string
55 }) {
56 return unwrapBodyOrDecodeToJSON<{ [ id: string ]: string }>(this.getRawRequest({
57 ...options,
58
59 url: options.url,
60 implicitToken: false,
61 defaultExpectedStatus: HttpStatusCode.OK_200
62 }))
63 }
64 }