diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-08 11:17:55 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:17 +0200 |
commit | e3d15a6a9aed97a004d9dac1b7a6499d794e080a (patch) | |
tree | 7637ac85a8659a66a1290c9533e0206e9a0c5a30 /shared/extra-utils/videos | |
parent | a1637fa1e25b60a88f7cfe50aac8953f50d55761 (diff) | |
download | PeerTube-e3d15a6a9aed97a004d9dac1b7a6499d794e080a.tar.gz PeerTube-e3d15a6a9aed97a004d9dac1b7a6499d794e080a.tar.zst PeerTube-e3d15a6a9aed97a004d9dac1b7a6499d794e080a.zip |
Introduce blacklist command
Diffstat (limited to 'shared/extra-utils/videos')
-rw-r--r-- | shared/extra-utils/videos/blacklist-command.ts | 77 | ||||
-rw-r--r-- | shared/extra-utils/videos/index.ts | 2 | ||||
-rw-r--r-- | shared/extra-utils/videos/video-blacklist.ts | 79 |
3 files changed, 78 insertions, 80 deletions
diff --git a/shared/extra-utils/videos/blacklist-command.ts b/shared/extra-utils/videos/blacklist-command.ts new file mode 100644 index 000000000..fdae6b469 --- /dev/null +++ b/shared/extra-utils/videos/blacklist-command.ts | |||
@@ -0,0 +1,77 @@ | |||
1 | |||
2 | import { ResultList } from '@shared/models' | ||
3 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
4 | import { VideoBlacklist, VideoBlacklistType } from '../../models/videos' | ||
5 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
6 | |||
7 | export class BlacklistCommand extends AbstractCommand { | ||
8 | |||
9 | add (options: OverrideCommandOptions & { | ||
10 | videoId: number | string | ||
11 | reason?: string | ||
12 | unfederate?: boolean | ||
13 | }) { | ||
14 | const { videoId, reason, unfederate } = options | ||
15 | const path = '/api/v1/videos/' + videoId + '/blacklist' | ||
16 | |||
17 | return this.postBodyRequest({ | ||
18 | ...options, | ||
19 | |||
20 | path, | ||
21 | fields: { reason, unfederate }, | ||
22 | implicitToken: true, | ||
23 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
24 | }) | ||
25 | } | ||
26 | |||
27 | update (options: OverrideCommandOptions & { | ||
28 | videoId: number | string | ||
29 | reason?: string | ||
30 | }) { | ||
31 | const { videoId, reason } = options | ||
32 | const path = '/api/v1/videos/' + videoId + '/blacklist' | ||
33 | |||
34 | return this.putBodyRequest({ | ||
35 | ...options, | ||
36 | |||
37 | path, | ||
38 | fields: { reason }, | ||
39 | implicitToken: true, | ||
40 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
41 | }) | ||
42 | } | ||
43 | |||
44 | remove (options: OverrideCommandOptions & { | ||
45 | videoId: number | string | ||
46 | }) { | ||
47 | const { videoId } = options | ||
48 | const path = '/api/v1/videos/' + videoId + '/blacklist' | ||
49 | |||
50 | return this.deleteRequest({ | ||
51 | ...options, | ||
52 | |||
53 | path, | ||
54 | implicitToken: true, | ||
55 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
56 | }) | ||
57 | } | ||
58 | |||
59 | list (options: OverrideCommandOptions & { | ||
60 | sort?: string | ||
61 | type?: VideoBlacklistType | ||
62 | } = {}) { | ||
63 | const { sort, type } = options | ||
64 | const path = '/api/v1/videos/blacklist/' | ||
65 | |||
66 | const query = { sort, type } | ||
67 | |||
68 | return this.getRequestBody<ResultList<VideoBlacklist>>({ | ||
69 | ...options, | ||
70 | |||
71 | path, | ||
72 | query, | ||
73 | implicitToken: true, | ||
74 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
75 | }) | ||
76 | } | ||
77 | } | ||
diff --git a/shared/extra-utils/videos/index.ts b/shared/extra-utils/videos/index.ts index fe5dc6655..67f5faf54 100644 --- a/shared/extra-utils/videos/index.ts +++ b/shared/extra-utils/videos/index.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | export * from './blacklist-command' | ||
1 | export * from './live-command' | 2 | export * from './live-command' |
2 | export * from './live' | 3 | export * from './live' |
3 | export * from './services-command' | 4 | export * from './services-command' |
4 | export * from './video-blacklist' | ||
5 | export * from './video-captions' | 5 | export * from './video-captions' |
6 | export * from './video-change-ownership' | 6 | export * from './video-change-ownership' |
7 | export * from './video-channels' | 7 | export * from './video-channels' |
diff --git a/shared/extra-utils/videos/video-blacklist.ts b/shared/extra-utils/videos/video-blacklist.ts deleted file mode 100644 index aa1548537..000000000 --- a/shared/extra-utils/videos/video-blacklist.ts +++ /dev/null | |||
@@ -1,79 +0,0 @@ | |||
1 | import * as request from 'supertest' | ||
2 | import { VideoBlacklistType } from '../../models/videos' | ||
3 | import { makeGetRequest } from '..' | ||
4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
5 | |||
6 | function addVideoToBlacklist ( | ||
7 | url: string, | ||
8 | token: string, | ||
9 | videoId: number | string, | ||
10 | reason?: string, | ||
11 | unfederate?: boolean, | ||
12 | specialStatus = HttpStatusCode.NO_CONTENT_204 | ||
13 | ) { | ||
14 | const path = '/api/v1/videos/' + videoId + '/blacklist' | ||
15 | |||
16 | return request(url) | ||
17 | .post(path) | ||
18 | .send({ reason, unfederate }) | ||
19 | .set('Accept', 'application/json') | ||
20 | .set('Authorization', 'Bearer ' + token) | ||
21 | .expect(specialStatus) | ||
22 | } | ||
23 | |||
24 | function updateVideoBlacklist ( | ||
25 | url: string, | ||
26 | token: string, | ||
27 | videoId: number, | ||
28 | reason?: string, | ||
29 | specialStatus = HttpStatusCode.NO_CONTENT_204 | ||
30 | ) { | ||
31 | const path = '/api/v1/videos/' + videoId + '/blacklist' | ||
32 | |||
33 | return request(url) | ||
34 | .put(path) | ||
35 | .send({ reason }) | ||
36 | .set('Accept', 'application/json') | ||
37 | .set('Authorization', 'Bearer ' + token) | ||
38 | .expect(specialStatus) | ||
39 | } | ||
40 | |||
41 | function removeVideoFromBlacklist (url: string, token: string, videoId: number | string, specialStatus = HttpStatusCode.NO_CONTENT_204) { | ||
42 | const path = '/api/v1/videos/' + videoId + '/blacklist' | ||
43 | |||
44 | return request(url) | ||
45 | .delete(path) | ||
46 | .set('Accept', 'application/json') | ||
47 | .set('Authorization', 'Bearer ' + token) | ||
48 | .expect(specialStatus) | ||
49 | } | ||
50 | |||
51 | function getBlacklistedVideosList (parameters: { | ||
52 | url: string | ||
53 | token: string | ||
54 | sort?: string | ||
55 | type?: VideoBlacklistType | ||
56 | specialStatus?: HttpStatusCode | ||
57 | }) { | ||
58 | const { url, token, sort, type, specialStatus = HttpStatusCode.OK_200 } = parameters | ||
59 | const path = '/api/v1/videos/blacklist/' | ||
60 | |||
61 | const query = { sort, type } | ||
62 | |||
63 | return makeGetRequest({ | ||
64 | url, | ||
65 | path, | ||
66 | query, | ||
67 | token, | ||
68 | statusCodeExpected: specialStatus | ||
69 | }) | ||
70 | } | ||
71 | |||
72 | // --------------------------------------------------------------------------- | ||
73 | |||
74 | export { | ||
75 | addVideoToBlacklist, | ||
76 | removeVideoFromBlacklist, | ||
77 | getBlacklistedVideosList, | ||
78 | updateVideoBlacklist | ||
79 | } | ||