]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/server-commands/videos/streaming-playlists-command.ts
Increase timeouts
[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
71e3e879
C
10
11 videoFileToken?: string
12 reinjectVideoFileToken?: boolean
13
34aa316f
C
14 withRetry?: boolean // default false
15 currentRetry?: number
d102de1b 16 }): Promise<string> {
71e3e879 17 const { videoFileToken, reinjectVideoFileToken, withRetry, currentRetry = 1 } = options
57f879a5 18
34aa316f
C
19 try {
20 const result = await unwrapTextOrDecode(this.getRawRequest({
21 ...options,
22
23 url: options.url,
71e3e879
C
24 query: {
25 videoFileToken,
26 reinjectVideoFileToken
27 },
34aa316f
C
28 implicitToken: false,
29 defaultExpectedStatus: HttpStatusCode.OK_200
30 }))
31
32 return result
33 } catch (err) {
34 if (!withRetry || currentRetry > 5) throw err
35
36 await wait(100)
37
38 return this.get({
39 ...options,
40
41 withRetry,
42 currentRetry: currentRetry + 1
43 })
44 }
57f879a5
C
45 }
46
cfd57d2c 47 getFragmentedSegment (options: OverrideCommandOptions & {
57f879a5
C
48 url: string
49 range?: string
50 }) {
dd0ebb71 51 return unwrapBody<Buffer>(this.getRawRequest({
57f879a5
C
52 ...options,
53
54 url: options.url,
55 range: options.range,
56 implicitToken: false,
d102de1b 57 responseType: 'application/octet-stream',
12edc149 58 defaultExpectedStatus: HttpStatusCode.OK_200
57f879a5
C
59 }))
60 }
61
62 getSegmentSha256 (options: OverrideCommandOptions & {
63 url: string
64 }) {
0305db28 65 return unwrapBodyOrDecodeToJSON<{ [ id: string ]: string }>(this.getRawRequest({
57f879a5
C
66 ...options,
67
68 url: options.url,
d102de1b 69 contentType: 'application/json',
57f879a5
C
70 implicitToken: false,
71 defaultExpectedStatus: HttpStatusCode.OK_200
72 }))
73 }
74}