1
0
Fork 0
peertube/shared/server-commands/videos/imports-command.ts

74 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-07-08 10:49:51 -04:00
2021-07-16 08:27:30 -04:00
import { HttpStatusCode, ResultList } from '@shared/models'
2021-07-08 10:49:51 -04:00
import { VideoImport, VideoImportCreate } from '../../models/videos'
import { unwrapBody } from '../requests'
import { AbstractCommand, OverrideCommandOptions } from '../shared'
export class ImportsCommand extends AbstractCommand {
importVideo (options: OverrideCommandOptions & {
attributes: VideoImportCreate & { torrentfile?: string }
}) {
const { attributes } = options
const path = '/api/v1/videos/imports'
let attaches: any = {}
if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile }
return unwrapBody<VideoImport>(this.postUploadRequest({
...options,
path,
attaches,
fields: options.attributes,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
}))
}
delete (options: OverrideCommandOptions & {
importId: number
}) {
const path = '/api/v1/videos/imports/' + options.importId
return this.deleteRequest({
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
cancel (options: OverrideCommandOptions & {
importId: number
}) {
const path = '/api/v1/videos/imports/' + options.importId + '/cancel'
return this.postBodyRequest({
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
2021-07-08 10:49:51 -04:00
getMyVideoImports (options: OverrideCommandOptions & {
sort?: string
targetUrl?: string
2021-07-08 10:49:51 -04:00
} = {}) {
const { sort, targetUrl } = options
2021-07-08 10:49:51 -04:00
const path = '/api/v1/users/me/videos/imports'
return this.getRequestBody<ResultList<VideoImport>>({
...options,
path,
query: { sort, targetUrl },
2021-07-08 10:49:51 -04:00
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
}