diff options
Diffstat (limited to 'packages/server-commands/src/videos/imports-command.ts')
-rw-r--r-- | packages/server-commands/src/videos/imports-command.ts | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/packages/server-commands/src/videos/imports-command.ts b/packages/server-commands/src/videos/imports-command.ts new file mode 100644 index 000000000..1a1931d64 --- /dev/null +++ b/packages/server-commands/src/videos/imports-command.ts | |||
@@ -0,0 +1,76 @@ | |||
1 | |||
2 | import { HttpStatusCode, ResultList, VideoImport, VideoImportCreate } from '@peertube/peertube-models' | ||
3 | import { unwrapBody } from '../requests/index.js' | ||
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared/index.js' | ||
5 | |||
6 | export class ImportsCommand extends AbstractCommand { | ||
7 | |||
8 | importVideo (options: OverrideCommandOptions & { | ||
9 | attributes: (VideoImportCreate | { torrentfile?: string, previewfile?: string, thumbnailfile?: string }) | ||
10 | }) { | ||
11 | const { attributes } = options | ||
12 | const path = '/api/v1/videos/imports' | ||
13 | |||
14 | let attaches: any = {} | ||
15 | if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile } | ||
16 | if (attributes.thumbnailfile) attaches = { thumbnailfile: attributes.thumbnailfile } | ||
17 | if (attributes.previewfile) attaches = { previewfile: attributes.previewfile } | ||
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 | delete (options: OverrideCommandOptions & { | ||
31 | importId: number | ||
32 | }) { | ||
33 | const path = '/api/v1/videos/imports/' + options.importId | ||
34 | |||
35 | return this.deleteRequest({ | ||
36 | ...options, | ||
37 | |||
38 | path, | ||
39 | implicitToken: true, | ||
40 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
41 | }) | ||
42 | } | ||
43 | |||
44 | cancel (options: OverrideCommandOptions & { | ||
45 | importId: number | ||
46 | }) { | ||
47 | const path = '/api/v1/videos/imports/' + options.importId + '/cancel' | ||
48 | |||
49 | return this.postBodyRequest({ | ||
50 | ...options, | ||
51 | |||
52 | path, | ||
53 | implicitToken: true, | ||
54 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
55 | }) | ||
56 | } | ||
57 | |||
58 | getMyVideoImports (options: OverrideCommandOptions & { | ||
59 | sort?: string | ||
60 | targetUrl?: string | ||
61 | videoChannelSyncId?: number | ||
62 | search?: string | ||
63 | } = {}) { | ||
64 | const { sort, targetUrl, videoChannelSyncId, search } = options | ||
65 | const path = '/api/v1/users/me/videos/imports' | ||
66 | |||
67 | return this.getRequestBody<ResultList<VideoImport>>({ | ||
68 | ...options, | ||
69 | |||
70 | path, | ||
71 | query: { sort, targetUrl, videoChannelSyncId, search }, | ||
72 | implicitToken: true, | ||
73 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
74 | }) | ||
75 | } | ||
76 | } | ||