feeds-command.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { buildUUID } from '@shared/extra-utils'
  2. import { HttpStatusCode } from '@shared/models'
  3. import { AbstractCommand, OverrideCommandOptions } from '../shared'
  4. type FeedType = 'videos' | 'video-comments' | 'subscriptions'
  5. export class FeedCommand extends AbstractCommand {
  6. getXML (options: OverrideCommandOptions & {
  7. feed: FeedType
  8. ignoreCache: boolean
  9. format?: string
  10. }) {
  11. const { feed, format, ignoreCache } = options
  12. const path = '/feeds/' + feed + '.xml'
  13. const query: { [id: string]: string } = {}
  14. if (ignoreCache) query.v = buildUUID()
  15. if (format) query.format = format
  16. return this.getRequestText({
  17. ...options,
  18. path,
  19. query,
  20. accept: 'application/xml',
  21. implicitToken: false,
  22. defaultExpectedStatus: HttpStatusCode.OK_200
  23. })
  24. }
  25. getJSON (options: OverrideCommandOptions & {
  26. feed: FeedType
  27. ignoreCache: boolean
  28. query?: { [ id: string ]: any }
  29. }) {
  30. const { feed, query = {}, ignoreCache } = options
  31. const path = '/feeds/' + feed + '.json'
  32. const cacheQuery = ignoreCache
  33. ? { v: buildUUID() }
  34. : {}
  35. return this.getRequestText({
  36. ...options,
  37. path,
  38. query: { ...query, ...cacheQuery },
  39. accept: 'application/json',
  40. implicitToken: false,
  41. defaultExpectedStatus: HttpStatusCode.OK_200
  42. })
  43. }
  44. }