1
0
Fork 0
peertube/shared/extra-utils/feeds/feeds-command.ts

45 lines
1 KiB
TypeScript
Raw Normal View History

2021-07-06 04:21:35 -04:00
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'
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 {
2021-07-06 04:21:35 -04:00
getXML (options: OverrideCommandOptions & {
feed: FeedType
format?: string
}) {
const { feed, format } = options
const path = '/feeds/' + feed + '.xml'
2021-07-06 04:21:35 -04:00
return this.getRequestText({
...options,
2021-07-06 04:21:35 -04:00
path,
query: format ? { format } : undefined,
accept: 'application/xml',
implicitToken: false,
2021-07-06 04:21:35 -04:00
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
getJSON (options: OverrideCommandOptions & {
feed: FeedType
query?: { [ id: string ]: any }
}) {
const { feed, query } = options
const path = '/feeds/' + feed + '.json'
2021-07-06 04:21:35 -04:00
return this.getRequestText({
...options,
2021-07-06 04:21:35 -04:00
path,
query,
accept: 'application/json',
implicitToken: false,
2021-07-06 04:21:35 -04:00
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
}