From bc8090411ddaa8d742ce4de3c83f9dba7bc18e2a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 11:07:12 +0200 Subject: Introduce stats command --- shared/extra-utils/index.ts | 4 ---- shared/extra-utils/server/index.ts | 3 +++ shared/extra-utils/server/servers.ts | 3 +++ shared/extra-utils/server/stats-command.ts | 25 +++++++++++++++++++++++++ shared/extra-utils/server/stats.ts | 23 ----------------------- 5 files changed, 31 insertions(+), 27 deletions(-) create mode 100644 shared/extra-utils/server/stats-command.ts delete mode 100644 shared/extra-utils/server/stats.ts (limited to 'shared') diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index cf6418249..f69d7241e 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts @@ -13,10 +13,6 @@ export * from './server' export * from './requests/check-api-params' export * from './requests/requests' -export * from './server/clients' -export * from './server/config' -export * from './server/servers' - export * from './users/accounts' export * from './users/blocklist' export * from './users/login' diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts index 3ee70f0cf..d37f46321 100644 --- a/shared/extra-utils/server/index.ts +++ b/shared/extra-utils/server/index.ts @@ -1,3 +1,4 @@ +export * from './config' export * from './contact-form-command' export * from './debug-command' export * from './follows-command' @@ -7,3 +8,5 @@ export * from './jobs-command' export * from './plugins-command' export * from './plugins' export * from './redundancy-command' +export * from './servers' +export * from './stats-command' diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index eaf39ecea..4603cf62e 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -22,6 +22,7 @@ import { FollowsCommand } from './follows-command' import { JobsCommand } from './jobs-command' import { PluginsCommand } from './plugins-command' import { RedundancyCommand } from './redundancy-command' +import { StatsCommand } from './stats-command' interface ServerInfo { app: ChildProcess @@ -89,6 +90,7 @@ interface ServerInfo { jobsCommand?: JobsCommand pluginsCommand?: PluginsCommand redundancyCommand?: RedundancyCommand + statsCommand?: StatsCommand } function parallelTests () { @@ -308,6 +310,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.jobsCommand = new JobsCommand(server) server.pluginsCommand = new PluginsCommand(server) server.redundancyCommand = new RedundancyCommand(server) + server.statsCommand = new StatsCommand(server) res(server) }) diff --git a/shared/extra-utils/server/stats-command.ts b/shared/extra-utils/server/stats-command.ts new file mode 100644 index 000000000..b51d9ceef --- /dev/null +++ b/shared/extra-utils/server/stats-command.ts @@ -0,0 +1,25 @@ +import { ServerStats } from '@shared/models' +import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { AbstractCommand, OverrideCommandOptions } from '../shared' + +export class StatsCommand extends AbstractCommand { + + get (options: OverrideCommandOptions & { + useCache?: boolean // default false + } = {}) { + const { useCache = false } = options + const path = '/api/v1/server/stats' + + const query = { + t: useCache ? undefined : new Date().getTime() + } + + return this.getRequestBody({ + ...options, + + path, + query, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } +} diff --git a/shared/extra-utils/server/stats.ts b/shared/extra-utils/server/stats.ts deleted file mode 100644 index b9dae24e2..000000000 --- a/shared/extra-utils/server/stats.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { makeGetRequest } from '../requests/requests' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' - -function getStats (url: string, useCache = false) { - const path = '/api/v1/server/stats' - - const query = { - t: useCache ? undefined : new Date().getTime() - } - - return makeGetRequest({ - url, - path, - query, - statusCodeExpected: HttpStatusCode.OK_200 - }) -} - -// --------------------------------------------------------------------------- - -export { - getStats -} -- cgit v1.2.3