imports-command.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { HttpStatusCode, ResultList } from '@shared/models'
  2. import { VideoImport, VideoImportCreate } from '../../models/videos'
  3. import { unwrapBody } from '../requests'
  4. import { AbstractCommand, OverrideCommandOptions } from '../shared'
  5. export class ImportsCommand extends AbstractCommand {
  6. importVideo (options: OverrideCommandOptions & {
  7. attributes: VideoImportCreate & { torrentfile?: string }
  8. }) {
  9. const { attributes } = options
  10. const path = '/api/v1/videos/imports'
  11. let attaches: any = {}
  12. if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile }
  13. return unwrapBody<VideoImport>(this.postUploadRequest({
  14. ...options,
  15. path,
  16. attaches,
  17. fields: options.attributes,
  18. implicitToken: true,
  19. defaultExpectedStatus: HttpStatusCode.OK_200
  20. }))
  21. }
  22. delete (options: OverrideCommandOptions & {
  23. importId: number
  24. }) {
  25. const path = '/api/v1/videos/imports/' + options.importId
  26. return this.deleteRequest({
  27. ...options,
  28. path,
  29. implicitToken: true,
  30. defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
  31. })
  32. }
  33. cancel (options: OverrideCommandOptions & {
  34. importId: number
  35. }) {
  36. const path = '/api/v1/videos/imports/' + options.importId + '/cancel'
  37. return this.postBodyRequest({
  38. ...options,
  39. path,
  40. implicitToken: true,
  41. defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
  42. })
  43. }
  44. getMyVideoImports (options: OverrideCommandOptions & {
  45. sort?: string
  46. targetUrl?: string
  47. videoChannelSyncId?: number
  48. search?: string
  49. } = {}) {
  50. const { sort, targetUrl, videoChannelSyncId, search } = options
  51. const path = '/api/v1/users/me/videos/imports'
  52. return this.getRequestBody<ResultList<VideoImport>>({
  53. ...options,
  54. path,
  55. query: { sort, targetUrl, videoChannelSyncId, search },
  56. implicitToken: true,
  57. defaultExpectedStatus: HttpStatusCode.OK_200
  58. })
  59. }
  60. }