diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-06 10:21:35 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:16 +0200 |
commit | c1bc8ee4783d6ce3102524e6c2a02b2f0f6aab6d (patch) | |
tree | 6f173749e46a79e6eca0bfd1f742054fa7276e7e /shared/extra-utils/feeds | |
parent | e8bd7ce7ccafe3e064b03978e9b512c1a4cc99e6 (diff) | |
download | PeerTube-c1bc8ee4783d6ce3102524e6c2a02b2f0f6aab6d.tar.gz PeerTube-c1bc8ee4783d6ce3102524e6c2a02b2f0f6aab6d.tar.zst PeerTube-c1bc8ee4783d6ce3102524e6c2a02b2f0f6aab6d.zip |
Introduce feed command
Diffstat (limited to 'shared/extra-utils/feeds')
-rw-r--r-- | shared/extra-utils/feeds/feeds.ts | 55 | ||||
-rw-r--r-- | shared/extra-utils/feeds/index.ts | 1 |
2 files changed, 33 insertions, 23 deletions
diff --git a/shared/extra-utils/feeds/feeds.ts b/shared/extra-utils/feeds/feeds.ts index ce0a98c6d..012ce6cfe 100644 --- a/shared/extra-utils/feeds/feeds.ts +++ b/shared/extra-utils/feeds/feeds.ts | |||
@@ -1,33 +1,42 @@ | |||
1 | import * as request from 'supertest' | 1 | |
2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
3 | 4 | ||
4 | type FeedType = 'videos' | 'video-comments' | 'subscriptions' | 5 | type FeedType = 'videos' | 'video-comments' | 'subscriptions' |
5 | 6 | ||
6 | function getXMLfeed (url: string, feed: FeedType, format?: string) { | 7 | export class FeedCommand extends AbstractCommand { |
7 | const path = '/feeds/' + feed + '.xml' | ||
8 | 8 | ||
9 | return request(url) | 9 | getXML (options: OverrideCommandOptions & { |
10 | .get(path) | 10 | feed: FeedType |
11 | .query((format) ? { format: format } : {}) | 11 | format?: string |
12 | .set('Accept', 'application/xml') | 12 | }) { |
13 | .expect(HttpStatusCode.OK_200) | 13 | const { feed, format } = options |
14 | .expect('Content-Type', /xml/) | 14 | const path = '/feeds/' + feed + '.xml' |
15 | } | ||
16 | 15 | ||
17 | function getJSONfeed (url: string, feed: FeedType, query: any = {}, statusCodeExpected = HttpStatusCode.OK_200) { | 16 | return this.getRequestText({ |
18 | const path = '/feeds/' + feed + '.json' | 17 | ...options, |
19 | 18 | ||
20 | return request(url) | 19 | path, |
21 | .get(path) | 20 | query: format ? { format } : undefined, |
22 | .query(query) | 21 | accept: 'application/xml', |
23 | .set('Accept', 'application/json') | 22 | defaultExpectedStatus: HttpStatusCode.OK_200 |
24 | .expect(statusCodeExpected) | 23 | }) |
25 | .expect('Content-Type', /json/) | 24 | } |
26 | } | 25 | |
26 | getJSON (options: OverrideCommandOptions & { | ||
27 | feed: FeedType | ||
28 | query?: { [ id: string ]: any } | ||
29 | }) { | ||
30 | const { feed, query } = options | ||
31 | const path = '/feeds/' + feed + '.json' | ||
27 | 32 | ||
28 | // --------------------------------------------------------------------------- | 33 | return this.getRequestText({ |
34 | ...options, | ||
29 | 35 | ||
30 | export { | 36 | path, |
31 | getXMLfeed, | 37 | query, |
32 | getJSONfeed | 38 | accept: 'application/json', |
39 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
40 | }) | ||
41 | } | ||
33 | } | 42 | } |
diff --git a/shared/extra-utils/feeds/index.ts b/shared/extra-utils/feeds/index.ts new file mode 100644 index 000000000..4634cb163 --- /dev/null +++ b/shared/extra-utils/feeds/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './feeds' | |||