diff options
Diffstat (limited to 'shared/extra-utils/feeds')
-rw-r--r-- | shared/extra-utils/feeds/feeds-command.ts | 44 | ||||
-rw-r--r-- | shared/extra-utils/feeds/feeds.ts | 33 | ||||
-rw-r--r-- | shared/extra-utils/feeds/index.ts | 1 |
3 files changed, 45 insertions, 33 deletions
diff --git a/shared/extra-utils/feeds/feeds-command.ts b/shared/extra-utils/feeds/feeds-command.ts new file mode 100644 index 000000000..3c95f9536 --- /dev/null +++ b/shared/extra-utils/feeds/feeds-command.ts | |||
@@ -0,0 +1,44 @@ | |||
1 | |||
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 | format?: string | ||
12 | }) { | ||
13 | const { feed, format } = options | ||
14 | const path = '/feeds/' + feed + '.xml' | ||
15 | |||
16 | return this.getRequestText({ | ||
17 | ...options, | ||
18 | |||
19 | path, | ||
20 | query: format ? { format } : undefined, | ||
21 | accept: 'application/xml', | ||
22 | implicitToken: false, | ||
23 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
24 | }) | ||
25 | } | ||
26 | |||
27 | getJSON (options: OverrideCommandOptions & { | ||
28 | feed: FeedType | ||
29 | query?: { [ id: string ]: any } | ||
30 | }) { | ||
31 | const { feed, query } = options | ||
32 | const path = '/feeds/' + feed + '.json' | ||
33 | |||
34 | return this.getRequestText({ | ||
35 | ...options, | ||
36 | |||
37 | path, | ||
38 | query, | ||
39 | accept: 'application/json', | ||
40 | implicitToken: false, | ||
41 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
42 | }) | ||
43 | } | ||
44 | } | ||
diff --git a/shared/extra-utils/feeds/feeds.ts b/shared/extra-utils/feeds/feeds.ts deleted file mode 100644 index ce0a98c6d..000000000 --- a/shared/extra-utils/feeds/feeds.ts +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | import * as request from 'supertest' | ||
2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
3 | |||
4 | type FeedType = 'videos' | 'video-comments' | 'subscriptions' | ||
5 | |||
6 | function getXMLfeed (url: string, feed: FeedType, format?: string) { | ||
7 | const path = '/feeds/' + feed + '.xml' | ||
8 | |||
9 | return request(url) | ||
10 | .get(path) | ||
11 | .query((format) ? { format: format } : {}) | ||
12 | .set('Accept', 'application/xml') | ||
13 | .expect(HttpStatusCode.OK_200) | ||
14 | .expect('Content-Type', /xml/) | ||
15 | } | ||
16 | |||
17 | function getJSONfeed (url: string, feed: FeedType, query: any = {}, statusCodeExpected = HttpStatusCode.OK_200) { | ||
18 | const path = '/feeds/' + feed + '.json' | ||
19 | |||
20 | return request(url) | ||
21 | .get(path) | ||
22 | .query(query) | ||
23 | .set('Accept', 'application/json') | ||
24 | .expect(statusCodeExpected) | ||
25 | .expect('Content-Type', /json/) | ||
26 | } | ||
27 | |||
28 | // --------------------------------------------------------------------------- | ||
29 | |||
30 | export { | ||
31 | getXMLfeed, | ||
32 | getJSONfeed | ||
33 | } | ||
diff --git a/shared/extra-utils/feeds/index.ts b/shared/extra-utils/feeds/index.ts new file mode 100644 index 000000000..662a22b6f --- /dev/null +++ b/shared/extra-utils/feeds/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './feeds-command' | |||