]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/server-commands/feeds/feeds-command.ts
Fix broken feeds with published live
[github/Chocobozzz/PeerTube.git] / shared / server-commands / feeds / feeds-command.ts
1 import { buildUUID } from '@shared/extra-utils'
2 import { HttpStatusCode } from '@shared/models'
3 import { AbstractCommand, OverrideCommandOptions } from '../shared'
4
5 type FeedType = 'videos' | 'video-comments' | 'subscriptions'
6
7 export class FeedCommand extends AbstractCommand {
8
9 getXML (options: OverrideCommandOptions & {
10 feed: FeedType
11 ignoreCache: boolean
12 format?: string
13 }) {
14 const { feed, format, ignoreCache } = options
15 const path = '/feeds/' + feed + '.xml'
16
17 const query: { [id: string]: string } = {}
18
19 if (ignoreCache) query.v = buildUUID()
20 if (format) query.format = format
21
22 return this.getRequestText({
23 ...options,
24
25 path,
26 query,
27 accept: 'application/xml',
28 implicitToken: false,
29 defaultExpectedStatus: HttpStatusCode.OK_200
30 })
31 }
32
33 getJSON (options: OverrideCommandOptions & {
34 feed: FeedType
35 ignoreCache: boolean
36 query?: { [ id: string ]: any }
37 }) {
38 const { feed, query = {}, ignoreCache } = options
39 const path = '/feeds/' + feed + '.json'
40
41 const cacheQuery = ignoreCache
42 ? { v: buildUUID() }
43 : {}
44
45 return this.getRequestText({
46 ...options,
47
48 path,
49 query: { ...query, ...cacheQuery },
50 accept: 'application/json',
51 implicitToken: false,
52 defaultExpectedStatus: HttpStatusCode.OK_200
53 })
54 }
55 }