From e3d15a6a9aed97a004d9dac1b7a6499d794e080a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 11:17:55 +0200 Subject: Introduce blacklist command --- shared/extra-utils/server/servers.ts | 4 +- shared/extra-utils/videos/blacklist-command.ts | 77 +++++++++++++++++++++++++ shared/extra-utils/videos/index.ts | 2 +- shared/extra-utils/videos/video-blacklist.ts | 79 -------------------------- 4 files changed, 81 insertions(+), 81 deletions(-) create mode 100644 shared/extra-utils/videos/blacklist-command.ts delete mode 100644 shared/extra-utils/videos/video-blacklist.ts (limited to 'shared/extra-utils') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index cb2a8814b..a4432902f 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -18,7 +18,7 @@ import { makeGetRequest } from '../requests/requests' import { SearchCommand } from '../search' import { SocketIOCommand } from '../socket' import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users' -import { LiveCommand, ServicesCommand } from '../videos' +import { LiveCommand, ServicesCommand, BlacklistCommand } from '../videos' import { ConfigCommand } from './config-command' import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' @@ -102,6 +102,7 @@ interface ServerInfo { subscriptionsCommand?: SubscriptionsCommand liveCommand?: LiveCommand servicesCommand?: ServicesCommand + blacklistCommand?: BlacklistCommand } function parallelTests () { @@ -329,6 +330,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.subscriptionsCommand = new SubscriptionsCommand(server) server.liveCommand = new LiveCommand(server) server.servicesCommand = new ServicesCommand(server) + server.blacklistCommand = new BlacklistCommand(server) res(server) }) 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 @@ + +import { ResultList } from '@shared/models' +import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { VideoBlacklist, VideoBlacklistType } from '../../models/videos' +import { AbstractCommand, OverrideCommandOptions } from '../shared' + +export class BlacklistCommand extends AbstractCommand { + + add (options: OverrideCommandOptions & { + videoId: number | string + reason?: string + unfederate?: boolean + }) { + const { videoId, reason, unfederate } = options + const path = '/api/v1/videos/' + videoId + '/blacklist' + + return this.postBodyRequest({ + ...options, + + path, + fields: { reason, unfederate }, + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + update (options: OverrideCommandOptions & { + videoId: number | string + reason?: string + }) { + const { videoId, reason } = options + const path = '/api/v1/videos/' + videoId + '/blacklist' + + return this.putBodyRequest({ + ...options, + + path, + fields: { reason }, + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + remove (options: OverrideCommandOptions & { + videoId: number | string + }) { + const { videoId } = options + const path = '/api/v1/videos/' + videoId + '/blacklist' + + return this.deleteRequest({ + ...options, + + path, + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + list (options: OverrideCommandOptions & { + sort?: string + type?: VideoBlacklistType + } = {}) { + const { sort, type } = options + const path = '/api/v1/videos/blacklist/' + + const query = { sort, type } + + return this.getRequestBody>({ + ...options, + + path, + query, + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } +} 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 @@ +export * from './blacklist-command' export * from './live-command' export * from './live' export * from './services-command' -export * from './video-blacklist' export * from './video-captions' export * from './video-change-ownership' 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 @@ -import * as request from 'supertest' -import { VideoBlacklistType } from '../../models/videos' -import { makeGetRequest } from '..' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' - -function addVideoToBlacklist ( - url: string, - token: string, - videoId: number | string, - reason?: string, - unfederate?: boolean, - specialStatus = HttpStatusCode.NO_CONTENT_204 -) { - const path = '/api/v1/videos/' + videoId + '/blacklist' - - return request(url) - .post(path) - .send({ reason, unfederate }) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + token) - .expect(specialStatus) -} - -function updateVideoBlacklist ( - url: string, - token: string, - videoId: number, - reason?: string, - specialStatus = HttpStatusCode.NO_CONTENT_204 -) { - const path = '/api/v1/videos/' + videoId + '/blacklist' - - return request(url) - .put(path) - .send({ reason }) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + token) - .expect(specialStatus) -} - -function removeVideoFromBlacklist (url: string, token: string, videoId: number | string, specialStatus = HttpStatusCode.NO_CONTENT_204) { - const path = '/api/v1/videos/' + videoId + '/blacklist' - - return request(url) - .delete(path) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + token) - .expect(specialStatus) -} - -function getBlacklistedVideosList (parameters: { - url: string - token: string - sort?: string - type?: VideoBlacklistType - specialStatus?: HttpStatusCode -}) { - const { url, token, sort, type, specialStatus = HttpStatusCode.OK_200 } = parameters - const path = '/api/v1/videos/blacklist/' - - const query = { sort, type } - - return makeGetRequest({ - url, - path, - query, - token, - statusCodeExpected: specialStatus - }) -} - -// --------------------------------------------------------------------------- - -export { - addVideoToBlacklist, - removeVideoFromBlacklist, - getBlacklistedVideosList, - updateVideoBlacklist -} -- cgit v1.2.3