accounts-command.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { Account, AccountVideoRate, ActorFollow, HttpStatusCode, ResultList, VideoRateType } from '@shared/models'
  2. import { AbstractCommand, OverrideCommandOptions } from '../shared'
  3. export class AccountsCommand extends AbstractCommand {
  4. list (options: OverrideCommandOptions & {
  5. sort?: string // default -createdAt
  6. } = {}) {
  7. const { sort = '-createdAt' } = options
  8. const path = '/api/v1/accounts'
  9. return this.getRequestBody<ResultList<Account>>({
  10. ...options,
  11. path,
  12. query: { sort },
  13. implicitToken: false,
  14. defaultExpectedStatus: HttpStatusCode.OK_200
  15. })
  16. }
  17. get (options: OverrideCommandOptions & {
  18. accountName: string
  19. }) {
  20. const path = '/api/v1/accounts/' + options.accountName
  21. return this.getRequestBody<Account>({
  22. ...options,
  23. path,
  24. implicitToken: false,
  25. defaultExpectedStatus: HttpStatusCode.OK_200
  26. })
  27. }
  28. listRatings (options: OverrideCommandOptions & {
  29. accountName: string
  30. rating?: VideoRateType
  31. }) {
  32. const { rating, accountName } = options
  33. const path = '/api/v1/accounts/' + accountName + '/ratings'
  34. const query = { rating }
  35. return this.getRequestBody<ResultList<AccountVideoRate>>({
  36. ...options,
  37. path,
  38. query,
  39. implicitToken: true,
  40. defaultExpectedStatus: HttpStatusCode.OK_200
  41. })
  42. }
  43. listFollowers (options: OverrideCommandOptions & {
  44. accountName: string
  45. start?: number
  46. count?: number
  47. sort?: string
  48. search?: string
  49. }) {
  50. const { accountName, start, count, sort, search } = options
  51. const path = '/api/v1/accounts/' + accountName + '/followers'
  52. const query = { start, count, sort, search }
  53. return this.getRequestBody<ResultList<ActorFollow>>({
  54. ...options,
  55. path,
  56. query,
  57. implicitToken: true,
  58. defaultExpectedStatus: HttpStatusCode.OK_200
  59. })
  60. }
  61. }