]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/server-commands/videos/imports-command.ts
c931ac481c2e7179841a53131194c0bc45105a44
[github/Chocobozzz/PeerTube.git] / shared / server-commands / videos / imports-command.ts
1
2 import { HttpStatusCode, ResultList } from '@shared/models'
3 import { VideoImport, VideoImportCreate } from '../../models/videos'
4 import { unwrapBody } from '../requests'
5 import { AbstractCommand, OverrideCommandOptions } from '../shared'
6
7 export class ImportsCommand extends AbstractCommand {
8
9 importVideo (options: OverrideCommandOptions & {
10 attributes: VideoImportCreate & { torrentfile?: string }
11 }) {
12 const { attributes } = options
13 const path = '/api/v1/videos/imports'
14
15 let attaches: any = {}
16 if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile }
17
18 return unwrapBody<VideoImport>(this.postUploadRequest({
19 ...options,
20
21 path,
22 attaches,
23 fields: options.attributes,
24 implicitToken: true,
25 defaultExpectedStatus: HttpStatusCode.OK_200
26 }))
27 }
28
29 delete (options: OverrideCommandOptions & {
30 importId: number
31 }) {
32 const path = '/api/v1/videos/imports/' + options.importId
33
34 return this.deleteRequest({
35 ...options,
36
37 path,
38 implicitToken: true,
39 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
40 })
41 }
42
43 cancel (options: OverrideCommandOptions & {
44 importId: number
45 }) {
46 const path = '/api/v1/videos/imports/' + options.importId + '/cancel'
47
48 return this.postBodyRequest({
49 ...options,
50
51 path,
52 implicitToken: true,
53 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
54 })
55 }
56
57 getMyVideoImports (options: OverrideCommandOptions & {
58 sort?: string
59 targetUrl?: string
60 } = {}) {
61 const { sort, targetUrl } = options
62 const path = '/api/v1/users/me/videos/imports'
63
64 return this.getRequestBody<ResultList<VideoImport>>({
65 ...options,
66
67 path,
68 query: { sort, targetUrl },
69 implicitToken: true,
70 defaultExpectedStatus: HttpStatusCode.OK_200
71 })
72 }
73 }