]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/server-commands/videos/imports-command.ts
Add ability to list imports of a channel sync
[github/Chocobozzz/PeerTube.git] / shared / server-commands / videos / imports-command.ts
CommitLineData
6910f20f 1
4c7e60bc 2import { HttpStatusCode, ResultList } from '@shared/models'
6910f20f
C
3import { VideoImport, VideoImportCreate } from '../../models/videos'
4import { unwrapBody } from '../requests'
5import { AbstractCommand, OverrideCommandOptions } from '../shared'
6
7export class ImportsCommand extends AbstractCommand {
8
6910f20f
C
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
419b520c
C
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
6910f20f
C
57 getMyVideoImports (options: OverrideCommandOptions & {
58 sort?: string
d511df28 59 targetUrl?: string
a3b472a1
C
60 videoChannelSyncId?: number
61 search?: string
6910f20f 62 } = {}) {
a3b472a1 63 const { sort, targetUrl, videoChannelSyncId, search } = options
6910f20f
C
64 const path = '/api/v1/users/me/videos/imports'
65
6910f20f
C
66 return this.getRequestBody<ResultList<VideoImport>>({
67 ...options,
68
69 path,
a3b472a1 70 query: { sort, targetUrl, videoChannelSyncId, search },
6910f20f
C
71 implicitToken: true,
72 defaultExpectedStatus: HttpStatusCode.OK_200
73 })
74 }
75}