aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/server/redundancy-command.ts
blob: e7a8b3c29ec86013568590b69b9c7d3282ad0ab9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { HttpStatusCode, ResultList, VideoRedundanciesTarget, VideoRedundancy } from '@shared/models'
import { AbstractCommand, OverrideCommandOptions } from '../shared'

export class RedundancyCommand extends AbstractCommand {

  updateRedundancy (options: OverrideCommandOptions & {
    host: string
    redundancyAllowed: boolean
  }) {
    const { host, redundancyAllowed } = options
    const path = '/api/v1/server/redundancy/' + host

    return this.putBodyRequest({
      ...options,

      path,
      fields: { redundancyAllowed },
      implicitToken: true,
      defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
    })
  }

  listVideos (options: OverrideCommandOptions & {
    target: VideoRedundanciesTarget
    start?: number
    count?: number
    sort?: string
  }) {
    const path = '/api/v1/server/redundancy/videos'

    const { target, start, count, sort } = options

    return this.getRequestBody<ResultList<VideoRedundancy>>({
      ...options,

      path,

      query: {
        start: start ?? 0,
        count: count ?? 5,
        sort: sort ?? 'name',
        target
      },

      implicitToken: true,
      defaultExpectedStatus: HttpStatusCode.OK_200
    })
  }

  addVideo (options: OverrideCommandOptions & {
    videoId: number
  }) {
    const path = '/api/v1/server/redundancy/videos'
    const { videoId } = options

    return this.postBodyRequest({
      ...options,

      path,
      fields: { videoId },
      implicitToken: true,
      defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
    })
  }

  removeVideo (options: OverrideCommandOptions & {
    redundancyId: number
  }) {
    const { redundancyId } = options
    const path = '/api/v1/server/redundancy/videos/' + redundancyId

    return this.deleteRequest({
      ...options,

      path,
      implicitToken: true,
      defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
    })
  }
}