]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/videos/imports-command.ts
Refactor requests
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / videos / imports-command.ts
CommitLineData
6910f20f 1
c0e8b12e 2import { HttpStatusCode } from '@shared/models'
6910f20f 3import { ResultList } from '@shared/models'
6910f20f
C
4import { VideoImport, VideoImportCreate } from '../../models/videos'
5import { unwrapBody } from '../requests'
6import { AbstractCommand, OverrideCommandOptions } from '../shared'
7
8export class ImportsCommand extends AbstractCommand {
9
6910f20f
C
10 importVideo (options: OverrideCommandOptions & {
11 attributes: VideoImportCreate & { torrentfile?: string }
12 }) {
13 const { attributes } = options
14 const path = '/api/v1/videos/imports'
15
16 let attaches: any = {}
17 if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile }
18
19 return unwrapBody<VideoImport>(this.postUploadRequest({
20 ...options,
21
22 path,
23 attaches,
24 fields: options.attributes,
25 implicitToken: true,
26 defaultExpectedStatus: HttpStatusCode.OK_200
27 }))
28 }
29
30 getMyVideoImports (options: OverrideCommandOptions & {
31 sort?: string
32 } = {}) {
33 const { sort } = options
34 const path = '/api/v1/users/me/videos/imports'
35
36 const query = {}
37 if (sort) query['sort'] = sort
38
39 return this.getRequestBody<ResultList<VideoImport>>({
40 ...options,
41
42 path,
43 query: { sort },
44 implicitToken: true,
45 defaultExpectedStatus: HttpStatusCode.OK_200
46 })
47 }
48}