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'
7 export class ImportsCommand extends AbstractCommand {
9 importVideo (options: OverrideCommandOptions & {
10 attributes: (VideoImportCreate | { torrentfile?: string, previewfile?: string, thumbnailfile?: string })
12 const { attributes } = options
13 const path = '/api/v1/videos/imports'
15 let attaches: any = {}
16 if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile }
17 if (attributes.thumbnailfile) attaches = { thumbnailfile: attributes.thumbnailfile }
18 if (attributes.previewfile) attaches = { previewfile: attributes.previewfile }
20 return unwrapBody<VideoImport>(this.postUploadRequest({
25 fields: options.attributes,
27 defaultExpectedStatus: HttpStatusCode.OK_200
31 delete (options: OverrideCommandOptions & {
34 const path = '/api/v1/videos/imports/' + options.importId
36 return this.deleteRequest({
41 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
45 cancel (options: OverrideCommandOptions & {
48 const path = '/api/v1/videos/imports/' + options.importId + '/cancel'
50 return this.postBodyRequest({
55 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
59 getMyVideoImports (options: OverrideCommandOptions & {
62 videoChannelSyncId?: number
65 const { sort, targetUrl, videoChannelSyncId, search } = options
66 const path = '/api/v1/users/me/videos/imports'
68 return this.getRequestBody<ResultList<VideoImport>>({
72 query: { sort, targetUrl, videoChannelSyncId, search },
74 defaultExpectedStatus: HttpStatusCode.OK_200