]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/server-commands/feeds/feeds-command.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / shared / server-commands / feeds / feeds-command.ts
CommitLineData
41e74ec9 1import { buildUUID } from '@shared/extra-utils'
c0e8b12e 2import { HttpStatusCode } from '@shared/models'
c1bc8ee4 3import { AbstractCommand, OverrideCommandOptions } from '../shared'
966eb053 4
5beb89f2 5type FeedType = 'videos' | 'video-comments' | 'subscriptions'
fe3a55b0 6
c1bc8ee4 7export class FeedCommand extends AbstractCommand {
966eb053 8
c1bc8ee4
C
9 getXML (options: OverrideCommandOptions & {
10 feed: FeedType
41e74ec9 11 ignoreCache: boolean
c1bc8ee4
C
12 format?: string
13 }) {
41e74ec9 14 const { feed, format, ignoreCache } = options
c1bc8ee4 15 const path = '/feeds/' + feed + '.xml'
966eb053 16
41e74ec9
C
17 const query: { [id: string]: string } = {}
18
19 if (ignoreCache) query.v = buildUUID()
20 if (format) query.format = format
21
c1bc8ee4
C
22 return this.getRequestText({
23 ...options,
966eb053 24
c1bc8ee4 25 path,
41e74ec9 26 query,
c1bc8ee4 27 accept: 'application/xml',
a1637fa1 28 implicitToken: false,
c1bc8ee4
C
29 defaultExpectedStatus: HttpStatusCode.OK_200
30 })
31 }
32
cb0eda56
AG
33 getPodcastXML (options: OverrideCommandOptions & {
34 ignoreCache: boolean
35 channelId: number
36 }) {
37 const { ignoreCache, channelId } = options
38 const path = `/feeds/podcast/videos.xml`
39
40 const query: { [id: string]: string } = {}
41
42 if (ignoreCache) query.v = buildUUID()
43 if (channelId) query.videoChannelId = channelId + ''
44
45 return this.getRequestText({
46 ...options,
47
48 path,
49 query,
50 accept: 'application/xml',
51 implicitToken: false,
52 defaultExpectedStatus: HttpStatusCode.OK_200
53 })
54 }
55
c1bc8ee4
C
56 getJSON (options: OverrideCommandOptions & {
57 feed: FeedType
41e74ec9 58 ignoreCache: boolean
c1bc8ee4
C
59 query?: { [ id: string ]: any }
60 }) {
41e74ec9 61 const { feed, query = {}, ignoreCache } = options
c1bc8ee4 62 const path = '/feeds/' + feed + '.json'
966eb053 63
41e74ec9
C
64 const cacheQuery = ignoreCache
65 ? { v: buildUUID() }
66 : {}
67
c1bc8ee4
C
68 return this.getRequestText({
69 ...options,
966eb053 70
c1bc8ee4 71 path,
41e74ec9 72 query: { ...query, ...cacheQuery },
c1bc8ee4 73 accept: 'application/json',
a1637fa1 74 implicitToken: false,
c1bc8ee4
C
75 defaultExpectedStatus: HttpStatusCode.OK_200
76 })
77 }
966eb053 78}