From f59545d97a80bf06025bf6343a80d834c7eb237f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 10:22:37 +0200 Subject: Rename command files --- shared/extra-utils/bulk/bulk-command.ts | 20 +++++++++++ shared/extra-utils/bulk/bulk.ts | 20 ----------- shared/extra-utils/bulk/index.ts | 2 +- shared/extra-utils/cli/cli-command.ts | 23 ++++++++++++ shared/extra-utils/cli/cli.ts | 23 ------------ shared/extra-utils/cli/index.ts | 2 +- .../custom-pages/custom-pages-command.ts | 30 ++++++++++++++++ shared/extra-utils/custom-pages/custom-pages.ts | 30 ---------------- shared/extra-utils/custom-pages/index.ts | 2 +- shared/extra-utils/feeds/feeds-command.ts | 42 ++++++++++++++++++++++ shared/extra-utils/feeds/feeds.ts | 42 ---------------------- shared/extra-utils/feeds/index.ts | 2 +- shared/extra-utils/index.ts | 2 +- shared/extra-utils/shared/abstract-command.ts | 2 +- 14 files changed, 121 insertions(+), 121 deletions(-) create mode 100644 shared/extra-utils/bulk/bulk-command.ts delete mode 100644 shared/extra-utils/bulk/bulk.ts create mode 100644 shared/extra-utils/cli/cli-command.ts delete mode 100644 shared/extra-utils/cli/cli.ts create mode 100644 shared/extra-utils/custom-pages/custom-pages-command.ts delete mode 100644 shared/extra-utils/custom-pages/custom-pages.ts create mode 100644 shared/extra-utils/feeds/feeds-command.ts delete mode 100644 shared/extra-utils/feeds/feeds.ts (limited to 'shared') diff --git a/shared/extra-utils/bulk/bulk-command.ts b/shared/extra-utils/bulk/bulk-command.ts new file mode 100644 index 000000000..fcbf04164 --- /dev/null +++ b/shared/extra-utils/bulk/bulk-command.ts @@ -0,0 +1,20 @@ + +import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model' +import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { AbstractCommand, OverrideCommandOptions } from '../shared' + +export class BulkCommand extends AbstractCommand { + + removeCommentsOf (options: OverrideCommandOptions & { + attributes: BulkRemoveCommentsOfBody + }) { + const { attributes } = options + + return this.postBodyRequest({ + ...options, + path: '/api/v1/bulk/remove-comments-of', + fields: attributes, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } +} diff --git a/shared/extra-utils/bulk/bulk.ts b/shared/extra-utils/bulk/bulk.ts deleted file mode 100644 index a58fb3fbb..000000000 --- a/shared/extra-utils/bulk/bulk.ts +++ /dev/null @@ -1,20 +0,0 @@ - -import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' -import { AbstractCommand, OverrideCommandOptions } from '../shared' - -export class BulkCommand extends AbstractCommand { - - removeCommentsOf (options: OverrideCommandOptions & { - attributes: BulkRemoveCommentsOfBody - }) { - const { attributes } = options - - return this.postBodyRequest({ - ...options, - path: '/api/v1/bulk/remove-comments-of', - fields: attributes, - defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 - }) - } -} diff --git a/shared/extra-utils/bulk/index.ts b/shared/extra-utils/bulk/index.ts index 5d2f9d3ad..391597243 100644 --- a/shared/extra-utils/bulk/index.ts +++ b/shared/extra-utils/bulk/index.ts @@ -1 +1 @@ -export * from './bulk' +export * from './bulk-command' diff --git a/shared/extra-utils/cli/cli-command.ts b/shared/extra-utils/cli/cli-command.ts new file mode 100644 index 000000000..bc1dddc68 --- /dev/null +++ b/shared/extra-utils/cli/cli-command.ts @@ -0,0 +1,23 @@ +import { exec } from 'child_process' +import { AbstractCommand } from '../shared' + +export class CLICommand extends AbstractCommand { + + static exec (command: string) { + return new Promise((res, rej) => { + exec(command, (err, stdout, _stderr) => { + if (err) return rej(err) + + return res(stdout) + }) + }) + } + + getEnv () { + return `NODE_ENV=test NODE_APP_INSTANCE=${this.server.internalServerNumber}` + } + + async execWithEnv (command: string) { + return CLICommand.exec(`${this.getEnv()} ${command}`) + } +} diff --git a/shared/extra-utils/cli/cli.ts b/shared/extra-utils/cli/cli.ts deleted file mode 100644 index bc1dddc68..000000000 --- a/shared/extra-utils/cli/cli.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { exec } from 'child_process' -import { AbstractCommand } from '../shared' - -export class CLICommand extends AbstractCommand { - - static exec (command: string) { - return new Promise((res, rej) => { - exec(command, (err, stdout, _stderr) => { - if (err) return rej(err) - - return res(stdout) - }) - }) - } - - getEnv () { - return `NODE_ENV=test NODE_APP_INSTANCE=${this.server.internalServerNumber}` - } - - async execWithEnv (command: string) { - return CLICommand.exec(`${this.getEnv()} ${command}`) - } -} diff --git a/shared/extra-utils/cli/index.ts b/shared/extra-utils/cli/index.ts index 8a3f31e2f..91b5abfbe 100644 --- a/shared/extra-utils/cli/index.ts +++ b/shared/extra-utils/cli/index.ts @@ -1 +1 @@ -export * from './cli' +export * from './cli-command' diff --git a/shared/extra-utils/custom-pages/custom-pages-command.ts b/shared/extra-utils/custom-pages/custom-pages-command.ts new file mode 100644 index 000000000..a062c9774 --- /dev/null +++ b/shared/extra-utils/custom-pages/custom-pages-command.ts @@ -0,0 +1,30 @@ +import { CustomPage } from '@shared/models' +import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { AbstractCommand, OverrideCommandOptions } from '../shared' + +export class CustomPagesCommand extends AbstractCommand { + + getInstanceHomepage (options: OverrideCommandOptions = {}) { + const path = '/api/v1/custom-pages/homepage/instance' + + return this.getRequestBody({ + ...options, + path, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + updateInstanceHomepage (options: OverrideCommandOptions & { + content: string + }) { + const { content } = options + const path = '/api/v1/custom-pages/homepage/instance' + + return this.putBodyRequest({ + ...options, + path, + fields: { content }, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } +} diff --git a/shared/extra-utils/custom-pages/custom-pages.ts b/shared/extra-utils/custom-pages/custom-pages.ts deleted file mode 100644 index 56dabdc0f..000000000 --- a/shared/extra-utils/custom-pages/custom-pages.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { CustomPage } from '@shared/models' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' -import { AbstractCommand, OverrideCommandOptions } from '../shared' - -export class CustomPagesCommand extends AbstractCommand { - - getInstanceHomepage (options: OverrideCommandOptions = {}) { - const path = '/api/v1/custom-pages/homepage/instance' - - return this.getRequestBody({ - ...options, - path, - defaultExpectedStatus: HttpStatusCode.OK_200 - }) - } - - updateInstanceHomepage (options: OverrideCommandOptions & { - content: string - }) { - const { content } = options - const path = '/api/v1/custom-pages/homepage/instance' - - return this.putBodyRequest({ - ...options, - path, - fields: { content }, - defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 - }) - } -} diff --git a/shared/extra-utils/custom-pages/index.ts b/shared/extra-utils/custom-pages/index.ts index 5e70778f8..58aed04f2 100644 --- a/shared/extra-utils/custom-pages/index.ts +++ b/shared/extra-utils/custom-pages/index.ts @@ -1 +1 @@ -export * from './custom-pages' +export * from './custom-pages-command' diff --git a/shared/extra-utils/feeds/feeds-command.ts b/shared/extra-utils/feeds/feeds-command.ts new file mode 100644 index 000000000..8031adf92 --- /dev/null +++ b/shared/extra-utils/feeds/feeds-command.ts @@ -0,0 +1,42 @@ + +import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { AbstractCommand, OverrideCommandOptions } from '../shared' + +type FeedType = 'videos' | 'video-comments' | 'subscriptions' + +export class FeedCommand extends AbstractCommand { + + getXML (options: OverrideCommandOptions & { + feed: FeedType + format?: string + }) { + const { feed, format } = options + const path = '/feeds/' + feed + '.xml' + + return this.getRequestText({ + ...options, + + path, + query: format ? { format } : undefined, + accept: 'application/xml', + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + getJSON (options: OverrideCommandOptions & { + feed: FeedType + query?: { [ id: string ]: any } + }) { + const { feed, query } = options + const path = '/feeds/' + feed + '.json' + + return this.getRequestText({ + ...options, + + path, + query, + accept: 'application/json', + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } +} diff --git a/shared/extra-utils/feeds/feeds.ts b/shared/extra-utils/feeds/feeds.ts deleted file mode 100644 index 012ce6cfe..000000000 --- a/shared/extra-utils/feeds/feeds.ts +++ /dev/null @@ -1,42 +0,0 @@ - -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' -import { AbstractCommand, OverrideCommandOptions } from '../shared' - -type FeedType = 'videos' | 'video-comments' | 'subscriptions' - -export class FeedCommand extends AbstractCommand { - - getXML (options: OverrideCommandOptions & { - feed: FeedType - format?: string - }) { - const { feed, format } = options - const path = '/feeds/' + feed + '.xml' - - return this.getRequestText({ - ...options, - - path, - query: format ? { format } : undefined, - accept: 'application/xml', - defaultExpectedStatus: HttpStatusCode.OK_200 - }) - } - - getJSON (options: OverrideCommandOptions & { - feed: FeedType - query?: { [ id: string ]: any } - }) { - const { feed, query } = options - const path = '/feeds/' + feed + '.json' - - return this.getRequestText({ - ...options, - - path, - query, - accept: 'application/json', - defaultExpectedStatus: HttpStatusCode.OK_200 - }) - } -} diff --git a/shared/extra-utils/feeds/index.ts b/shared/extra-utils/feeds/index.ts index 4634cb163..662a22b6f 100644 --- a/shared/extra-utils/feeds/index.ts +++ b/shared/extra-utils/feeds/index.ts @@ -1 +1 @@ -export * from './feeds' +export * from './feeds-command' diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index 10781d049..c4f0afdc4 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts @@ -4,7 +4,7 @@ export * from './cli' export * from './custom-pages' -export * from './feeds/feeds' +export * from './feeds' export * from './mock-servers/mock-instances-index' diff --git a/shared/extra-utils/shared/abstract-command.ts b/shared/extra-utils/shared/abstract-command.ts index 53c644124..7f812daa8 100644 --- a/shared/extra-utils/shared/abstract-command.ts +++ b/shared/extra-utils/shared/abstract-command.ts @@ -1,5 +1,5 @@ import { HttpStatusCode } from '@shared/core-utils' -import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, unwrap, unwrapBody, unwrapText } from '../requests/requests' +import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, unwrapBody, unwrapText } from '../requests/requests' import { ServerInfo } from '../server/servers' export interface OverrideCommandOptions { -- cgit v1.2.3