2022-06-27 04:36:16 -04:00
|
|
|
import { buildUUID } from '@shared/extra-utils'
|
2021-07-16 04:42:24 -04:00
|
|
|
import { HttpStatusCode } from '@shared/models'
|
2021-07-06 04:21:35 -04:00
|
|
|
import { AbstractCommand, OverrideCommandOptions } from '../shared'
|
2018-04-18 10:08:36 -04:00
|
|
|
|
2020-11-09 10:25:27 -05:00
|
|
|
type FeedType = 'videos' | 'video-comments' | 'subscriptions'
|
2018-06-08 14:34:37 -04:00
|
|
|
|
2021-07-06 04:21:35 -04:00
|
|
|
export class FeedCommand extends AbstractCommand {
|
2018-04-18 10:08:36 -04:00
|
|
|
|
2021-07-06 04:21:35 -04:00
|
|
|
getXML (options: OverrideCommandOptions & {
|
|
|
|
feed: FeedType
|
2022-06-27 04:36:16 -04:00
|
|
|
ignoreCache: boolean
|
2021-07-06 04:21:35 -04:00
|
|
|
format?: string
|
|
|
|
}) {
|
2022-06-27 04:36:16 -04:00
|
|
|
const { feed, format, ignoreCache } = options
|
2021-07-06 04:21:35 -04:00
|
|
|
const path = '/feeds/' + feed + '.xml'
|
2018-04-18 10:08:36 -04:00
|
|
|
|
2022-06-27 04:36:16 -04:00
|
|
|
const query: { [id: string]: string } = {}
|
|
|
|
|
|
|
|
if (ignoreCache) query.v = buildUUID()
|
|
|
|
if (format) query.format = format
|
|
|
|
|
2021-07-06 04:21:35 -04:00
|
|
|
return this.getRequestText({
|
|
|
|
...options,
|
2018-04-18 10:08:36 -04:00
|
|
|
|
2021-07-06 04:21:35 -04:00
|
|
|
path,
|
2022-06-27 04:36:16 -04:00
|
|
|
query,
|
2021-07-06 04:21:35 -04:00
|
|
|
accept: 'application/xml',
|
2021-07-08 04:55:16 -04:00
|
|
|
implicitToken: false,
|
2021-07-06 04:21:35 -04:00
|
|
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
getJSON (options: OverrideCommandOptions & {
|
|
|
|
feed: FeedType
|
2022-06-27 04:36:16 -04:00
|
|
|
ignoreCache: boolean
|
2021-07-06 04:21:35 -04:00
|
|
|
query?: { [ id: string ]: any }
|
|
|
|
}) {
|
2022-06-27 04:36:16 -04:00
|
|
|
const { feed, query = {}, ignoreCache } = options
|
2021-07-06 04:21:35 -04:00
|
|
|
const path = '/feeds/' + feed + '.json'
|
2018-04-18 10:08:36 -04:00
|
|
|
|
2022-06-27 04:36:16 -04:00
|
|
|
const cacheQuery = ignoreCache
|
|
|
|
? { v: buildUUID() }
|
|
|
|
: {}
|
|
|
|
|
2021-07-06 04:21:35 -04:00
|
|
|
return this.getRequestText({
|
|
|
|
...options,
|
2018-04-18 10:08:36 -04:00
|
|
|
|
2021-07-06 04:21:35 -04:00
|
|
|
path,
|
2022-06-27 04:36:16 -04:00
|
|
|
query: { ...query, ...cacheQuery },
|
2021-07-06 04:21:35 -04:00
|
|
|
accept: 'application/json',
|
2021-07-08 04:55:16 -04:00
|
|
|
implicitToken: false,
|
2021-07-06 04:21:35 -04:00
|
|
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
|
|
|
})
|
|
|
|
}
|
2018-04-18 10:08:36 -04:00
|
|
|
}
|