]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - shared/server-commands/videos/streaming-playlists-command.ts
Increase timeouts
[github/Chocobozzz/PeerTube.git] / shared / server-commands / videos / streaming-playlists-command.ts
... / ...
CommitLineData
1import { wait } from '@shared/core-utils'
2import { HttpStatusCode } from '@shared/models'
3import { unwrapBody, unwrapBodyOrDecodeToJSON, unwrapTextOrDecode } from '../requests'
4import { AbstractCommand, OverrideCommandOptions } from '../shared'
5
6export class StreamingPlaylistsCommand extends AbstractCommand {
7
8 async get (options: OverrideCommandOptions & {
9 url: string
10
11 videoFileToken?: string
12 reinjectVideoFileToken?: boolean
13
14 withRetry?: boolean // default false
15 currentRetry?: number
16 }): Promise<string> {
17 const { videoFileToken, reinjectVideoFileToken, withRetry, currentRetry = 1 } = options
18
19 try {
20 const result = await unwrapTextOrDecode(this.getRawRequest({
21 ...options,
22
23 url: options.url,
24 query: {
25 videoFileToken,
26 reinjectVideoFileToken
27 },
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 }
45 }
46
47 getFragmentedSegment (options: OverrideCommandOptions & {
48 url: string
49 range?: string
50 }) {
51 return unwrapBody<Buffer>(this.getRawRequest({
52 ...options,
53
54 url: options.url,
55 range: options.range,
56 implicitToken: false,
57 responseType: 'application/octet-stream',
58 defaultExpectedStatus: HttpStatusCode.OK_200
59 }))
60 }
61
62 getSegmentSha256 (options: OverrideCommandOptions & {
63 url: string
64 }) {
65 return unwrapBodyOrDecodeToJSON<{ [ id: string ]: string }>(this.getRawRequest({
66 ...options,
67
68 url: options.url,
69 contentType: 'application/json',
70 implicitToken: false,
71 defaultExpectedStatus: HttpStatusCode.OK_200
72 }))
73 }
74}