diff options
Diffstat (limited to 'shared/extra-utils')
-rw-r--r-- | shared/extra-utils/server/servers.ts | 4 | ||||
-rw-r--r-- | shared/extra-utils/videos/change-ownership-command.ts | 69 | ||||
-rw-r--r-- | shared/extra-utils/videos/index.ts | 2 | ||||
-rw-r--r-- | shared/extra-utils/videos/video-change-ownership.ts | 72 |
4 files changed, 73 insertions, 74 deletions
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 170360341..33f558414 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts | |||
@@ -18,7 +18,7 @@ import { makeGetRequest } from '../requests/requests' | |||
18 | import { SearchCommand } from '../search' | 18 | import { SearchCommand } from '../search' |
19 | import { SocketIOCommand } from '../socket' | 19 | import { SocketIOCommand } from '../socket' |
20 | import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users' | 20 | import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users' |
21 | import { LiveCommand, ServicesCommand, BlacklistCommand, CaptionsCommand } from '../videos' | 21 | import { BlacklistCommand, CaptionsCommand, ChangeOwnershipCommand, LiveCommand, ServicesCommand } from '../videos' |
22 | import { ConfigCommand } from './config-command' | 22 | import { ConfigCommand } from './config-command' |
23 | import { ContactFormCommand } from './contact-form-command' | 23 | import { ContactFormCommand } from './contact-form-command' |
24 | import { DebugCommand } from './debug-command' | 24 | import { DebugCommand } from './debug-command' |
@@ -104,6 +104,7 @@ interface ServerInfo { | |||
104 | servicesCommand?: ServicesCommand | 104 | servicesCommand?: ServicesCommand |
105 | blacklistCommand?: BlacklistCommand | 105 | blacklistCommand?: BlacklistCommand |
106 | captionsCommand?: CaptionsCommand | 106 | captionsCommand?: CaptionsCommand |
107 | changeOwnershipCommand?: ChangeOwnershipCommand | ||
107 | } | 108 | } |
108 | 109 | ||
109 | function parallelTests () { | 110 | function parallelTests () { |
@@ -333,6 +334,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] | |||
333 | server.servicesCommand = new ServicesCommand(server) | 334 | server.servicesCommand = new ServicesCommand(server) |
334 | server.blacklistCommand = new BlacklistCommand(server) | 335 | server.blacklistCommand = new BlacklistCommand(server) |
335 | server.captionsCommand = new CaptionsCommand(server) | 336 | server.captionsCommand = new CaptionsCommand(server) |
337 | server.changeOwnershipCommand = new ChangeOwnershipCommand(server) | ||
336 | 338 | ||
337 | res(server) | 339 | res(server) |
338 | }) | 340 | }) |
diff --git a/shared/extra-utils/videos/change-ownership-command.ts b/shared/extra-utils/videos/change-ownership-command.ts new file mode 100644 index 000000000..03f77a95f --- /dev/null +++ b/shared/extra-utils/videos/change-ownership-command.ts | |||
@@ -0,0 +1,69 @@ | |||
1 | |||
2 | import { ResultList, VideoChangeOwnership } from '@shared/models' | ||
3 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
5 | |||
6 | export class ChangeOwnershipCommand extends AbstractCommand { | ||
7 | |||
8 | create (options: OverrideCommandOptions & { | ||
9 | videoId: number | string | ||
10 | username: string | ||
11 | }) { | ||
12 | const { videoId, username } = options | ||
13 | const path = '/api/v1/videos/' + videoId + '/give-ownership' | ||
14 | |||
15 | return this.postBodyRequest({ | ||
16 | ...options, | ||
17 | |||
18 | path, | ||
19 | fields: { username }, | ||
20 | implicitToken: true, | ||
21 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
22 | }) | ||
23 | } | ||
24 | |||
25 | list (options: OverrideCommandOptions = {}) { | ||
26 | const path = '/api/v1/videos/ownership' | ||
27 | |||
28 | return this.getRequestBody<ResultList<VideoChangeOwnership>>({ | ||
29 | ...options, | ||
30 | |||
31 | path, | ||
32 | query: { sort: '-createdAt' }, | ||
33 | implicitToken: true, | ||
34 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
35 | }) | ||
36 | } | ||
37 | |||
38 | accept (options: OverrideCommandOptions & { | ||
39 | ownershipId: number | ||
40 | channelId: number | ||
41 | }) { | ||
42 | const { ownershipId, channelId } = options | ||
43 | const path = '/api/v1/videos/ownership/' + ownershipId + '/accept' | ||
44 | |||
45 | return this.postBodyRequest({ | ||
46 | ...options, | ||
47 | |||
48 | path, | ||
49 | fields: { channelId }, | ||
50 | implicitToken: true, | ||
51 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
52 | }) | ||
53 | } | ||
54 | |||
55 | refuse (options: OverrideCommandOptions & { | ||
56 | ownershipId: number | ||
57 | }) { | ||
58 | const { ownershipId } = options | ||
59 | const path = '/api/v1/videos/ownership/' + ownershipId + '/refuse' | ||
60 | |||
61 | return this.postBodyRequest({ | ||
62 | ...options, | ||
63 | |||
64 | path, | ||
65 | implicitToken: true, | ||
66 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
67 | }) | ||
68 | } | ||
69 | } | ||
diff --git a/shared/extra-utils/videos/index.ts b/shared/extra-utils/videos/index.ts index 03b4756d5..815c7f944 100644 --- a/shared/extra-utils/videos/index.ts +++ b/shared/extra-utils/videos/index.ts | |||
@@ -1,10 +1,10 @@ | |||
1 | export * from './blacklist-command' | 1 | export * from './blacklist-command' |
2 | export * from './captions' | 2 | export * from './captions' |
3 | export * from './captions-command' | 3 | export * from './captions-command' |
4 | export * from './change-ownership-command' | ||
4 | export * from './live-command' | 5 | export * from './live-command' |
5 | export * from './live' | 6 | export * from './live' |
6 | export * from './services-command' | 7 | export * from './services-command' |
7 | export * from './video-change-ownership' | ||
8 | export * from './video-channels' | 8 | export * from './video-channels' |
9 | export * from './video-comments' | 9 | export * from './video-comments' |
10 | export * from './video-history' | 10 | export * from './video-history' |
diff --git a/shared/extra-utils/videos/video-change-ownership.ts b/shared/extra-utils/videos/video-change-ownership.ts deleted file mode 100644 index ef82a7636..000000000 --- a/shared/extra-utils/videos/video-change-ownership.ts +++ /dev/null | |||
@@ -1,72 +0,0 @@ | |||
1 | import * as request from 'supertest' | ||
2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
3 | |||
4 | function changeVideoOwnership ( | ||
5 | url: string, | ||
6 | token: string, | ||
7 | videoId: number | string, | ||
8 | username, | ||
9 | expectedStatus = HttpStatusCode.NO_CONTENT_204 | ||
10 | ) { | ||
11 | const path = '/api/v1/videos/' + videoId + '/give-ownership' | ||
12 | |||
13 | return request(url) | ||
14 | .post(path) | ||
15 | .set('Accept', 'application/json') | ||
16 | .set('Authorization', 'Bearer ' + token) | ||
17 | .send({ username }) | ||
18 | .expect(expectedStatus) | ||
19 | } | ||
20 | |||
21 | function getVideoChangeOwnershipList (url: string, token: string) { | ||
22 | const path = '/api/v1/videos/ownership' | ||
23 | |||
24 | return request(url) | ||
25 | .get(path) | ||
26 | .query({ sort: '-createdAt' }) | ||
27 | .set('Accept', 'application/json') | ||
28 | .set('Authorization', 'Bearer ' + token) | ||
29 | .expect(HttpStatusCode.OK_200) | ||
30 | .expect('Content-Type', /json/) | ||
31 | } | ||
32 | |||
33 | function acceptChangeOwnership ( | ||
34 | url: string, | ||
35 | token: string, | ||
36 | ownershipId: string, | ||
37 | channelId: number, | ||
38 | expectedStatus = HttpStatusCode.NO_CONTENT_204 | ||
39 | ) { | ||
40 | const path = '/api/v1/videos/ownership/' + ownershipId + '/accept' | ||
41 | |||
42 | return request(url) | ||
43 | .post(path) | ||
44 | .set('Accept', 'application/json') | ||
45 | .set('Authorization', 'Bearer ' + token) | ||
46 | .send({ channelId }) | ||
47 | .expect(expectedStatus) | ||
48 | } | ||
49 | |||
50 | function refuseChangeOwnership ( | ||
51 | url: string, | ||
52 | token: string, | ||
53 | ownershipId: string, | ||
54 | expectedStatus = HttpStatusCode.NO_CONTENT_204 | ||
55 | ) { | ||
56 | const path = '/api/v1/videos/ownership/' + ownershipId + '/refuse' | ||
57 | |||
58 | return request(url) | ||
59 | .post(path) | ||
60 | .set('Accept', 'application/json') | ||
61 | .set('Authorization', 'Bearer ' + token) | ||
62 | .expect(expectedStatus) | ||
63 | } | ||
64 | |||
65 | // --------------------------------------------------------------------------- | ||
66 | |||
67 | export { | ||
68 | changeVideoOwnership, | ||
69 | getVideoChangeOwnershipList, | ||
70 | acceptChangeOwnership, | ||
71 | refuseChangeOwnership | ||
72 | } | ||