]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/server-commands/videos/imports-command.ts
Bumped to version v5.2.1
[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 9 importVideo (options: OverrideCommandOptions & {
d41f4a6d 10 attributes: (VideoImportCreate | { torrentfile?: string, previewfile?: string, thumbnailfile?: string })
6910f20f
C
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 }
d41f4a6d
C
17 if (attributes.thumbnailfile) attaches = { thumbnailfile: attributes.thumbnailfile }
18 if (attributes.previewfile) attaches = { previewfile: attributes.previewfile }
6910f20f
C
19
20 return unwrapBody<VideoImport>(this.postUploadRequest({
21 ...options,
22
23 path,
24 attaches,
25 fields: options.attributes,
26 implicitToken: true,
27 defaultExpectedStatus: HttpStatusCode.OK_200
28 }))
29 }
30
419b520c
C
31 delete (options: OverrideCommandOptions & {
32 importId: number
33 }) {
34 const path = '/api/v1/videos/imports/' + options.importId
35
36 return this.deleteRequest({
37 ...options,
38
39 path,
40 implicitToken: true,
41 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
42 })
43 }
44
45 cancel (options: OverrideCommandOptions & {
46 importId: number
47 }) {
48 const path = '/api/v1/videos/imports/' + options.importId + '/cancel'
49
50 return this.postBodyRequest({
51 ...options,
52
53 path,
54 implicitToken: true,
55 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
56 })
57 }
58
6910f20f
C
59 getMyVideoImports (options: OverrideCommandOptions & {
60 sort?: string
d511df28 61 targetUrl?: string
a3b472a1
C
62 videoChannelSyncId?: number
63 search?: string
6910f20f 64 } = {}) {
a3b472a1 65 const { sort, targetUrl, videoChannelSyncId, search } = options
6910f20f
C
66 const path = '/api/v1/users/me/videos/imports'
67
6910f20f
C
68 return this.getRequestBody<ResultList<VideoImport>>({
69 ...options,
70
71 path,
a3b472a1 72 query: { sort, targetUrl, videoChannelSyncId, search },
6910f20f
C
73 implicitToken: true,
74 defaultExpectedStatus: HttpStatusCode.OK_200
75 })
76 }
77}