diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-06 14:30:20 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:17 +0200 |
commit | 23a3a8827cb8b862f5cc7ee2819f39918303beca (patch) | |
tree | 93a3bdbd02787d32094d6d50aa209f2c079038a5 /shared | |
parent | 480d6ea6791fe4100f1905af1e1e3a08173594ea (diff) | |
download | PeerTube-23a3a8827cb8b862f5cc7ee2819f39918303beca.tar.gz PeerTube-23a3a8827cb8b862f5cc7ee2819f39918303beca.tar.zst PeerTube-23a3a8827cb8b862f5cc7ee2819f39918303beca.zip |
Introduce overviews command
Diffstat (limited to 'shared')
-rw-r--r-- | shared/extra-utils/index.ts | 1 | ||||
-rw-r--r-- | shared/extra-utils/overviews/index.ts | 1 | ||||
-rw-r--r-- | shared/extra-utils/overviews/overviews-command.ts | 25 | ||||
-rw-r--r-- | shared/extra-utils/overviews/overviews.ts | 34 | ||||
-rw-r--r-- | shared/extra-utils/server/servers.ts | 3 | ||||
-rw-r--r-- | shared/extra-utils/shared/abstract-command.ts | 5 |
6 files changed, 34 insertions, 35 deletions
diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index 7ca079c78..38c8c4c1c 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts | |||
@@ -6,6 +6,7 @@ export * from './logs' | |||
6 | export * from './miscs' | 6 | export * from './miscs' |
7 | export * from './mock-servers' | 7 | export * from './mock-servers' |
8 | export * from './moderation' | 8 | export * from './moderation' |
9 | export * from './overviews' | ||
9 | 10 | ||
10 | export * from './requests/check-api-params' | 11 | export * from './requests/check-api-params' |
11 | export * from './requests/requests' | 12 | export * from './requests/requests' |
diff --git a/shared/extra-utils/overviews/index.ts b/shared/extra-utils/overviews/index.ts new file mode 100644 index 000000000..e19551907 --- /dev/null +++ b/shared/extra-utils/overviews/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './overviews-command' | |||
diff --git a/shared/extra-utils/overviews/overviews-command.ts b/shared/extra-utils/overviews/overviews-command.ts new file mode 100644 index 000000000..0ac3cbd33 --- /dev/null +++ b/shared/extra-utils/overviews/overviews-command.ts | |||
@@ -0,0 +1,25 @@ | |||
1 | import { HttpStatusCode } from '@shared/core-utils' | ||
2 | import { VideosOverview } from '@shared/models' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | export class OverviewsCommand extends AbstractCommand { | ||
6 | |||
7 | getVideos (options: OverrideCommandOptions & { | ||
8 | page: number | ||
9 | token?: string | ||
10 | }) { | ||
11 | const { token, page } = options | ||
12 | const path = '/api/v1/overviews/videos' | ||
13 | |||
14 | const query = { page } | ||
15 | |||
16 | return this.getRequestBody<VideosOverview>({ | ||
17 | ...options, | ||
18 | |||
19 | token: token || null, | ||
20 | path, | ||
21 | query, | ||
22 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
23 | }) | ||
24 | } | ||
25 | } | ||
diff --git a/shared/extra-utils/overviews/overviews.ts b/shared/extra-utils/overviews/overviews.ts deleted file mode 100644 index 5e1a13e5e..000000000 --- a/shared/extra-utils/overviews/overviews.ts +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | import { makeGetRequest } from '../requests/requests' | ||
2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
3 | |||
4 | function getVideosOverview (url: string, page: number, statusCodeExpected = HttpStatusCode.OK_200) { | ||
5 | const path = '/api/v1/overviews/videos' | ||
6 | |||
7 | const query = { page } | ||
8 | |||
9 | return makeGetRequest({ | ||
10 | url, | ||
11 | path, | ||
12 | query, | ||
13 | statusCodeExpected | ||
14 | }) | ||
15 | } | ||
16 | |||
17 | function getVideosOverviewWithToken (url: string, page: number, token: string, statusCodeExpected = HttpStatusCode.OK_200) { | ||
18 | const path = '/api/v1/overviews/videos' | ||
19 | |||
20 | const query = { page } | ||
21 | |||
22 | return makeGetRequest({ | ||
23 | url, | ||
24 | path, | ||
25 | query, | ||
26 | token, | ||
27 | statusCodeExpected | ||
28 | }) | ||
29 | } | ||
30 | |||
31 | export { | ||
32 | getVideosOverview, | ||
33 | getVideosOverviewWithToken | ||
34 | } | ||
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index f05f0dbbe..70be96cf6 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts | |||
@@ -13,6 +13,7 @@ import { FeedCommand } from '../feeds' | |||
13 | import { LogsCommand } from '../logs' | 13 | import { LogsCommand } from '../logs' |
14 | import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs' | 14 | import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs' |
15 | import { AbusesCommand } from '../moderation' | 15 | import { AbusesCommand } from '../moderation' |
16 | import { OverviewsCommand } from '../overviews' | ||
16 | import { makeGetRequest } from '../requests/requests' | 17 | import { makeGetRequest } from '../requests/requests' |
17 | 18 | ||
18 | interface ServerInfo { | 19 | interface ServerInfo { |
@@ -73,6 +74,7 @@ interface ServerInfo { | |||
73 | feedCommand?: FeedCommand | 74 | feedCommand?: FeedCommand |
74 | logsCommand?: LogsCommand | 75 | logsCommand?: LogsCommand |
75 | abusesCommand?: AbusesCommand | 76 | abusesCommand?: AbusesCommand |
77 | overviewsCommand?: OverviewsCommand | ||
76 | } | 78 | } |
77 | 79 | ||
78 | function parallelTests () { | 80 | function parallelTests () { |
@@ -284,6 +286,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] | |||
284 | server.feedCommand = new FeedCommand(server) | 286 | server.feedCommand = new FeedCommand(server) |
285 | server.logsCommand = new LogsCommand(server) | 287 | server.logsCommand = new LogsCommand(server) |
286 | server.abusesCommand = new AbusesCommand(server) | 288 | server.abusesCommand = new AbusesCommand(server) |
289 | server.overviewsCommand = new OverviewsCommand(server) | ||
287 | 290 | ||
288 | res(server) | 291 | res(server) |
289 | }) | 292 | }) |
diff --git a/shared/extra-utils/shared/abstract-command.ts b/shared/extra-utils/shared/abstract-command.ts index 3ee5cd865..3815fab0e 100644 --- a/shared/extra-utils/shared/abstract-command.ts +++ b/shared/extra-utils/shared/abstract-command.ts | |||
@@ -78,7 +78,10 @@ abstract class AbstractCommand { | |||
78 | return { | 78 | return { |
79 | url: this.server.url, | 79 | url: this.server.url, |
80 | path, | 80 | path, |
81 | token: token ?? this.server.accessToken, | 81 | |
82 | // Token can be null if we don't want to add it | ||
83 | token: token !== undefined ? token : this.server.accessToken, | ||
84 | |||
82 | statusCodeExpected: expectedStatus ?? this.expectedStatus ?? defaultExpectedStatus | 85 | statusCodeExpected: expectedStatus ?? this.expectedStatus ?? defaultExpectedStatus |
83 | } | 86 | } |
84 | } | 87 | } |