aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/server-commands/videos/imports-command.ts
blob: f63ed5d4bc3db2abe5ccee524831eaf37b3ca605 (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
import { HttpStatusCode, ResultList } from '@shared/models'
import { VideoImport, VideoImportCreate } from '../../models/videos'
import { unwrapBody } from '../requests'
import { AbstractCommand, OverrideCommandOptions } from '../shared'

export class ImportsCommand extends AbstractCommand {

  importVideo (options: OverrideCommandOptions & {
    attributes: VideoImportCreate & { torrentfile?: string }
  }) {
    const { attributes } = options
    const path = '/api/v1/videos/imports'

    let attaches: any = {}
    if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile }

    return unwrapBody<VideoImport>(this.postUploadRequest({
      ...options,

      path,
      attaches,
      fields: options.attributes,
      implicitToken: true,
      defaultExpectedStatus: HttpStatusCode.OK_200
    }))
  }

  delete (options: OverrideCommandOptions & {
    importId: number
  }) {
    const path = '/api/v1/videos/imports/' + options.importId

    return this.deleteRequest({
      ...options,

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

  cancel (options: OverrideCommandOptions & {
    importId: number
  }) {
    const path = '/api/v1/videos/imports/' + options.importId + '/cancel'

    return this.postBodyRequest({
      ...options,

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

  getMyVideoImports (options: OverrideCommandOptions & {
    sort?: string
  } = {}) {
    const { sort } = options
    const path = '/api/v1/users/me/videos/imports'

    const query = {}
    if (sort) query['sort'] = sort

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

      path,
      query: { sort },
      implicitToken: true,
      defaultExpectedStatus: HttpStatusCode.OK_200
    })
  }
}