From 329619b3453479f76c049816b7403b86e9d45cb5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 5 Jul 2021 16:37:50 +0200 Subject: Introduce CLI command --- shared/extra-utils/server/servers.ts | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 28e431e94..1b0775421 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -6,6 +6,8 @@ import { copy, ensureDir, pathExists, readdir, readFile, remove } from 'fs-extra import { join } from 'path' import { randomInt } from '../../core-utils/miscs/miscs' import { VideoChannel } from '../../models/videos' +import { BulkCommand } from '../bulk' +import { CLICommand } from '../cli' import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs' import { makeGetRequest } from '../requests/requests' @@ -60,6 +62,9 @@ interface ServerInfo { } videos?: { id: number, uuid: string }[] + + bulkCommand?: BulkCommand + cliCommand?: CLICommand } function parallelTests () { @@ -265,6 +270,9 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] } catch { /* empty */ } }) + server.bulkCommand = new BulkCommand(server) + server.cliCommand = new CLICommand(server) + res(server) }) }) -- cgit v1.2.3 From e8bd7ce7ccafe3e064b03978e9b512c1a4cc99e6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 09:55:05 +0200 Subject: Introduce CustomPage command --- shared/extra-utils/server/servers.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 1b0775421..e07926065 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -8,6 +8,7 @@ import { randomInt } from '../../core-utils/miscs/miscs' import { VideoChannel } from '../../models/videos' import { BulkCommand } from '../bulk' import { CLICommand } from '../cli' +import { CustomPagesCommand } from '../custom-pages' import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs' import { makeGetRequest } from '../requests/requests' @@ -65,6 +66,7 @@ interface ServerInfo { bulkCommand?: BulkCommand cliCommand?: CLICommand + customPageCommand?: CustomPagesCommand } function parallelTests () { @@ -272,6 +274,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.bulkCommand = new BulkCommand(server) server.cliCommand = new CLICommand(server) + server.customPageCommand = new CustomPagesCommand(server) res(server) }) -- cgit v1.2.3 From c1bc8ee4783d6ce3102524e6c2a02b2f0f6aab6d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 10:21:35 +0200 Subject: Introduce feed command --- shared/extra-utils/server/servers.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index e07926065..b64c9eec6 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -9,6 +9,7 @@ import { VideoChannel } from '../../models/videos' import { BulkCommand } from '../bulk' import { CLICommand } from '../cli' import { CustomPagesCommand } from '../custom-pages' +import { FeedCommand } from '../feeds' import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs' import { makeGetRequest } from '../requests/requests' @@ -67,6 +68,7 @@ interface ServerInfo { bulkCommand?: BulkCommand cliCommand?: CLICommand customPageCommand?: CustomPagesCommand + feedCommand?: FeedCommand } function parallelTests () { @@ -275,6 +277,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.bulkCommand = new BulkCommand(server) server.cliCommand = new CLICommand(server) server.customPageCommand = new CustomPagesCommand(server) + server.feedCommand = new FeedCommand(server) res(server) }) -- cgit v1.2.3 From a92ddacb38a4a17e117ca9ed41680a03580fb81d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 10:34:29 +0200 Subject: Introduce logs command --- shared/extra-utils/server/servers.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index b64c9eec6..4343eab93 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -10,6 +10,7 @@ import { BulkCommand } from '../bulk' import { CLICommand } from '../cli' import { CustomPagesCommand } from '../custom-pages' import { FeedCommand } from '../feeds' +import { LogsCommand } from '../logs' import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs' import { makeGetRequest } from '../requests/requests' @@ -69,6 +70,7 @@ interface ServerInfo { cliCommand?: CLICommand customPageCommand?: CustomPagesCommand feedCommand?: FeedCommand + logsCommand?: LogsCommand } function parallelTests () { @@ -278,6 +280,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.cliCommand = new CLICommand(server) server.customPageCommand = new CustomPagesCommand(server) server.feedCommand = new FeedCommand(server) + server.logsCommand = new LogsCommand(server) res(server) }) -- cgit v1.2.3 From 0c1a77e9ccf915184c431145a8b326d4ce271b46 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 12:01:59 +0200 Subject: Introduce abuse command --- shared/extra-utils/server/servers.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 4343eab93..f05f0dbbe 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -12,6 +12,7 @@ import { CustomPagesCommand } from '../custom-pages' import { FeedCommand } from '../feeds' import { LogsCommand } from '../logs' import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs' +import { AbusesCommand } from '../moderation' import { makeGetRequest } from '../requests/requests' interface ServerInfo { @@ -71,6 +72,7 @@ interface ServerInfo { customPageCommand?: CustomPagesCommand feedCommand?: FeedCommand logsCommand?: LogsCommand + abusesCommand?: AbusesCommand } function parallelTests () { @@ -281,6 +283,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.customPageCommand = new CustomPagesCommand(server) server.feedCommand = new FeedCommand(server) server.logsCommand = new LogsCommand(server) + server.abusesCommand = new AbusesCommand(server) res(server) }) -- cgit v1.2.3 From 23a3a8827cb8b862f5cc7ee2819f39918303beca Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 14:30:20 +0200 Subject: Introduce overviews command --- shared/extra-utils/server/servers.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index f05f0dbbe..70be96cf6 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -13,6 +13,7 @@ import { FeedCommand } from '../feeds' import { LogsCommand } from '../logs' import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs' import { AbusesCommand } from '../moderation' +import { OverviewsCommand } from '../overviews' import { makeGetRequest } from '../requests/requests' interface ServerInfo { @@ -73,6 +74,7 @@ interface ServerInfo { feedCommand?: FeedCommand logsCommand?: LogsCommand abusesCommand?: AbusesCommand + overviewsCommand?: OverviewsCommand } function parallelTests () { @@ -284,6 +286,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.feedCommand = new FeedCommand(server) server.logsCommand = new LogsCommand(server) server.abusesCommand = new AbusesCommand(server) + server.overviewsCommand = new OverviewsCommand(server) res(server) }) -- cgit v1.2.3 From af971e06c620bd46a5aa64c8833364e7022b5e3d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 15:22:51 +0200 Subject: Introduce search command --- shared/extra-utils/server/servers.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 70be96cf6..8ccf790fc 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -15,6 +15,7 @@ import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../mi import { AbusesCommand } from '../moderation' import { OverviewsCommand } from '../overviews' import { makeGetRequest } from '../requests/requests' +import { SearchCommand } from '../search' interface ServerInfo { app: ChildProcess @@ -75,6 +76,7 @@ interface ServerInfo { logsCommand?: LogsCommand abusesCommand?: AbusesCommand overviewsCommand?: OverviewsCommand + searchCommand?: SearchCommand } function parallelTests () { @@ -287,6 +289,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.logsCommand = new LogsCommand(server) server.abusesCommand = new AbusesCommand(server) server.overviewsCommand = new OverviewsCommand(server) + server.searchCommand = new SearchCommand(server) res(server) }) -- cgit v1.2.3 From 2d1ad5b96063d1e430ca99128a15e2e56cb614e0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 15:33:39 +0200 Subject: Move AP request in requests file --- shared/extra-utils/server/activitypub.ts | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 shared/extra-utils/server/activitypub.ts (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/activitypub.ts b/shared/extra-utils/server/activitypub.ts deleted file mode 100644 index cf967ed7d..000000000 --- a/shared/extra-utils/server/activitypub.ts +++ /dev/null @@ -1,15 +0,0 @@ -import * as request from 'supertest' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' - -function makeActivityPubGetRequest (url: string, path: string, expectedStatus = HttpStatusCode.OK_200) { - return request(url) - .get(path) - .set('Accept', 'application/activity+json,text/html;q=0.9,\\*/\\*;q=0.8') - .expect(expectedStatus) -} - -// --------------------------------------------------------------------------- - -export { - makeActivityPubGetRequest -} -- cgit v1.2.3 From a9c58393d36d221197b48884a1960e6126ab31d7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 15:53:25 +0200 Subject: Introduce contact form command --- shared/extra-utils/server/contact-form-command.ts | 31 +++++++++++++++++++++++ shared/extra-utils/server/contact-form.ts | 31 ----------------------- shared/extra-utils/server/index.ts | 1 + shared/extra-utils/server/servers.ts | 3 +++ 4 files changed, 35 insertions(+), 31 deletions(-) create mode 100644 shared/extra-utils/server/contact-form-command.ts delete mode 100644 shared/extra-utils/server/contact-form.ts create mode 100644 shared/extra-utils/server/index.ts (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/contact-form-command.ts b/shared/extra-utils/server/contact-form-command.ts new file mode 100644 index 000000000..943e5ccbb --- /dev/null +++ b/shared/extra-utils/server/contact-form-command.ts @@ -0,0 +1,31 @@ +import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { ContactForm } from '../../models/server' +import { AbstractCommand, OverrideCommandOptions } from '../shared' + +export class ContactFormCommand extends AbstractCommand { + + send (options: OverrideCommandOptions & { + fromEmail: string + fromName: string + subject: string + body: string + }) { + const path = '/api/v1/server/contact' + + const body: ContactForm = { + fromEmail: options.fromEmail, + fromName: options.fromName, + subject: options.subject, + body: options.body + } + + return this.postBodyRequest({ + ...options, + + path, + token: null, + fields: body, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } +} diff --git a/shared/extra-utils/server/contact-form.ts b/shared/extra-utils/server/contact-form.ts deleted file mode 100644 index 6c9232cc6..000000000 --- a/shared/extra-utils/server/contact-form.ts +++ /dev/null @@ -1,31 +0,0 @@ -import * as request from 'supertest' -import { ContactForm } from '../../models/server' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' - -function sendContactForm (options: { - url: string - fromEmail: string - fromName: string - subject: string - body: string - expectedStatus?: number -}) { - const path = '/api/v1/server/contact' - - const body: ContactForm = { - fromEmail: options.fromEmail, - fromName: options.fromName, - subject: options.subject, - body: options.body - } - return request(options.url) - .post(path) - .send(body) - .expect(options.expectedStatus || HttpStatusCode.NO_CONTENT_204) -} - -// --------------------------------------------------------------------------- - -export { - sendContactForm -} diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts new file mode 100644 index 000000000..4121c8828 --- /dev/null +++ b/shared/extra-utils/server/index.ts @@ -0,0 +1 @@ +export * from './contact-form-command' diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 8ccf790fc..b58639ba6 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -16,6 +16,7 @@ import { AbusesCommand } from '../moderation' import { OverviewsCommand } from '../overviews' import { makeGetRequest } from '../requests/requests' import { SearchCommand } from '../search' +import { ContactFormCommand } from './contact-form-command' interface ServerInfo { app: ChildProcess @@ -77,6 +78,7 @@ interface ServerInfo { abusesCommand?: AbusesCommand overviewsCommand?: OverviewsCommand searchCommand?: SearchCommand + contactFormCommand?: ContactFormCommand } function parallelTests () { @@ -290,6 +292,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.abusesCommand = new AbusesCommand(server) server.overviewsCommand = new OverviewsCommand(server) server.searchCommand = new SearchCommand(server) + server.contactFormCommand = new ContactFormCommand(server) res(server) }) -- cgit v1.2.3 From 883a9019085ff9013079d6b1539b86f2f519175a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 16:02:11 +0200 Subject: Introduce debug command --- shared/extra-utils/server/debug-command.ts | 32 +++++++++++++++++++++++++++++ shared/extra-utils/server/debug.ts | 33 ------------------------------ shared/extra-utils/server/index.ts | 1 + shared/extra-utils/server/jobs.ts | 9 ++++---- shared/extra-utils/server/servers.ts | 3 +++ 5 files changed, 40 insertions(+), 38 deletions(-) create mode 100644 shared/extra-utils/server/debug-command.ts delete mode 100644 shared/extra-utils/server/debug.ts (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/debug-command.ts b/shared/extra-utils/server/debug-command.ts new file mode 100644 index 000000000..eecbb1711 --- /dev/null +++ b/shared/extra-utils/server/debug-command.ts @@ -0,0 +1,32 @@ +import { Debug, SendDebugCommand } from '@shared/models' +import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { AbstractCommand, OverrideCommandOptions } from '../shared' + +export class DebugCommand extends AbstractCommand { + + getDebug (options: OverrideCommandOptions = {}) { + const path = '/api/v1/server/debug' + + return this.getRequestBody({ + ...options, + + path, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + sendCommand (options: OverrideCommandOptions & { + body: SendDebugCommand + }) { + const { body } = options + const path = '/api/v1/server/debug/run-command' + + return this.postBodyRequest({ + ...options, + + path, + fields: body, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } +} diff --git a/shared/extra-utils/server/debug.ts b/shared/extra-utils/server/debug.ts deleted file mode 100644 index f196812b7..000000000 --- a/shared/extra-utils/server/debug.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { makeGetRequest, makePostBodyRequest } from '../requests/requests' -import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' -import { SendDebugCommand } from '@shared/models' - -function getDebug (url: string, token: string) { - const path = '/api/v1/server/debug' - - return makeGetRequest({ - url, - path, - token, - statusCodeExpected: HttpStatusCode.OK_200 - }) -} - -function sendDebugCommand (url: string, token: string, body: SendDebugCommand) { - const path = '/api/v1/server/debug/run-command' - - return makePostBodyRequest({ - url, - path, - token, - fields: body, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 - }) -} - -// --------------------------------------------------------------------------- - -export { - getDebug, - sendDebugCommand -} diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts index 4121c8828..f0071ba72 100644 --- a/shared/extra-utils/server/index.ts +++ b/shared/extra-utils/server/index.ts @@ -1 +1,2 @@ export * from './contact-form-command' +export * from './debug-command' diff --git a/shared/extra-utils/server/jobs.ts b/shared/extra-utils/server/jobs.ts index 763374e03..a3683913a 100644 --- a/shared/extra-utils/server/jobs.ts +++ b/shared/extra-utils/server/jobs.ts @@ -1,7 +1,7 @@ import * as request from 'supertest' import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' -import { getDebug, makeGetRequest } from '../../../shared/extra-utils' -import { Job, JobState, JobType, ServerDebug } from '../../models' +import { makeGetRequest } from '../../../shared/extra-utils' +import { Job, JobState, JobType } from '../../models' import { wait } from '../miscs/miscs' import { ServerInfo } from './servers' @@ -90,9 +90,8 @@ async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { tasks.push(p) } - const p = getDebug(server.url, server.accessToken) - .then(res => res.body) - .then((obj: ServerDebug) => { + const p = server.debugCommand.getDebug() + .then(obj => { if (obj.activityPubMessagesWaiting !== 0) { pendingRequests = true } diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index b58639ba6..30e712ab8 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -17,6 +17,7 @@ import { OverviewsCommand } from '../overviews' import { makeGetRequest } from '../requests/requests' import { SearchCommand } from '../search' import { ContactFormCommand } from './contact-form-command' +import { DebugCommand } from './debug-command' interface ServerInfo { app: ChildProcess @@ -79,6 +80,7 @@ interface ServerInfo { overviewsCommand?: OverviewsCommand searchCommand?: SearchCommand contactFormCommand?: ContactFormCommand + debugCommand?: DebugCommand } function parallelTests () { @@ -293,6 +295,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.overviewsCommand = new OverviewsCommand(server) server.searchCommand = new SearchCommand(server) server.contactFormCommand = new ContactFormCommand(server) + server.debugCommand = new DebugCommand(server) res(server) }) -- cgit v1.2.3 From c3d29f694bf8c910f917be655626d0f80871124f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 09:16:40 +0200 Subject: Introduce follows command --- shared/extra-utils/server/follows-command.ts | 124 +++++++++++++++++++++++++ shared/extra-utils/server/follows.ts | 131 +-------------------------- shared/extra-utils/server/index.ts | 2 + shared/extra-utils/server/servers.ts | 3 + 4 files changed, 133 insertions(+), 127 deletions(-) create mode 100644 shared/extra-utils/server/follows-command.ts (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/follows-command.ts b/shared/extra-utils/server/follows-command.ts new file mode 100644 index 000000000..aba7bce82 --- /dev/null +++ b/shared/extra-utils/server/follows-command.ts @@ -0,0 +1,124 @@ +import { pick } from 'lodash' +import { ActivityPubActorType, ActorFollow, FollowState, ResultList } from '@shared/models' +import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { AbstractCommand, OverrideCommandOptions } from '../shared' +import { ServerInfo } from './servers' + +export class FollowsCommand extends AbstractCommand { + + getFollowers (options: OverrideCommandOptions & { + start: number + count: number + sort: string + search?: string + actorType?: ActivityPubActorType + state?: FollowState + }) { + const path = '/api/v1/server/followers' + + const toPick = [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ] + const query = pick(options, toPick) + + return this.getRequestBody>({ + ...options, + + token: null, + + path, + query, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + getFollowings (options: OverrideCommandOptions & { + start: number + count: number + sort: string + search?: string + actorType?: ActivityPubActorType + state?: FollowState + }) { + const path = '/api/v1/server/following' + + const toPick = [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ] + const query = pick(options, toPick) + + return this.getRequestBody>({ + ...options, + + token: null, + + path, + query, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + follow (options: OverrideCommandOptions & { + targets: string[] + }) { + const path = '/api/v1/server/following' + + const hosts = options.targets.map(f => f.replace(/^http:\/\//, '')) + + return this.postBodyRequest({ + ...options, + + path, + fields: { hosts }, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + async unfollow (options: OverrideCommandOptions & { + target: ServerInfo + }) { + const path = '/api/v1/server/following/' + options.target.host + + return this.deleteRequest({ + ...options, + + path, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + acceptFollower (options: OverrideCommandOptions & { + follower: string + }) { + const path = '/api/v1/server/followers/' + options.follower + '/accept' + + return this.postBodyRequest({ + ...options, + + path, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + rejectFollower (options: OverrideCommandOptions & { + follower: string + }) { + const path = '/api/v1/server/followers/' + options.follower + '/reject' + + return this.postBodyRequest({ + ...options, + + path, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + removeFollower (options: OverrideCommandOptions & { + follower: ServerInfo + }) { + const path = '/api/v1/server/followers/peertube@' + options.follower.host + + return this.deleteRequest({ + ...options, + + path, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } +} diff --git a/shared/extra-utils/server/follows.ts b/shared/extra-utils/server/follows.ts index 6aae4a31d..c23cebd81 100644 --- a/shared/extra-utils/server/follows.ts +++ b/shared/extra-utils/server/follows.ts @@ -1,126 +1,10 @@ -import * as request from 'supertest' -import { ServerInfo } from './servers' import { waitJobs } from './jobs' -import { makePostBodyRequest } from '../requests/requests' -import { ActivityPubActorType, FollowState } from '@shared/models' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' - -function getFollowersListPaginationAndSort (options: { - url: string - start: number - count: number - sort: string - search?: string - actorType?: ActivityPubActorType - state?: FollowState -}) { - const { url, start, count, sort, search, state, actorType } = options - const path = '/api/v1/server/followers' - - const query = { - start, - count, - sort, - search, - state, - actorType - } - - return request(url) - .get(path) - .query(query) - .set('Accept', 'application/json') - .expect(HttpStatusCode.OK_200) - .expect('Content-Type', /json/) -} - -function acceptFollower (url: string, token: string, follower: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) { - const path = '/api/v1/server/followers/' + follower + '/accept' - - return makePostBodyRequest({ - url, - token, - path, - statusCodeExpected - }) -} - -function rejectFollower (url: string, token: string, follower: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) { - const path = '/api/v1/server/followers/' + follower + '/reject' - - return makePostBodyRequest({ - url, - token, - path, - statusCodeExpected - }) -} - -function getFollowingListPaginationAndSort (options: { - url: string - start: number - count: number - sort: string - search?: string - actorType?: ActivityPubActorType - state?: FollowState -}) { - const { url, start, count, sort, search, state, actorType } = options - const path = '/api/v1/server/following' - - const query = { - start, - count, - sort, - search, - state, - actorType - } - - return request(url) - .get(path) - .query(query) - .set('Accept', 'application/json') - .expect(HttpStatusCode.OK_200) - .expect('Content-Type', /json/) -} - -function follow (follower: string, following: string[], accessToken: string, expectedStatus = HttpStatusCode.NO_CONTENT_204) { - const path = '/api/v1/server/following' - - const followingHosts = following.map(f => f.replace(/^http:\/\//, '')) - return request(follower) - .post(path) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + accessToken) - .send({ hosts: followingHosts }) - .expect(expectedStatus) -} - -async function unfollow (url: string, accessToken: string, target: ServerInfo, expectedStatus = HttpStatusCode.NO_CONTENT_204) { - const path = '/api/v1/server/following/' + target.host - - return request(url) - .delete(path) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + accessToken) - .expect(expectedStatus) -} - -function removeFollower (url: string, accessToken: string, follower: ServerInfo, expectedStatus = HttpStatusCode.NO_CONTENT_204) { - const path = '/api/v1/server/followers/peertube@' + follower.host - - return request(url) - .delete(path) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + accessToken) - .expect(expectedStatus) -} +import { ServerInfo } from './servers' async function doubleFollow (server1: ServerInfo, server2: ServerInfo) { await Promise.all([ - follow(server1.url, [ server2.url ], server1.accessToken), - follow(server2.url, [ server1.url ], server2.accessToken) + server1.followsCommand.follow({ targets: [ server2.url ] }), + server2.followsCommand.follow({ targets: [ server1.url ] }) ]) // Wait request propagation @@ -132,12 +16,5 @@ async function doubleFollow (server1: ServerInfo, server2: ServerInfo) { // --------------------------------------------------------------------------- export { - getFollowersListPaginationAndSort, - getFollowingListPaginationAndSort, - unfollow, - removeFollower, - follow, - doubleFollow, - acceptFollower, - rejectFollower + doubleFollow } diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts index f0071ba72..258084623 100644 --- a/shared/extra-utils/server/index.ts +++ b/shared/extra-utils/server/index.ts @@ -1,2 +1,4 @@ export * from './contact-form-command' export * from './debug-command' +export * from './follows-command' +export * from './follows' diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 30e712ab8..7ac80cea0 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -18,6 +18,7 @@ import { makeGetRequest } from '../requests/requests' import { SearchCommand } from '../search' import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' +import { FollowsCommand } from './follows-command' interface ServerInfo { app: ChildProcess @@ -81,6 +82,7 @@ interface ServerInfo { searchCommand?: SearchCommand contactFormCommand?: ContactFormCommand debugCommand?: DebugCommand + followsCommand?: FollowsCommand } function parallelTests () { @@ -296,6 +298,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.searchCommand = new SearchCommand(server) server.contactFormCommand = new ContactFormCommand(server) server.debugCommand = new DebugCommand(server) + server.followsCommand = new FollowsCommand(server) res(server) }) -- cgit v1.2.3 From 9c6327f803aaf4200672f1fc40b2f43786daca47 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 09:34:56 +0200 Subject: Introduce jobs command --- shared/extra-utils/server/index.ts | 2 + shared/extra-utils/server/jobs-command.ts | 35 ++++++++++++++++ shared/extra-utils/server/jobs.ts | 67 ++++--------------------------- shared/extra-utils/server/servers.ts | 3 ++ 4 files changed, 47 insertions(+), 60 deletions(-) create mode 100644 shared/extra-utils/server/jobs-command.ts (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts index 258084623..b5b6b2116 100644 --- a/shared/extra-utils/server/index.ts +++ b/shared/extra-utils/server/index.ts @@ -2,3 +2,5 @@ export * from './contact-form-command' export * from './debug-command' export * from './follows-command' export * from './follows' +export * from './jobs' +export * from './jobs-command' diff --git a/shared/extra-utils/server/jobs-command.ts b/shared/extra-utils/server/jobs-command.ts new file mode 100644 index 000000000..758b4a4af --- /dev/null +++ b/shared/extra-utils/server/jobs-command.ts @@ -0,0 +1,35 @@ +import { pick } from 'lodash' +import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { Job, JobState, JobType, ResultList } from '../../models' +import { AbstractCommand, OverrideCommandOptions } from '../shared' + +export class JobsCommand extends AbstractCommand { + + getJobsList (options: OverrideCommandOptions & { + state?: JobState + jobType?: JobType + start?: number + count?: number + sort?: string + } = {}) { + const path = this.buildJobsUrl(options.state) + + const query = pick(options, [ 'start', 'count', 'sort', 'jobType' ]) + + return this.getRequestBody>({ + ...options, + + path, + query, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + private buildJobsUrl (state?: JobState) { + let path = '/api/v1/jobs' + + if (state) path += '/' + state + + return path + } +} diff --git a/shared/extra-utils/server/jobs.ts b/shared/extra-utils/server/jobs.ts index a3683913a..b4b3d52e7 100644 --- a/shared/extra-utils/server/jobs.ts +++ b/shared/extra-utils/server/jobs.ts @@ -1,57 +1,8 @@ -import * as request from 'supertest' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' -import { makeGetRequest } from '../../../shared/extra-utils' -import { Job, JobState, JobType } from '../../models' + +import { JobState } from '../../models' import { wait } from '../miscs/miscs' import { ServerInfo } from './servers' -function buildJobsUrl (state?: JobState) { - let path = '/api/v1/jobs' - - if (state) path += '/' + state - - return path -} - -function getJobsList (url: string, accessToken: string, state?: JobState) { - const path = buildJobsUrl(state) - - return request(url) - .get(path) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + accessToken) - .expect(HttpStatusCode.OK_200) - .expect('Content-Type', /json/) -} - -function getJobsListPaginationAndSort (options: { - url: string - accessToken: string - start: number - count: number - sort: string - state?: JobState - jobType?: JobType -}) { - const { url, accessToken, state, start, count, sort, jobType } = options - const path = buildJobsUrl(state) - - const query = { - start, - count, - sort, - jobType - } - - return makeGetRequest({ - url, - path, - token: accessToken, - statusCodeExpected: HttpStatusCode.OK_200, - query - }) -} - async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { const pendingJobWait = process.env.NODE_PENDING_JOB_WAIT ? parseInt(process.env.NODE_PENDING_JOB_WAIT, 10) @@ -72,15 +23,13 @@ async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { // Check if each server has pending request for (const server of servers) { for (const state of states) { - const p = getJobsListPaginationAndSort({ - url: server.url, - accessToken: server.accessToken, - state: state, + const p = server.jobsCommand.getJobsList({ + state, start: 0, count: 10, sort: '-createdAt' - }).then(res => res.body.data) - .then((jobs: Job[]) => jobs.filter(j => !repeatableJobs.includes(j.type))) + }).then(body => body.data) + .then(jobs => jobs.filter(j => !repeatableJobs.includes(j.type))) .then(jobs => { if (jobs.length !== 0) { pendingRequests = true @@ -122,7 +71,5 @@ async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { // --------------------------------------------------------------------------- export { - getJobsList, - waitJobs, - getJobsListPaginationAndSort + waitJobs } diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 7ac80cea0..5511ce0b0 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -19,6 +19,7 @@ import { SearchCommand } from '../search' import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' import { FollowsCommand } from './follows-command' +import { JobsCommand } from './jobs-command' interface ServerInfo { app: ChildProcess @@ -83,6 +84,7 @@ interface ServerInfo { contactFormCommand?: ContactFormCommand debugCommand?: DebugCommand followsCommand?: FollowsCommand + jobsCommand?: JobsCommand } function parallelTests () { @@ -299,6 +301,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.contactFormCommand = new ContactFormCommand(server) server.debugCommand = new DebugCommand(server) server.followsCommand = new FollowsCommand(server) + server.jobsCommand = new JobsCommand(server) res(server) }) -- cgit v1.2.3 From ae2abfd3aed3e75d39a316b49b914d187faa7475 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 10:33:49 +0200 Subject: Introduce plugins command --- shared/extra-utils/server/index.ts | 2 + shared/extra-utils/server/plugins-command.ts | 245 ++++++++++++++++++++++ shared/extra-utils/server/plugins.ts | 297 +-------------------------- shared/extra-utils/server/servers.ts | 3 + 4 files changed, 254 insertions(+), 293 deletions(-) create mode 100644 shared/extra-utils/server/plugins-command.ts (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts index b5b6b2116..e602fec7e 100644 --- a/shared/extra-utils/server/index.ts +++ b/shared/extra-utils/server/index.ts @@ -4,3 +4,5 @@ export * from './follows-command' export * from './follows' export * from './jobs' export * from './jobs-command' +export * from './plugins-command' +export * from './plugins' diff --git a/shared/extra-utils/server/plugins-command.ts b/shared/extra-utils/server/plugins-command.ts new file mode 100644 index 000000000..f06e58a22 --- /dev/null +++ b/shared/extra-utils/server/plugins-command.ts @@ -0,0 +1,245 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import { readJSON, writeJSON } from 'fs-extra' +import { join } from 'path' +import { root } from '@server/helpers/core-utils' +import { HttpStatusCode } from '@shared/core-utils' +import { + PeerTubePlugin, + PeerTubePluginIndex, + PeertubePluginIndexList, + PluginPackageJson, + PluginTranslation, + PluginType, + PublicServerSetting, + RegisteredServerSettings, + ResultList +} from '@shared/models' +import { buildServerDirectory } from '../miscs' +import { AbstractCommand, OverrideCommandOptions } from '../shared' + +export class PluginsCommand extends AbstractCommand { + + static getPluginTestPath (suffix = '') { + return join(root(), 'server', 'tests', 'fixtures', 'peertube-plugin-test' + suffix) + } + + list (options: OverrideCommandOptions & { + start?: number + count?: number + sort?: string + pluginType?: PluginType + uninstalled?: boolean + }) { + const { start, count, sort, pluginType, uninstalled } = options + const path = '/api/v1/plugins' + + return this.getRequestBody>({ + ...options, + + path, + query: { + start, + count, + sort, + pluginType, + uninstalled + }, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + listAvailable (options: OverrideCommandOptions & { + start?: number + count?: number + sort?: string + pluginType?: PluginType + currentPeerTubeEngine?: string + search?: string + expectedStatus?: HttpStatusCode + }) { + const { start, count, sort, pluginType, search, currentPeerTubeEngine } = options + const path = '/api/v1/plugins/available' + + const query: PeertubePluginIndexList = { + start, + count, + sort, + pluginType, + currentPeerTubeEngine, + search + } + + return this.getRequestBody>({ + ...options, + + path, + query, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + get (options: OverrideCommandOptions & { + npmName: string + }) { + const path = '/api/v1/plugins/' + options.npmName + + return this.getRequestBody({ + ...options, + + path, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + updateSettings (options: OverrideCommandOptions & { + npmName: string + settings: any + }) { + const { npmName, settings } = options + const path = '/api/v1/plugins/' + npmName + '/settings' + + return this.putBodyRequest({ + ...options, + + path, + fields: { settings }, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + getRegisteredSettings (options: OverrideCommandOptions & { + npmName: string + }) { + const path = '/api/v1/plugins/' + options.npmName + '/registered-settings' + + return this.getRequestBody({ + ...options, + + path, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + getPublicSettings (options: OverrideCommandOptions & { + npmName: string + }) { + const { npmName } = options + const path = '/api/v1/plugins/' + npmName + '/public-settings' + + return this.getRequestBody({ + ...options, + + path, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + getTranslations (options: OverrideCommandOptions & { + locale: string + }) { + const { locale } = options + const path = '/plugins/translations/' + locale + '.json' + + return this.getRequestBody({ + ...options, + + path, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + install (options: OverrideCommandOptions & { + path?: string + npmName?: string + }) { + const { npmName, path } = options + const apiPath = '/api/v1/plugins/install' + + return this.postBodyRequest({ + ...options, + + path: apiPath, + fields: { npmName, path }, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + update (options: OverrideCommandOptions & { + path?: string + npmName?: string + }) { + const { npmName, path } = options + const apiPath = '/api/v1/plugins/update' + + return this.postBodyRequest({ + ...options, + + path: apiPath, + fields: { npmName, path }, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + uninstall (options: OverrideCommandOptions & { + npmName: string + }) { + const { npmName } = options + const apiPath = '/api/v1/plugins/uninstall' + + return this.postBodyRequest({ + ...options, + + path: apiPath, + fields: { npmName }, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + getCSS (options: OverrideCommandOptions = {}) { + const path = '/plugins/global.css' + + return this.getRequestText({ + ...options, + + path, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + getExternalAuth (options: OverrideCommandOptions & { + npmName: string + npmVersion: string + authName: string + query?: any + }) { + const { npmName, npmVersion, authName, query } = options + + const path = '/plugins/' + npmName + '/' + npmVersion + '/auth/' + authName + + return this.getRequest({ + ...options, + + path, + query, + defaultExpectedStatus: HttpStatusCode.OK_200, + redirects: 0 + }) + } + + updatePackageJSON (npmName: string, json: any) { + const path = this.getPackageJSONPath(npmName) + + return writeJSON(path, json) + } + + getPackageJSON (npmName: string): Promise { + const path = this.getPackageJSONPath(npmName) + + return readJSON(path) + } + + private getPackageJSONPath (npmName: string) { + return buildServerDirectory(this.server, join('plugins', 'node_modules', npmName, 'package.json')) + } +} diff --git a/shared/extra-utils/server/plugins.ts b/shared/extra-utils/server/plugins.ts index d53e5b382..1084ea4f4 100644 --- a/shared/extra-utils/server/plugins.ts +++ b/shared/extra-utils/server/plugins.ts @@ -1,307 +1,18 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import { expect } from 'chai' -import { readJSON, writeJSON } from 'fs-extra' -import { join } from 'path' -import { RegisteredServerSettings } from '@shared/models' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' -import { PeertubePluginIndexList } from '../../models/plugins/plugin-index/peertube-plugin-index-list.model' -import { PluginType } from '../../models/plugins/plugin.type' -import { buildServerDirectory, root } from '../miscs/miscs' -import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' -import { ServerInfo } from './servers' - -function listPlugins (parameters: { - url: string - accessToken: string - start?: number - count?: number - sort?: string - pluginType?: PluginType - uninstalled?: boolean - expectedStatus?: HttpStatusCode -}) { - const { url, accessToken, start, count, sort, pluginType, uninstalled, expectedStatus = HttpStatusCode.OK_200 } = parameters - const path = '/api/v1/plugins' - - return makeGetRequest({ - url, - path, - token: accessToken, - query: { - start, - count, - sort, - pluginType, - uninstalled - }, - statusCodeExpected: expectedStatus - }) -} - -function listAvailablePlugins (parameters: { - url: string - accessToken: string - start?: number - count?: number - sort?: string - pluginType?: PluginType - currentPeerTubeEngine?: string - search?: string - expectedStatus?: HttpStatusCode -}) { - const { - url, - accessToken, - start, - count, - sort, - pluginType, - search, - currentPeerTubeEngine, - expectedStatus = HttpStatusCode.OK_200 - } = parameters - const path = '/api/v1/plugins/available' - - const query: PeertubePluginIndexList = { - start, - count, - sort, - pluginType, - currentPeerTubeEngine, - search - } - - return makeGetRequest({ - url, - path, - token: accessToken, - query, - statusCodeExpected: expectedStatus - }) -} - -function getPlugin (parameters: { - url: string - accessToken: string - npmName: string - expectedStatus?: HttpStatusCode -}) { - const { url, accessToken, npmName, expectedStatus = HttpStatusCode.OK_200 } = parameters - const path = '/api/v1/plugins/' + npmName - - return makeGetRequest({ - url, - path, - token: accessToken, - statusCodeExpected: expectedStatus - }) -} - -function updatePluginSettings (parameters: { - url: string - accessToken: string - npmName: string - settings: any - expectedStatus?: HttpStatusCode -}) { - const { url, accessToken, npmName, settings, expectedStatus = HttpStatusCode.NO_CONTENT_204 } = parameters - const path = '/api/v1/plugins/' + npmName + '/settings' - - return makePutBodyRequest({ - url, - path, - token: accessToken, - fields: { settings }, - statusCodeExpected: expectedStatus - }) -} - -function getPluginRegisteredSettings (parameters: { - url: string - accessToken: string - npmName: string - expectedStatus?: HttpStatusCode -}) { - const { url, accessToken, npmName, expectedStatus = HttpStatusCode.OK_200 } = parameters - const path = '/api/v1/plugins/' + npmName + '/registered-settings' - - return makeGetRequest({ - url, - path, - token: accessToken, - statusCodeExpected: expectedStatus - }) -} +import { ServerInfo } from '../server/servers' async function testHelloWorldRegisteredSettings (server: ServerInfo) { - const res = await getPluginRegisteredSettings({ - url: server.url, - accessToken: server.accessToken, - npmName: 'peertube-plugin-hello-world' - }) - - const registeredSettings = (res.body as RegisteredServerSettings).registeredSettings + const body = await server.pluginsCommand.getRegisteredSettings({ npmName: 'peertube-plugin-hello-world' }) + const registeredSettings = body.registeredSettings expect(registeredSettings).to.have.length.at.least(1) const adminNameSettings = registeredSettings.find(s => s.name === 'admin-name') expect(adminNameSettings).to.not.be.undefined } -function getPublicSettings (parameters: { - url: string - npmName: string - expectedStatus?: HttpStatusCode -}) { - const { url, npmName, expectedStatus = HttpStatusCode.OK_200 } = parameters - const path = '/api/v1/plugins/' + npmName + '/public-settings' - - return makeGetRequest({ - url, - path, - statusCodeExpected: expectedStatus - }) -} - -function getPluginTranslations (parameters: { - url: string - locale: string - expectedStatus?: HttpStatusCode -}) { - const { url, locale, expectedStatus = HttpStatusCode.OK_200 } = parameters - const path = '/plugins/translations/' + locale + '.json' - - return makeGetRequest({ - url, - path, - statusCodeExpected: expectedStatus - }) -} - -function installPlugin (parameters: { - url: string - accessToken: string - path?: string - npmName?: string - expectedStatus?: HttpStatusCode -}) { - const { url, accessToken, npmName, path, expectedStatus = HttpStatusCode.OK_200 } = parameters - const apiPath = '/api/v1/plugins/install' - - return makePostBodyRequest({ - url, - path: apiPath, - token: accessToken, - fields: { npmName, path }, - statusCodeExpected: expectedStatus - }) -} - -function updatePlugin (parameters: { - url: string - accessToken: string - path?: string - npmName?: string - expectedStatus?: HttpStatusCode -}) { - const { url, accessToken, npmName, path, expectedStatus = HttpStatusCode.OK_200 } = parameters - const apiPath = '/api/v1/plugins/update' - - return makePostBodyRequest({ - url, - path: apiPath, - token: accessToken, - fields: { npmName, path }, - statusCodeExpected: expectedStatus - }) -} - -function uninstallPlugin (parameters: { - url: string - accessToken: string - npmName: string - expectedStatus?: HttpStatusCode -}) { - const { url, accessToken, npmName, expectedStatus = HttpStatusCode.NO_CONTENT_204 } = parameters - const apiPath = '/api/v1/plugins/uninstall' - - return makePostBodyRequest({ - url, - path: apiPath, - token: accessToken, - fields: { npmName }, - statusCodeExpected: expectedStatus - }) -} - -function getPluginsCSS (url: string) { - const path = '/plugins/global.css' - - return makeGetRequest({ - url, - path, - statusCodeExpected: HttpStatusCode.OK_200 - }) -} - -function getPackageJSONPath (server: ServerInfo, npmName: string) { - return buildServerDirectory(server, join('plugins', 'node_modules', npmName, 'package.json')) -} - -function updatePluginPackageJSON (server: ServerInfo, npmName: string, json: any) { - const path = getPackageJSONPath(server, npmName) - - return writeJSON(path, json) -} - -function getPluginPackageJSON (server: ServerInfo, npmName: string) { - const path = getPackageJSONPath(server, npmName) - - return readJSON(path) -} - -function getPluginTestPath (suffix = '') { - return join(root(), 'server', 'tests', 'fixtures', 'peertube-plugin-test' + suffix) -} - -function getExternalAuth (options: { - url: string - npmName: string - npmVersion: string - authName: string - query?: any - statusCodeExpected?: HttpStatusCode -}) { - const { url, npmName, npmVersion, authName, statusCodeExpected, query } = options - - const path = '/plugins/' + npmName + '/' + npmVersion + '/auth/' + authName - - return makeGetRequest({ - url, - path, - query, - statusCodeExpected: statusCodeExpected || HttpStatusCode.OK_200, - redirects: 0 - }) -} - export { - listPlugins, - listAvailablePlugins, - installPlugin, - getPluginTranslations, - getPluginsCSS, - updatePlugin, - getPlugin, - uninstallPlugin, - testHelloWorldRegisteredSettings, - updatePluginSettings, - getPluginRegisteredSettings, - getPackageJSONPath, - updatePluginPackageJSON, - getPluginPackageJSON, - getPluginTestPath, - getPublicSettings, - getExternalAuth + testHelloWorldRegisteredSettings } diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 5511ce0b0..79d6b7b1a 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -20,6 +20,7 @@ import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' import { FollowsCommand } from './follows-command' import { JobsCommand } from './jobs-command' +import { PluginsCommand } from './plugins-command' interface ServerInfo { app: ChildProcess @@ -85,6 +86,7 @@ interface ServerInfo { debugCommand?: DebugCommand followsCommand?: FollowsCommand jobsCommand?: JobsCommand + pluginsCommand?: PluginsCommand } function parallelTests () { @@ -302,6 +304,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.debugCommand = new DebugCommand(server) server.followsCommand = new FollowsCommand(server) server.jobsCommand = new JobsCommand(server) + server.pluginsCommand = new PluginsCommand(server) res(server) }) -- cgit v1.2.3 From dab047092b51b453f175069573d8865fb17acdfc Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 10:56:45 +0200 Subject: Introduce redundancy command --- shared/extra-utils/server/index.ts | 1 + shared/extra-utils/server/redundancy-command.ts | 77 ++++++++++++++++++++++ shared/extra-utils/server/redundancy.ts | 88 ------------------------- shared/extra-utils/server/servers.ts | 3 + 4 files changed, 81 insertions(+), 88 deletions(-) create mode 100644 shared/extra-utils/server/redundancy-command.ts delete mode 100644 shared/extra-utils/server/redundancy.ts (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts index e602fec7e..3ee70f0cf 100644 --- a/shared/extra-utils/server/index.ts +++ b/shared/extra-utils/server/index.ts @@ -6,3 +6,4 @@ export * from './jobs' export * from './jobs-command' export * from './plugins-command' export * from './plugins' +export * from './redundancy-command' diff --git a/shared/extra-utils/server/redundancy-command.ts b/shared/extra-utils/server/redundancy-command.ts new file mode 100644 index 000000000..d717d35f8 --- /dev/null +++ b/shared/extra-utils/server/redundancy-command.ts @@ -0,0 +1,77 @@ +import { ResultList, VideoRedundanciesTarget, VideoRedundancy } from '@shared/models' +import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { AbstractCommand, OverrideCommandOptions } from '../shared' + +export class RedundancyCommand extends AbstractCommand { + + updateRedundancy (options: OverrideCommandOptions & { + host: string + redundancyAllowed: boolean + }) { + const { host, redundancyAllowed } = options + const path = '/api/v1/server/redundancy/' + host + + return this.putBodyRequest({ + ...options, + + path, + fields: { redundancyAllowed }, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + listVideos (options: OverrideCommandOptions & { + target: VideoRedundanciesTarget + start?: number + count?: number + sort?: string + }) { + const path = '/api/v1/server/redundancy/videos' + + const { target, start, count, sort } = options + + return this.getRequestBody>({ + ...options, + + path, + + query: { + start: start ?? 0, + count: count ?? 5, + sort: sort ?? 'name', + target + }, + + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + addVideo (options: OverrideCommandOptions & { + videoId: number + }) { + const path = '/api/v1/server/redundancy/videos' + const { videoId } = options + + return this.postBodyRequest({ + ...options, + + path, + fields: { videoId }, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + removeVideo (options: OverrideCommandOptions & { + redundancyId: number + }) { + const { redundancyId } = options + const path = '/api/v1/server/redundancy/videos/' + redundancyId + + return this.deleteRequest({ + ...options, + + path, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } +} diff --git a/shared/extra-utils/server/redundancy.ts b/shared/extra-utils/server/redundancy.ts deleted file mode 100644 index b83815a37..000000000 --- a/shared/extra-utils/server/redundancy.ts +++ /dev/null @@ -1,88 +0,0 @@ -import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' -import { VideoRedundanciesTarget } from '@shared/models' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' - -function updateRedundancy ( - url: string, - accessToken: string, - host: string, - redundancyAllowed: boolean, - expectedStatus = HttpStatusCode.NO_CONTENT_204 -) { - const path = '/api/v1/server/redundancy/' + host - - return makePutBodyRequest({ - url, - path, - token: accessToken, - fields: { redundancyAllowed }, - statusCodeExpected: expectedStatus - }) -} - -function listVideoRedundancies (options: { - url: string - accessToken: string - target: VideoRedundanciesTarget - start?: number - count?: number - sort?: string - statusCodeExpected?: HttpStatusCode -}) { - const path = '/api/v1/server/redundancy/videos' - - const { url, accessToken, target, statusCodeExpected, start, count, sort } = options - - return makeGetRequest({ - url, - token: accessToken, - path, - query: { - start: start ?? 0, - count: count ?? 5, - sort: sort ?? 'name', - target - }, - statusCodeExpected: statusCodeExpected || HttpStatusCode.OK_200 - }) -} - -function addVideoRedundancy (options: { - url: string - accessToken: string - videoId: number -}) { - const path = '/api/v1/server/redundancy/videos' - const { url, accessToken, videoId } = options - - return makePostBodyRequest({ - url, - token: accessToken, - path, - fields: { videoId }, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 - }) -} - -function removeVideoRedundancy (options: { - url: string - accessToken: string - redundancyId: number -}) { - const { url, accessToken, redundancyId } = options - const path = '/api/v1/server/redundancy/videos/' + redundancyId - - return makeDeleteRequest({ - url, - token: accessToken, - path, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 - }) -} - -export { - updateRedundancy, - listVideoRedundancies, - addVideoRedundancy, - removeVideoRedundancy -} diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 79d6b7b1a..eaf39ecea 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -21,6 +21,7 @@ import { DebugCommand } from './debug-command' import { FollowsCommand } from './follows-command' import { JobsCommand } from './jobs-command' import { PluginsCommand } from './plugins-command' +import { RedundancyCommand } from './redundancy-command' interface ServerInfo { app: ChildProcess @@ -87,6 +88,7 @@ interface ServerInfo { followsCommand?: FollowsCommand jobsCommand?: JobsCommand pluginsCommand?: PluginsCommand + redundancyCommand?: RedundancyCommand } function parallelTests () { @@ -305,6 +307,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.followsCommand = new FollowsCommand(server) server.jobsCommand = new JobsCommand(server) server.pluginsCommand = new PluginsCommand(server) + server.redundancyCommand = new RedundancyCommand(server) res(server) }) -- cgit v1.2.3 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/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 ----------------------- 4 files changed, 31 insertions(+), 23 deletions(-) create mode 100644 shared/extra-utils/server/stats-command.ts delete mode 100644 shared/extra-utils/server/stats.ts (limited to 'shared/extra-utils/server') 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 From 65e6e2602c0d5521f3a6740f7469bb92830ecb53 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 11:51:09 +0200 Subject: Introduce config command --- shared/extra-utils/server/config-command.ts | 260 ++++++++++++++++++++++++++++ shared/extra-utils/server/config.ts | 260 ---------------------------- shared/extra-utils/server/index.ts | 2 +- shared/extra-utils/server/servers.ts | 3 + 4 files changed, 264 insertions(+), 261 deletions(-) create mode 100644 shared/extra-utils/server/config-command.ts delete mode 100644 shared/extra-utils/server/config.ts (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/config-command.ts b/shared/extra-utils/server/config-command.ts new file mode 100644 index 000000000..959848706 --- /dev/null +++ b/shared/extra-utils/server/config-command.ts @@ -0,0 +1,260 @@ +import { merge } from 'lodash' +import { DeepPartial, HttpStatusCode } from '@shared/core-utils' +import { About, ServerConfig } from '@shared/models' +import { CustomConfig } from '../../models/server/custom-config.model' +import { AbstractCommand, OverrideCommandOptions } from '../shared' + +export class ConfigCommand extends AbstractCommand { + + static getCustomConfigResolutions (enabled: boolean) { + return { + '240p': enabled, + '360p': enabled, + '480p': enabled, + '720p': enabled, + '1080p': enabled, + '1440p': enabled, + '2160p': enabled + } + } + + getConfig (options: OverrideCommandOptions = {}) { + const path = '/api/v1/config' + + return this.getRequestBody({ + ...options, + + token: null, + path, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + getAbout (options: OverrideCommandOptions = {}) { + const path = '/api/v1/config/about' + + return this.getRequestBody({ + ...options, + + token: null, + path, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + getCustomConfig (options: OverrideCommandOptions = {}) { + const path = '/api/v1/config/custom' + + return this.getRequestBody({ + ...options, + + path, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + updateCustomConfig (options: OverrideCommandOptions & { + newCustomConfig: CustomConfig + }) { + const path = '/api/v1/config/custom' + + return this.putBodyRequest({ + ...options, + + path, + fields: options.newCustomConfig, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + deleteCustomConfig (options: OverrideCommandOptions = {}) { + const path = '/api/v1/config/custom' + + return this.deleteRequest({ + ...options, + + path, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + updateCustomSubConfig (options: OverrideCommandOptions & { + newConfig: DeepPartial + }) { + const newCustomConfig: CustomConfig = { + instance: { + name: 'PeerTube updated', + shortDescription: 'my short description', + description: 'my super description', + terms: 'my super terms', + codeOfConduct: 'my super coc', + + creationReason: 'my super creation reason', + moderationInformation: 'my super moderation information', + administrator: 'Kuja', + maintenanceLifetime: 'forever', + businessModel: 'my super business model', + hardwareInformation: '2vCore 3GB RAM', + + languages: [ 'en', 'es' ], + categories: [ 1, 2 ], + + isNSFW: true, + defaultNSFWPolicy: 'blur', + + defaultClientRoute: '/videos/recently-added', + + customizations: { + javascript: 'alert("coucou")', + css: 'body { background-color: red; }' + } + }, + theme: { + default: 'default' + }, + services: { + twitter: { + username: '@MySuperUsername', + whitelisted: true + } + }, + cache: { + previews: { + size: 2 + }, + captions: { + size: 3 + }, + torrents: { + size: 4 + } + }, + signup: { + enabled: false, + limit: 5, + requiresEmailVerification: false, + minimumAge: 16 + }, + admin: { + email: 'superadmin1@example.com' + }, + contactForm: { + enabled: true + }, + user: { + videoQuota: 5242881, + videoQuotaDaily: 318742 + }, + transcoding: { + enabled: true, + allowAdditionalExtensions: true, + allowAudioFiles: true, + threads: 1, + concurrency: 3, + profile: 'default', + resolutions: { + '0p': false, + '240p': false, + '360p': true, + '480p': true, + '720p': false, + '1080p': false, + '1440p': false, + '2160p': false + }, + webtorrent: { + enabled: true + }, + hls: { + enabled: false + } + }, + live: { + enabled: true, + allowReplay: false, + maxDuration: -1, + maxInstanceLives: -1, + maxUserLives: 50, + transcoding: { + enabled: true, + threads: 4, + profile: 'default', + resolutions: { + '240p': true, + '360p': true, + '480p': true, + '720p': true, + '1080p': true, + '1440p': true, + '2160p': true + } + } + }, + import: { + videos: { + concurrency: 3, + http: { + enabled: false + }, + torrent: { + enabled: false + } + } + }, + trending: { + videos: { + algorithms: { + enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ], + default: 'hot' + } + } + }, + autoBlacklist: { + videos: { + ofUsers: { + enabled: false + } + } + }, + followers: { + instance: { + enabled: true, + manualApproval: false + } + }, + followings: { + instance: { + autoFollowBack: { + enabled: false + }, + autoFollowIndex: { + indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts', + enabled: false + } + } + }, + broadcastMessage: { + enabled: true, + level: 'warning', + message: 'hello', + dismissable: true + }, + search: { + remoteUri: { + users: true, + anonymous: true + }, + searchIndex: { + enabled: true, + url: 'https://search.joinpeertube.org', + disableLocalSearch: true, + isDefaultSearch: true + } + } + } + + merge(newCustomConfig, options.newConfig) + + return this.updateCustomConfig({ ...options, newCustomConfig }) + } +} diff --git a/shared/extra-utils/server/config.ts b/shared/extra-utils/server/config.ts deleted file mode 100644 index 9fcfb31fd..000000000 --- a/shared/extra-utils/server/config.ts +++ /dev/null @@ -1,260 +0,0 @@ -import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests' -import { CustomConfig } from '../../models/server/custom-config.model' -import { DeepPartial, HttpStatusCode } from '@shared/core-utils' -import { merge } from 'lodash' - -function getConfig (url: string) { - const path = '/api/v1/config' - - return makeGetRequest({ - url, - path, - statusCodeExpected: HttpStatusCode.OK_200 - }) -} - -function getAbout (url: string) { - const path = '/api/v1/config/about' - - return makeGetRequest({ - url, - path, - statusCodeExpected: HttpStatusCode.OK_200 - }) -} - -function getCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) { - const path = '/api/v1/config/custom' - - return makeGetRequest({ - url, - token, - path, - statusCodeExpected - }) -} - -function updateCustomConfig (url: string, token: string, newCustomConfig: CustomConfig, statusCodeExpected = HttpStatusCode.OK_200) { - const path = '/api/v1/config/custom' - - return makePutBodyRequest({ - url, - token, - path, - fields: newCustomConfig, - statusCodeExpected - }) -} - -function updateCustomSubConfig (url: string, token: string, newConfig: DeepPartial) { - const updateParams: CustomConfig = { - instance: { - name: 'PeerTube updated', - shortDescription: 'my short description', - description: 'my super description', - terms: 'my super terms', - codeOfConduct: 'my super coc', - - creationReason: 'my super creation reason', - moderationInformation: 'my super moderation information', - administrator: 'Kuja', - maintenanceLifetime: 'forever', - businessModel: 'my super business model', - hardwareInformation: '2vCore 3GB RAM', - - languages: [ 'en', 'es' ], - categories: [ 1, 2 ], - - isNSFW: true, - defaultNSFWPolicy: 'blur', - - defaultClientRoute: '/videos/recently-added', - - customizations: { - javascript: 'alert("coucou")', - css: 'body { background-color: red; }' - } - }, - theme: { - default: 'default' - }, - services: { - twitter: { - username: '@MySuperUsername', - whitelisted: true - } - }, - cache: { - previews: { - size: 2 - }, - captions: { - size: 3 - }, - torrents: { - size: 4 - } - }, - signup: { - enabled: false, - limit: 5, - requiresEmailVerification: false, - minimumAge: 16 - }, - admin: { - email: 'superadmin1@example.com' - }, - contactForm: { - enabled: true - }, - user: { - videoQuota: 5242881, - videoQuotaDaily: 318742 - }, - transcoding: { - enabled: true, - allowAdditionalExtensions: true, - allowAudioFiles: true, - threads: 1, - concurrency: 3, - profile: 'default', - resolutions: { - '0p': false, - '240p': false, - '360p': true, - '480p': true, - '720p': false, - '1080p': false, - '1440p': false, - '2160p': false - }, - webtorrent: { - enabled: true - }, - hls: { - enabled: false - } - }, - live: { - enabled: true, - allowReplay: false, - maxDuration: -1, - maxInstanceLives: -1, - maxUserLives: 50, - transcoding: { - enabled: true, - threads: 4, - profile: 'default', - resolutions: { - '240p': true, - '360p': true, - '480p': true, - '720p': true, - '1080p': true, - '1440p': true, - '2160p': true - } - } - }, - import: { - videos: { - concurrency: 3, - http: { - enabled: false - }, - torrent: { - enabled: false - } - } - }, - trending: { - videos: { - algorithms: { - enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ], - default: 'hot' - } - } - }, - autoBlacklist: { - videos: { - ofUsers: { - enabled: false - } - } - }, - followers: { - instance: { - enabled: true, - manualApproval: false - } - }, - followings: { - instance: { - autoFollowBack: { - enabled: false - }, - autoFollowIndex: { - indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts', - enabled: false - } - } - }, - broadcastMessage: { - enabled: true, - level: 'warning', - message: 'hello', - dismissable: true - }, - search: { - remoteUri: { - users: true, - anonymous: true - }, - searchIndex: { - enabled: true, - url: 'https://search.joinpeertube.org', - disableLocalSearch: true, - isDefaultSearch: true - } - } - } - - merge(updateParams, newConfig) - - return updateCustomConfig(url, token, updateParams) -} - -function getCustomConfigResolutions (enabled: boolean) { - return { - '240p': enabled, - '360p': enabled, - '480p': enabled, - '720p': enabled, - '1080p': enabled, - '1440p': enabled, - '2160p': enabled - } -} - -function deleteCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) { - const path = '/api/v1/config/custom' - - return makeDeleteRequest({ - url, - token, - path, - statusCodeExpected - }) -} - -// --------------------------------------------------------------------------- - -export { - getConfig, - getCustomConfig, - updateCustomConfig, - getAbout, - deleteCustomConfig, - updateCustomSubConfig, - getCustomConfigResolutions -} diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts index d37f46321..03c3b0123 100644 --- a/shared/extra-utils/server/index.ts +++ b/shared/extra-utils/server/index.ts @@ -1,4 +1,4 @@ -export * from './config' +export * from './config-command' export * from './contact-form-command' export * from './debug-command' export * from './follows-command' diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 4603cf62e..c33b68316 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -16,6 +16,7 @@ import { AbusesCommand } from '../moderation' import { OverviewsCommand } from '../overviews' import { makeGetRequest } from '../requests/requests' import { SearchCommand } from '../search' +import { ConfigCommand } from './config-command' import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' import { FollowsCommand } from './follows-command' @@ -91,6 +92,7 @@ interface ServerInfo { pluginsCommand?: PluginsCommand redundancyCommand?: RedundancyCommand statsCommand?: StatsCommand + configCommand?: ConfigCommand } function parallelTests () { @@ -311,6 +313,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.pluginsCommand = new PluginsCommand(server) server.redundancyCommand = new RedundancyCommand(server) server.statsCommand = new StatsCommand(server) + server.configCommand = new ConfigCommand(server) res(server) }) -- cgit v1.2.3 From 87e2635a50ac2decb1c330e55c2ff7b6d07a85de Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 11:55:16 +0200 Subject: Introduce socket io command --- shared/extra-utils/server/servers.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index c33b68316..8bd4446be 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -16,6 +16,7 @@ import { AbusesCommand } from '../moderation' import { OverviewsCommand } from '../overviews' import { makeGetRequest } from '../requests/requests' import { SearchCommand } from '../search' +import { SocketIOCommand } from '../socket' import { ConfigCommand } from './config-command' import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' @@ -93,6 +94,7 @@ interface ServerInfo { redundancyCommand?: RedundancyCommand statsCommand?: StatsCommand configCommand?: ConfigCommand + socketIOCommand?: SocketIOCommand } function parallelTests () { @@ -314,6 +316,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.redundancyCommand = new RedundancyCommand(server) server.statsCommand = new StatsCommand(server) server.configCommand = new ConfigCommand(server) + server.socketIOCommand = new SocketIOCommand(server) res(server) }) -- cgit v1.2.3 From 9fff08cf83f34339df7ed4ac770e1dee536adf9d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 13:38:26 +0200 Subject: Introduce accounts command --- shared/extra-utils/server/servers.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 8bd4446be..c2cab9818 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -17,6 +17,7 @@ import { OverviewsCommand } from '../overviews' import { makeGetRequest } from '../requests/requests' import { SearchCommand } from '../search' import { SocketIOCommand } from '../socket' +import { AccountsCommand } from '../users' import { ConfigCommand } from './config-command' import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' @@ -95,6 +96,7 @@ interface ServerInfo { statsCommand?: StatsCommand configCommand?: ConfigCommand socketIOCommand?: SocketIOCommand + accountsCommand?: AccountsCommand } function parallelTests () { @@ -317,6 +319,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.statsCommand = new StatsCommand(server) server.configCommand = new ConfigCommand(server) server.socketIOCommand = new SocketIOCommand(server) + server.accountsCommand = new AccountsCommand(server) res(server) }) -- cgit v1.2.3 From 5f8bd4cbb178290da7d8f81e996f19f0eccc8e4c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 16:02:46 +0200 Subject: Introduce blocklist command --- shared/extra-utils/server/servers.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index c2cab9818..3c709666d 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -17,7 +17,7 @@ import { OverviewsCommand } from '../overviews' import { makeGetRequest } from '../requests/requests' import { SearchCommand } from '../search' import { SocketIOCommand } from '../socket' -import { AccountsCommand } from '../users' +import { AccountsCommand, BlocklistCommand } from '../users' import { ConfigCommand } from './config-command' import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' @@ -97,6 +97,7 @@ interface ServerInfo { configCommand?: ConfigCommand socketIOCommand?: SocketIOCommand accountsCommand?: AccountsCommand + blocklistCommand?: BlocklistCommand } function parallelTests () { @@ -320,6 +321,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.configCommand = new ConfigCommand(server) server.socketIOCommand = new SocketIOCommand(server) server.accountsCommand = new AccountsCommand(server) + server.blocklistCommand = new BlocklistCommand(server) res(server) }) -- cgit v1.2.3 From 2c27e70471120c92e0bc8c8114141fbb31ff98ac Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 16:40:49 +0200 Subject: Introduce subscriptions command --- shared/extra-utils/server/servers.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 3c709666d..57b37728a 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -17,7 +17,7 @@ import { OverviewsCommand } from '../overviews' import { makeGetRequest } from '../requests/requests' import { SearchCommand } from '../search' import { SocketIOCommand } from '../socket' -import { AccountsCommand, BlocklistCommand } from '../users' +import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users' import { ConfigCommand } from './config-command' import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' @@ -98,6 +98,7 @@ interface ServerInfo { socketIOCommand?: SocketIOCommand accountsCommand?: AccountsCommand blocklistCommand?: BlocklistCommand + subscriptionsCommand?: SubscriptionsCommand } function parallelTests () { @@ -322,6 +323,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.socketIOCommand = new SocketIOCommand(server) server.accountsCommand = new AccountsCommand(server) server.blocklistCommand = new BlocklistCommand(server) + server.subscriptionsCommand = new SubscriptionsCommand(server) res(server) }) -- cgit v1.2.3 From 4f2199144e428c16460750305f737b890c1ac322 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 10:18:40 +0200 Subject: Introduce live command --- shared/extra-utils/server/servers.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 57b37728a..eca0689aa 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -18,6 +18,7 @@ import { makeGetRequest } from '../requests/requests' import { SearchCommand } from '../search' import { SocketIOCommand } from '../socket' import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users' +import { LiveCommand } from '../videos' import { ConfigCommand } from './config-command' import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' @@ -99,6 +100,7 @@ interface ServerInfo { accountsCommand?: AccountsCommand blocklistCommand?: BlocklistCommand subscriptionsCommand?: SubscriptionsCommand + liveCommand?: LiveCommand } function parallelTests () { @@ -324,6 +326,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.accountsCommand = new AccountsCommand(server) server.blocklistCommand = new BlocklistCommand(server) server.subscriptionsCommand = new SubscriptionsCommand(server) + server.liveCommand = new LiveCommand(server) res(server) }) -- cgit v1.2.3 From d897210c2db1ca2acc1e7b28a13127647ab2222c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 10:23:21 +0200 Subject: Introduce services command --- shared/extra-utils/server/servers.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index eca0689aa..cb2a8814b 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 } from '../videos' +import { LiveCommand, ServicesCommand } from '../videos' import { ConfigCommand } from './config-command' import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' @@ -101,6 +101,7 @@ interface ServerInfo { blocklistCommand?: BlocklistCommand subscriptionsCommand?: SubscriptionsCommand liveCommand?: LiveCommand + servicesCommand?: ServicesCommand } function parallelTests () { @@ -327,6 +328,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.blocklistCommand = new BlocklistCommand(server) server.subscriptionsCommand = new SubscriptionsCommand(server) server.liveCommand = new LiveCommand(server) + server.servicesCommand = new ServicesCommand(server) res(server) }) -- cgit v1.2.3 From a1637fa1e25b60a88f7cfe50aac8953f50d55761 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 10:55:16 +0200 Subject: Specify if we want to fallback to the server token --- shared/extra-utils/server/config-command.ts | 7 +++++-- shared/extra-utils/server/contact-form-command.ts | 2 +- shared/extra-utils/server/debug-command.ts | 2 ++ shared/extra-utils/server/follows-command.ts | 11 +++++++---- shared/extra-utils/server/jobs-command.ts | 1 + shared/extra-utils/server/plugins-command.ts | 12 ++++++++++++ shared/extra-utils/server/redundancy-command.ts | 4 ++++ shared/extra-utils/server/stats-command.ts | 1 + 8 files changed, 33 insertions(+), 7 deletions(-) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/config-command.ts b/shared/extra-utils/server/config-command.ts index 959848706..f5d7fc5e3 100644 --- a/shared/extra-utils/server/config-command.ts +++ b/shared/extra-utils/server/config-command.ts @@ -24,8 +24,8 @@ export class ConfigCommand extends AbstractCommand { return this.getRequestBody({ ...options, - token: null, path, + implicitToken: false, defaultExpectedStatus: HttpStatusCode.OK_200 }) } @@ -36,8 +36,8 @@ export class ConfigCommand extends AbstractCommand { return this.getRequestBody({ ...options, - token: null, path, + implicitToken: false, defaultExpectedStatus: HttpStatusCode.OK_200 }) } @@ -49,6 +49,7 @@ export class ConfigCommand extends AbstractCommand { ...options, path, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.OK_200 }) } @@ -63,6 +64,7 @@ export class ConfigCommand extends AbstractCommand { path, fields: options.newCustomConfig, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.OK_200 }) } @@ -74,6 +76,7 @@ export class ConfigCommand extends AbstractCommand { ...options, path, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.OK_200 }) } diff --git a/shared/extra-utils/server/contact-form-command.ts b/shared/extra-utils/server/contact-form-command.ts index 943e5ccbb..8d034552b 100644 --- a/shared/extra-utils/server/contact-form-command.ts +++ b/shared/extra-utils/server/contact-form-command.ts @@ -23,8 +23,8 @@ export class ContactFormCommand extends AbstractCommand { ...options, path, - token: null, fields: body, + implicitToken: false, defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 }) } diff --git a/shared/extra-utils/server/debug-command.ts b/shared/extra-utils/server/debug-command.ts index eecbb1711..8b24b3067 100644 --- a/shared/extra-utils/server/debug-command.ts +++ b/shared/extra-utils/server/debug-command.ts @@ -11,6 +11,7 @@ export class DebugCommand extends AbstractCommand { ...options, path, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.OK_200 }) } @@ -26,6 +27,7 @@ export class DebugCommand extends AbstractCommand { path, fields: body, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 }) } diff --git a/shared/extra-utils/server/follows-command.ts b/shared/extra-utils/server/follows-command.ts index aba7bce82..4e1e56d7a 100644 --- a/shared/extra-utils/server/follows-command.ts +++ b/shared/extra-utils/server/follows-command.ts @@ -22,10 +22,9 @@ export class FollowsCommand extends AbstractCommand { return this.getRequestBody>({ ...options, - token: null, - path, query, + implicitToken: false, defaultExpectedStatus: HttpStatusCode.OK_200 }) } @@ -46,10 +45,9 @@ export class FollowsCommand extends AbstractCommand { return this.getRequestBody>({ ...options, - token: null, - path, query, + implicitToken: false, defaultExpectedStatus: HttpStatusCode.OK_200 }) } @@ -66,6 +64,7 @@ export class FollowsCommand extends AbstractCommand { path, fields: { hosts }, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 }) } @@ -79,6 +78,7 @@ export class FollowsCommand extends AbstractCommand { ...options, path, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 }) } @@ -92,6 +92,7 @@ export class FollowsCommand extends AbstractCommand { ...options, path, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 }) } @@ -105,6 +106,7 @@ export class FollowsCommand extends AbstractCommand { ...options, path, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 }) } @@ -118,6 +120,7 @@ export class FollowsCommand extends AbstractCommand { ...options, path, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 }) } diff --git a/shared/extra-utils/server/jobs-command.ts b/shared/extra-utils/server/jobs-command.ts index 758b4a4af..392b868c1 100644 --- a/shared/extra-utils/server/jobs-command.ts +++ b/shared/extra-utils/server/jobs-command.ts @@ -21,6 +21,7 @@ export class JobsCommand extends AbstractCommand { path, query, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.OK_200 }) } diff --git a/shared/extra-utils/server/plugins-command.ts b/shared/extra-utils/server/plugins-command.ts index f06e58a22..ff49d58c4 100644 --- a/shared/extra-utils/server/plugins-command.ts +++ b/shared/extra-utils/server/plugins-command.ts @@ -45,6 +45,7 @@ export class PluginsCommand extends AbstractCommand { pluginType, uninstalled }, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.OK_200 }) } @@ -75,6 +76,7 @@ export class PluginsCommand extends AbstractCommand { path, query, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.OK_200 }) } @@ -88,6 +90,7 @@ export class PluginsCommand extends AbstractCommand { ...options, path, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.OK_200 }) } @@ -104,6 +107,7 @@ export class PluginsCommand extends AbstractCommand { path, fields: { settings }, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 }) } @@ -117,6 +121,7 @@ export class PluginsCommand extends AbstractCommand { ...options, path, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.OK_200 }) } @@ -131,6 +136,7 @@ export class PluginsCommand extends AbstractCommand { ...options, path, + implicitToken: false, defaultExpectedStatus: HttpStatusCode.OK_200 }) } @@ -145,6 +151,7 @@ export class PluginsCommand extends AbstractCommand { ...options, path, + implicitToken: false, defaultExpectedStatus: HttpStatusCode.OK_200 }) } @@ -161,6 +168,7 @@ export class PluginsCommand extends AbstractCommand { path: apiPath, fields: { npmName, path }, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.OK_200 }) } @@ -177,6 +185,7 @@ export class PluginsCommand extends AbstractCommand { path: apiPath, fields: { npmName, path }, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.OK_200 }) } @@ -192,6 +201,7 @@ export class PluginsCommand extends AbstractCommand { path: apiPath, fields: { npmName }, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 }) } @@ -203,6 +213,7 @@ export class PluginsCommand extends AbstractCommand { ...options, path, + implicitToken: false, defaultExpectedStatus: HttpStatusCode.OK_200 }) } @@ -222,6 +233,7 @@ export class PluginsCommand extends AbstractCommand { path, query, + implicitToken: false, defaultExpectedStatus: HttpStatusCode.OK_200, redirects: 0 }) diff --git a/shared/extra-utils/server/redundancy-command.ts b/shared/extra-utils/server/redundancy-command.ts index d717d35f8..728332fdd 100644 --- a/shared/extra-utils/server/redundancy-command.ts +++ b/shared/extra-utils/server/redundancy-command.ts @@ -16,6 +16,7 @@ export class RedundancyCommand extends AbstractCommand { path, fields: { redundancyAllowed }, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 }) } @@ -42,6 +43,7 @@ export class RedundancyCommand extends AbstractCommand { target }, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.OK_200 }) } @@ -57,6 +59,7 @@ export class RedundancyCommand extends AbstractCommand { path, fields: { videoId }, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 }) } @@ -71,6 +74,7 @@ export class RedundancyCommand extends AbstractCommand { ...options, path, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 }) } diff --git a/shared/extra-utils/server/stats-command.ts b/shared/extra-utils/server/stats-command.ts index b51d9ceef..f0f02ca08 100644 --- a/shared/extra-utils/server/stats-command.ts +++ b/shared/extra-utils/server/stats-command.ts @@ -19,6 +19,7 @@ export class StatsCommand extends AbstractCommand { path, query, + implicitToken: false, defaultExpectedStatus: HttpStatusCode.OK_200 }) } -- cgit v1.2.3 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 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'shared/extra-utils/server') 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) }) -- cgit v1.2.3 From a2470c9f4bfc7f49f4b94de935bacdd53fd54f29 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 11:49:38 +0200 Subject: Introduce captions command --- shared/extra-utils/server/servers.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index a4432902f..170360341 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, BlacklistCommand } from '../videos' +import { LiveCommand, ServicesCommand, BlacklistCommand, CaptionsCommand } from '../videos' import { ConfigCommand } from './config-command' import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' @@ -103,6 +103,7 @@ interface ServerInfo { liveCommand?: LiveCommand servicesCommand?: ServicesCommand blacklistCommand?: BlacklistCommand + captionsCommand?: CaptionsCommand } function parallelTests () { @@ -331,6 +332,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.liveCommand = new LiveCommand(server) server.servicesCommand = new ServicesCommand(server) server.blacklistCommand = new BlacklistCommand(server) + server.captionsCommand = new CaptionsCommand(server) res(server) }) -- cgit v1.2.3 From 72cbfc5695ec5ebdb9721d3648218f63feeaeac5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 13:56:04 +0200 Subject: Introduce change ownership command --- shared/extra-utils/server/servers.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'shared/extra-utils/server') 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' import { SearchCommand } from '../search' import { SocketIOCommand } from '../socket' import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users' -import { LiveCommand, ServicesCommand, BlacklistCommand, CaptionsCommand } from '../videos' +import { BlacklistCommand, CaptionsCommand, ChangeOwnershipCommand, LiveCommand, ServicesCommand } from '../videos' import { ConfigCommand } from './config-command' import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' @@ -104,6 +104,7 @@ interface ServerInfo { servicesCommand?: ServicesCommand blacklistCommand?: BlacklistCommand captionsCommand?: CaptionsCommand + changeOwnershipCommand?: ChangeOwnershipCommand } function parallelTests () { @@ -333,6 +334,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.servicesCommand = new ServicesCommand(server) server.blacklistCommand = new BlacklistCommand(server) server.captionsCommand = new CaptionsCommand(server) + server.changeOwnershipCommand = new ChangeOwnershipCommand(server) res(server) }) -- cgit v1.2.3 From e6346d59e63135cf012ed18c102d3b0179ef565f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 15:54:39 +0200 Subject: Introduce playlist command --- shared/extra-utils/server/servers.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 33f558414..78b3be9c7 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 { BlacklistCommand, CaptionsCommand, ChangeOwnershipCommand, LiveCommand, ServicesCommand } from '../videos' +import { BlacklistCommand, CaptionsCommand, ChangeOwnershipCommand, LiveCommand, PlaylistsCommand, ServicesCommand } from '../videos' import { ConfigCommand } from './config-command' import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' @@ -105,6 +105,7 @@ interface ServerInfo { blacklistCommand?: BlacklistCommand captionsCommand?: CaptionsCommand changeOwnershipCommand?: ChangeOwnershipCommand + playlistsCommand?: PlaylistsCommand } function parallelTests () { @@ -335,6 +336,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.blacklistCommand = new BlacklistCommand(server) server.captionsCommand = new CaptionsCommand(server) server.changeOwnershipCommand = new ChangeOwnershipCommand(server) + server.playlistsCommand = new PlaylistsCommand(server) res(server) }) -- cgit v1.2.3 From 313228e9c3b5bcef5391228c9b949d05d32ad7bb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 16:21:42 +0200 Subject: Introduce history command --- shared/extra-utils/server/servers.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 78b3be9c7..bd5c29e51 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 { BlacklistCommand, CaptionsCommand, ChangeOwnershipCommand, LiveCommand, PlaylistsCommand, ServicesCommand } from '../videos' +import { BlacklistCommand, CaptionsCommand, ChangeOwnershipCommand, HistoryCommand, LiveCommand, PlaylistsCommand, ServicesCommand } from '../videos' import { ConfigCommand } from './config-command' import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' @@ -106,6 +106,7 @@ interface ServerInfo { captionsCommand?: CaptionsCommand changeOwnershipCommand?: ChangeOwnershipCommand playlistsCommand?: PlaylistsCommand + historyCommand?: HistoryCommand } function parallelTests () { @@ -337,6 +338,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.captionsCommand = new CaptionsCommand(server) server.changeOwnershipCommand = new ChangeOwnershipCommand(server) server.playlistsCommand = new PlaylistsCommand(server) + server.historyCommand = new HistoryCommand(server) res(server) }) -- cgit v1.2.3 From 6910f20f114b5bd020258a3a9a3f2117819a60c2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 16:49:51 +0200 Subject: Introduce import command --- shared/extra-utils/server/servers.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index bd5c29e51..95c876110 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -18,7 +18,16 @@ import { makeGetRequest } from '../requests/requests' import { SearchCommand } from '../search' import { SocketIOCommand } from '../socket' import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users' -import { BlacklistCommand, CaptionsCommand, ChangeOwnershipCommand, HistoryCommand, LiveCommand, PlaylistsCommand, ServicesCommand } from '../videos' +import { + BlacklistCommand, + CaptionsCommand, + ChangeOwnershipCommand, + HistoryCommand, + ImportsCommand, + LiveCommand, + PlaylistsCommand, + ServicesCommand +} from '../videos' import { ConfigCommand } from './config-command' import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' @@ -107,6 +116,7 @@ interface ServerInfo { changeOwnershipCommand?: ChangeOwnershipCommand playlistsCommand?: PlaylistsCommand historyCommand?: HistoryCommand + importsCommand?: ImportsCommand } function parallelTests () { @@ -339,6 +349,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.changeOwnershipCommand = new ChangeOwnershipCommand(server) server.playlistsCommand = new PlaylistsCommand(server) server.historyCommand = new HistoryCommand(server) + server.importsCommand = new ImportsCommand(server) res(server) }) -- cgit v1.2.3 From 57f879a540551c3b958b0991c8e1e3657a4481d8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 10:21:10 +0200 Subject: Introduce streaming playlists command --- shared/extra-utils/server/servers.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 95c876110..6a1dadbcc 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -26,7 +26,8 @@ import { ImportsCommand, LiveCommand, PlaylistsCommand, - ServicesCommand + ServicesCommand, + StreamingPlaylistsCommand } from '../videos' import { ConfigCommand } from './config-command' import { ContactFormCommand } from './contact-form-command' @@ -117,6 +118,7 @@ interface ServerInfo { playlistsCommand?: PlaylistsCommand historyCommand?: HistoryCommand importsCommand?: ImportsCommand + streamingPlaylistsCommand?: StreamingPlaylistsCommand } function parallelTests () { @@ -350,6 +352,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.playlistsCommand = new PlaylistsCommand(server) server.historyCommand = new HistoryCommand(server) server.importsCommand = new ImportsCommand(server) + server.streamingPlaylistsCommand = new StreamingPlaylistsCommand(server) res(server) }) -- cgit v1.2.3 From a54618880c394ad7571f3f3222dc96ec2dd10d9a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 11:21:30 +0200 Subject: Introduce channels command --- shared/extra-utils/server/servers.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 6a1dadbcc..68e10af5f 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -22,6 +22,7 @@ import { BlacklistCommand, CaptionsCommand, ChangeOwnershipCommand, + ChannelsCommand, HistoryCommand, ImportsCommand, LiveCommand, @@ -119,6 +120,7 @@ interface ServerInfo { historyCommand?: HistoryCommand importsCommand?: ImportsCommand streamingPlaylistsCommand?: StreamingPlaylistsCommand + channelsCommand?: ChannelsCommand } function parallelTests () { @@ -353,6 +355,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.historyCommand = new HistoryCommand(server) server.importsCommand = new ImportsCommand(server) server.streamingPlaylistsCommand = new StreamingPlaylistsCommand(server) + server.channelsCommand = new ChannelsCommand(server) res(server) }) -- cgit v1.2.3 From 12edc1495a36b2199f1bf1ba37f50c7b694be382 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 14:15:11 +0200 Subject: Introduce comments command --- shared/extra-utils/server/servers.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 68e10af5f..8e80a9842 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -30,6 +30,7 @@ import { ServicesCommand, StreamingPlaylistsCommand } from '../videos' +import { CommentsCommand } from '../videos/comments-command' import { ConfigCommand } from './config-command' import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' @@ -121,6 +122,7 @@ interface ServerInfo { importsCommand?: ImportsCommand streamingPlaylistsCommand?: StreamingPlaylistsCommand channelsCommand?: ChannelsCommand + commentsCommand?: CommentsCommand } function parallelTests () { @@ -356,6 +358,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.importsCommand = new ImportsCommand(server) server.streamingPlaylistsCommand = new StreamingPlaylistsCommand(server) server.channelsCommand = new ChannelsCommand(server) + server.commentsCommand = new CommentsCommand(server) res(server) }) -- cgit v1.2.3 From 078f17e6d90376050f43ce639e88e11869b49ee7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 15:03:44 +0200 Subject: Fix CLI tools --- shared/extra-utils/server/servers.ts | 89 +++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 42 deletions(-) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 8e80a9842..41b48a8ee 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -41,25 +41,25 @@ import { RedundancyCommand } from './redundancy-command' import { StatsCommand } from './stats-command' interface ServerInfo { - app: ChildProcess + app?: ChildProcess url: string - host: string - hostname: string - port: number + host?: string + hostname?: string + port?: number - rtmpPort: number + rtmpPort?: number - parallel: boolean + parallel?: boolean internalServerNumber: number - serverNumber: number + serverNumber?: number - client: { - id: string - secret: string + client?: { + id?: string + secret?: string } - user: { + user?: { username: string password: string email?: string @@ -328,43 +328,47 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] } catch { /* empty */ } }) - server.bulkCommand = new BulkCommand(server) - server.cliCommand = new CLICommand(server) - server.customPageCommand = new CustomPagesCommand(server) - server.feedCommand = new FeedCommand(server) - server.logsCommand = new LogsCommand(server) - server.abusesCommand = new AbusesCommand(server) - server.overviewsCommand = new OverviewsCommand(server) - server.searchCommand = new SearchCommand(server) - server.contactFormCommand = new ContactFormCommand(server) - server.debugCommand = new DebugCommand(server) - server.followsCommand = new FollowsCommand(server) - server.jobsCommand = new JobsCommand(server) - server.pluginsCommand = new PluginsCommand(server) - server.redundancyCommand = new RedundancyCommand(server) - server.statsCommand = new StatsCommand(server) - server.configCommand = new ConfigCommand(server) - server.socketIOCommand = new SocketIOCommand(server) - server.accountsCommand = new AccountsCommand(server) - server.blocklistCommand = new BlocklistCommand(server) - server.subscriptionsCommand = new SubscriptionsCommand(server) - server.liveCommand = new LiveCommand(server) - server.servicesCommand = new ServicesCommand(server) - server.blacklistCommand = new BlacklistCommand(server) - server.captionsCommand = new CaptionsCommand(server) - server.changeOwnershipCommand = new ChangeOwnershipCommand(server) - server.playlistsCommand = new PlaylistsCommand(server) - server.historyCommand = new HistoryCommand(server) - server.importsCommand = new ImportsCommand(server) - server.streamingPlaylistsCommand = new StreamingPlaylistsCommand(server) - server.channelsCommand = new ChannelsCommand(server) - server.commentsCommand = new CommentsCommand(server) + assignCommands(server) res(server) }) }) } +function assignCommands (server: ServerInfo) { + server.bulkCommand = new BulkCommand(server) + server.cliCommand = new CLICommand(server) + server.customPageCommand = new CustomPagesCommand(server) + server.feedCommand = new FeedCommand(server) + server.logsCommand = new LogsCommand(server) + server.abusesCommand = new AbusesCommand(server) + server.overviewsCommand = new OverviewsCommand(server) + server.searchCommand = new SearchCommand(server) + server.contactFormCommand = new ContactFormCommand(server) + server.debugCommand = new DebugCommand(server) + server.followsCommand = new FollowsCommand(server) + server.jobsCommand = new JobsCommand(server) + server.pluginsCommand = new PluginsCommand(server) + server.redundancyCommand = new RedundancyCommand(server) + server.statsCommand = new StatsCommand(server) + server.configCommand = new ConfigCommand(server) + server.socketIOCommand = new SocketIOCommand(server) + server.accountsCommand = new AccountsCommand(server) + server.blocklistCommand = new BlocklistCommand(server) + server.subscriptionsCommand = new SubscriptionsCommand(server) + server.liveCommand = new LiveCommand(server) + server.servicesCommand = new ServicesCommand(server) + server.blacklistCommand = new BlacklistCommand(server) + server.captionsCommand = new CaptionsCommand(server) + server.changeOwnershipCommand = new ChangeOwnershipCommand(server) + server.playlistsCommand = new PlaylistsCommand(server) + server.historyCommand = new HistoryCommand(server) + server.importsCommand = new ImportsCommand(server) + server.streamingPlaylistsCommand = new StreamingPlaylistsCommand(server) + server.channelsCommand = new ChannelsCommand(server) + server.commentsCommand = new CommentsCommand(server) +} + async function reRunServer (server: ServerInfo, configOverride?: any) { const newServer = await runServer(server, configOverride) server.app = newServer.app @@ -475,5 +479,6 @@ export { flushAndRunServer, killallServers, reRunServer, + assignCommands, waitUntilLog } -- cgit v1.2.3 From 9293139fde7091e9badcafa9b570b83cea9a10ad Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 15:37:43 +0200 Subject: Introduce sql command --- shared/extra-utils/server/servers.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 41b48a8ee..bd3be8373 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -30,6 +30,7 @@ import { ServicesCommand, StreamingPlaylistsCommand } from '../videos' +import { SQLCommand } from '../miscs' import { CommentsCommand } from '../videos/comments-command' import { ConfigCommand } from './config-command' import { ContactFormCommand } from './contact-form-command' @@ -123,6 +124,7 @@ interface ServerInfo { streamingPlaylistsCommand?: StreamingPlaylistsCommand channelsCommand?: ChannelsCommand commentsCommand?: CommentsCommand + sqlCommand?: SQLCommand } function parallelTests () { @@ -367,6 +369,7 @@ function assignCommands (server: ServerInfo) { server.streamingPlaylistsCommand = new StreamingPlaylistsCommand(server) server.channelsCommand = new ChannelsCommand(server) server.commentsCommand = new CommentsCommand(server) + server.sqlCommand = new SQLCommand(server) } async function reRunServer (server: ServerInfo, configOverride?: any) { @@ -398,17 +401,20 @@ async function checkDirectoryIsEmpty (server: ServerInfo, directory: string, exc expect(filtered).to.have.lengthOf(0) } -function killallServers (servers: ServerInfo[]) { +async function killallServers (servers: ServerInfo[]) { for (const server of servers) { if (!server.app) continue + await server.sqlCommand.cleanup() + process.kill(-server.app.pid) + server.app = null } } async function cleanupTests (servers: ServerInfo[]) { - killallServers(servers) + await killallServers(servers) if (isGithubCI()) { await ensureDir('artifacts') -- cgit v1.2.3 From dd0ebb715123dfa126a82d4e4fe3a04064ae77b8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 16:23:01 +0200 Subject: Introduce notifications command --- shared/extra-utils/server/servers.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index bd3be8373..e0e49d2c4 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -11,13 +11,14 @@ import { CLICommand } from '../cli' import { CustomPagesCommand } from '../custom-pages' import { FeedCommand } from '../feeds' import { LogsCommand } from '../logs' +import { SQLCommand } from '../miscs' import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs' import { AbusesCommand } from '../moderation' import { OverviewsCommand } from '../overviews' import { makeGetRequest } from '../requests/requests' import { SearchCommand } from '../search' import { SocketIOCommand } from '../socket' -import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users' +import { AccountsCommand, BlocklistCommand, NotificationsCommand, SubscriptionsCommand } from '../users' import { BlacklistCommand, CaptionsCommand, @@ -30,7 +31,6 @@ import { ServicesCommand, StreamingPlaylistsCommand } from '../videos' -import { SQLCommand } from '../miscs' import { CommentsCommand } from '../videos/comments-command' import { ConfigCommand } from './config-command' import { ContactFormCommand } from './contact-form-command' @@ -125,6 +125,7 @@ interface ServerInfo { channelsCommand?: ChannelsCommand commentsCommand?: CommentsCommand sqlCommand?: SQLCommand + notificationsCommand?: NotificationsCommand } function parallelTests () { @@ -370,6 +371,7 @@ function assignCommands (server: ServerInfo) { server.channelsCommand = new ChannelsCommand(server) server.commentsCommand = new CommentsCommand(server) server.sqlCommand = new SQLCommand(server) + server.notificationsCommand = new NotificationsCommand(server) } async function reRunServer (server: ServerInfo, configOverride?: any) { -- cgit v1.2.3 From 6c5065a011b099618681a37bd77eaa7bd3db752e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 09:43:59 +0200 Subject: Introduce server commands --- shared/extra-utils/server/directories.ts | 34 +++++++++ shared/extra-utils/server/index.ts | 2 + shared/extra-utils/server/jobs.ts | 2 +- shared/extra-utils/server/plugins-command.ts | 3 +- shared/extra-utils/server/servers-command.ts | 81 ++++++++++++++++++++ shared/extra-utils/server/servers.ts | 108 +++------------------------ 6 files changed, 130 insertions(+), 100 deletions(-) create mode 100644 shared/extra-utils/server/directories.ts create mode 100644 shared/extra-utils/server/servers-command.ts (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/directories.ts b/shared/extra-utils/server/directories.ts new file mode 100644 index 000000000..3cd38a561 --- /dev/null +++ b/shared/extra-utils/server/directories.ts @@ -0,0 +1,34 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import { expect } from 'chai' +import { pathExists, readdir } from 'fs-extra' +import { join } from 'path' +import { root } from '@server/helpers/core-utils' +import { ServerInfo } from './servers' + +async function checkTmpIsEmpty (server: ServerInfo) { + await checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css', 'hls', 'resumable-uploads' ]) + + if (await pathExists(join('test' + server.internalServerNumber, 'tmp', 'hls'))) { + await checkDirectoryIsEmpty(server, 'tmp/hls') + } +} + +async function checkDirectoryIsEmpty (server: ServerInfo, directory: string, exceptions: string[] = []) { + const testDirectory = 'test' + server.internalServerNumber + + const directoryPath = join(root(), testDirectory, directory) + + const directoryExists = await pathExists(directoryPath) + expect(directoryExists).to.be.true + + const files = await readdir(directoryPath) + const filtered = files.filter(f => exceptions.includes(f) === false) + + expect(filtered).to.have.lengthOf(0) +} + +export { + checkTmpIsEmpty, + checkDirectoryIsEmpty +} diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts index 03c3b0123..669b004cd 100644 --- a/shared/extra-utils/server/index.ts +++ b/shared/extra-utils/server/index.ts @@ -1,6 +1,7 @@ export * from './config-command' export * from './contact-form-command' export * from './debug-command' +export * from './directories' export * from './follows-command' export * from './follows' export * from './jobs' @@ -8,5 +9,6 @@ export * from './jobs-command' export * from './plugins-command' export * from './plugins' export * from './redundancy-command' +export * from './servers-command' export * from './servers' export * from './stats-command' diff --git a/shared/extra-utils/server/jobs.ts b/shared/extra-utils/server/jobs.ts index b4b3d52e7..36ef882b3 100644 --- a/shared/extra-utils/server/jobs.ts +++ b/shared/extra-utils/server/jobs.ts @@ -1,6 +1,6 @@ import { JobState } from '../../models' -import { wait } from '../miscs/miscs' +import { wait } from '../miscs' import { ServerInfo } from './servers' async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { diff --git a/shared/extra-utils/server/plugins-command.ts b/shared/extra-utils/server/plugins-command.ts index ff49d58c4..5bed51d1a 100644 --- a/shared/extra-utils/server/plugins-command.ts +++ b/shared/extra-utils/server/plugins-command.ts @@ -15,7 +15,6 @@ import { RegisteredServerSettings, ResultList } from '@shared/models' -import { buildServerDirectory } from '../miscs' import { AbstractCommand, OverrideCommandOptions } from '../shared' export class PluginsCommand extends AbstractCommand { @@ -252,6 +251,6 @@ export class PluginsCommand extends AbstractCommand { } private getPackageJSONPath (npmName: string) { - return buildServerDirectory(this.server, join('plugins', 'node_modules', npmName, 'package.json')) + return this.server.serversCommand.buildDirectory(join('plugins', 'node_modules', npmName, 'package.json')) } } diff --git a/shared/extra-utils/server/servers-command.ts b/shared/extra-utils/server/servers-command.ts new file mode 100644 index 000000000..9ef68fede --- /dev/null +++ b/shared/extra-utils/server/servers-command.ts @@ -0,0 +1,81 @@ +import { exec } from 'child_process' +import { copy, ensureDir, readFile, remove } from 'fs-extra' +import { join } from 'path' +import { root } from '@server/helpers/core-utils' +import { HttpStatusCode } from '@shared/core-utils' +import { getFileSize } from '@uploadx/core' +import { isGithubCI, wait } from '../miscs' +import { AbstractCommand, OverrideCommandOptions } from '../shared' + +export class ServersCommand extends AbstractCommand { + + static flushTests (internalServerNumber: number) { + return new Promise((res, rej) => { + const suffix = ` -- ${internalServerNumber}` + + return exec('npm run clean:server:test' + suffix, (err, _stdout, stderr) => { + if (err || stderr) return rej(err || new Error(stderr)) + + return res() + }) + }) + } + + ping (options: OverrideCommandOptions = {}) { + return this.getRequestBody({ + ...options, + + path: '/api/v1/ping', + implicitToken: false, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + async cleanupTests () { + const p: Promise[] = [] + + if (isGithubCI()) { + await ensureDir('artifacts') + + const origin = this.server.serversCommand.buildDirectory('logs/peertube.log') + const destname = `peertube-${this.server.internalServerNumber}.log` + console.log('Saving logs %s.', destname) + + await copy(origin, join('artifacts', destname)) + } + + if (this.server.parallel) { + p.push(ServersCommand.flushTests(this.server.internalServerNumber)) + } + + if (this.server.customConfigFile) { + p.push(remove(this.server.customConfigFile)) + } + + return p + } + + async waitUntilLog (str: string, count = 1, strictCount = true) { + const logfile = this.server.serversCommand.buildDirectory('logs/peertube.log') + + while (true) { + const buf = await readFile(logfile) + + const matches = buf.toString().match(new RegExp(str, 'g')) + if (matches && matches.length === count) return + if (matches && strictCount === false && matches.length >= count) return + + await wait(1000) + } + } + + buildDirectory (directory: string) { + return join(root(), 'test' + this.server.internalServerNumber, directory) + } + + async getServerFileSize (subPath: string) { + const path = this.server.serversCommand.buildDirectory(subPath) + + return getFileSize(path) + } +} diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index e0e49d2c4..f5dc0326f 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ -import { expect } from 'chai' -import { ChildProcess, exec, fork } from 'child_process' -import { copy, ensureDir, pathExists, readdir, readFile, remove } from 'fs-extra' +import { ChildProcess, fork } from 'child_process' +import { copy, ensureDir } from 'fs-extra' import { join } from 'path' +import { root } from '@server/helpers/core-utils' import { randomInt } from '../../core-utils/miscs/miscs' import { VideoChannel } from '../../models/videos' import { BulkCommand } from '../bulk' @@ -11,11 +11,9 @@ import { CLICommand } from '../cli' import { CustomPagesCommand } from '../custom-pages' import { FeedCommand } from '../feeds' import { LogsCommand } from '../logs' -import { SQLCommand } from '../miscs' -import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs' +import { isGithubCI, parallelTests, SQLCommand } from '../miscs' import { AbusesCommand } from '../moderation' import { OverviewsCommand } from '../overviews' -import { makeGetRequest } from '../requests/requests' import { SearchCommand } from '../search' import { SocketIOCommand } from '../socket' import { AccountsCommand, BlocklistCommand, NotificationsCommand, SubscriptionsCommand } from '../users' @@ -39,6 +37,7 @@ import { FollowsCommand } from './follows-command' import { JobsCommand } from './jobs-command' import { PluginsCommand } from './plugins-command' import { RedundancyCommand } from './redundancy-command' +import { ServersCommand } from './servers-command' import { StatsCommand } from './stats-command' interface ServerInfo { @@ -126,10 +125,7 @@ interface ServerInfo { commentsCommand?: CommentsCommand sqlCommand?: SQLCommand notificationsCommand?: NotificationsCommand -} - -function parallelTests () { - return process.env.MOCHA_PARALLEL === 'true' + serversCommand?: ServersCommand } function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) { @@ -151,18 +147,6 @@ function flushAndRunMultipleServers (totalServers: number, configOverride?: Obje }) } -function flushTests (serverNumber?: number) { - return new Promise((res, rej) => { - const suffix = serverNumber ? ` -- ${serverNumber}` : '' - - return exec('npm run clean:server:test' + suffix, (err, _stdout, stderr) => { - if (err || stderr) return rej(err || new Error(stderr)) - - return res() - }) - }) -} - function randomServer () { const low = 10 const high = 10000 @@ -189,7 +173,7 @@ async function flushAndRunServer (serverNumber: number, configOverride?: Object, const rtmpPort = parallel ? randomRTMP() : 1936 const port = 9000 + internalServerNumber - await flushTests(internalServerNumber) + await ServersCommand.flushTests(internalServerNumber) const server: ServerInfo = { app: null, @@ -372,6 +356,7 @@ function assignCommands (server: ServerInfo) { server.commentsCommand = new CommentsCommand(server) server.sqlCommand = new SQLCommand(server) server.notificationsCommand = new NotificationsCommand(server) + server.serversCommand = new ServersCommand(server) } async function reRunServer (server: ServerInfo, configOverride?: any) { @@ -381,28 +366,6 @@ async function reRunServer (server: ServerInfo, configOverride?: any) { return server } -async function checkTmpIsEmpty (server: ServerInfo) { - await checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css', 'hls', 'resumable-uploads' ]) - - if (await pathExists(join('test' + server.internalServerNumber, 'tmp', 'hls'))) { - await checkDirectoryIsEmpty(server, 'tmp/hls') - } -} - -async function checkDirectoryIsEmpty (server: ServerInfo, directory: string, exceptions: string[] = []) { - const testDirectory = 'test' + server.internalServerNumber - - const directoryPath = join(root(), testDirectory, directory) - - const directoryExists = await pathExists(directoryPath) - expect(directoryExists).to.be.true - - const files = await readdir(directoryPath) - const filtered = files.filter(f => exceptions.includes(f) === false) - - expect(filtered).to.have.lengthOf(0) -} - async function killallServers (servers: ServerInfo[]) { for (const server of servers) { if (!server.app) continue @@ -422,71 +385,22 @@ async function cleanupTests (servers: ServerInfo[]) { await ensureDir('artifacts') } - const p: Promise[] = [] + let p: Promise[] = [] for (const server of servers) { - if (isGithubCI()) { - const origin = await buildServerDirectory(server, 'logs/peertube.log') - const destname = `peertube-${server.internalServerNumber}.log` - console.log('Saving logs %s.', destname) - - await copy(origin, join('artifacts', destname)) - } - - if (server.parallel) { - p.push(flushTests(server.internalServerNumber)) - } - - if (server.customConfigFile) { - p.push(remove(server.customConfigFile)) - } + p = p.concat(server.serversCommand.cleanupTests()) } return Promise.all(p) } -async function waitUntilLog (server: ServerInfo, str: string, count = 1, strictCount = true) { - const logfile = buildServerDirectory(server, 'logs/peertube.log') - - while (true) { - const buf = await readFile(logfile) - - const matches = buf.toString().match(new RegExp(str, 'g')) - if (matches && matches.length === count) return - if (matches && strictCount === false && matches.length >= count) return - - await wait(1000) - } -} - -async function getServerFileSize (server: ServerInfo, subPath: string) { - const path = buildServerDirectory(server, subPath) - - return getFileSize(path) -} - -function makePingRequest (server: ServerInfo) { - return makeGetRequest({ - url: server.url, - path: '/api/v1/ping', - statusCodeExpected: 200 - }) -} - // --------------------------------------------------------------------------- export { - checkDirectoryIsEmpty, - checkTmpIsEmpty, - getServerFileSize, ServerInfo, - parallelTests, cleanupTests, flushAndRunMultipleServers, - flushTests, - makePingRequest, flushAndRunServer, killallServers, reRunServer, - assignCommands, - waitUntilLog + assignCommands } -- cgit v1.2.3 From 41d1d075011174e73dccb74006181a92a618d7b4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 11:05:15 +0200 Subject: Introduce login command --- shared/extra-utils/server/clients.ts | 20 -------------------- shared/extra-utils/server/servers.ts | 4 +++- 2 files changed, 3 insertions(+), 21 deletions(-) delete mode 100644 shared/extra-utils/server/clients.ts (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/clients.ts b/shared/extra-utils/server/clients.ts deleted file mode 100644 index 894fe4911..000000000 --- a/shared/extra-utils/server/clients.ts +++ /dev/null @@ -1,20 +0,0 @@ -import * as request from 'supertest' -import { URL } from 'url' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' - -function getClient (url: string) { - const path = '/api/v1/oauth-clients/local' - - return request(url) - .get(path) - .set('Host', new URL(url).host) - .set('Accept', 'application/json') - .expect(HttpStatusCode.OK_200) - .expect('Content-Type', /json/) -} - -// --------------------------------------------------------------------------- - -export { - getClient -} diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index f5dc0326f..4d9599680 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -16,7 +16,7 @@ import { AbusesCommand } from '../moderation' import { OverviewsCommand } from '../overviews' import { SearchCommand } from '../search' import { SocketIOCommand } from '../socket' -import { AccountsCommand, BlocklistCommand, NotificationsCommand, SubscriptionsCommand } from '../users' +import { AccountsCommand, BlocklistCommand, LoginCommand, NotificationsCommand, SubscriptionsCommand } from '../users' import { BlacklistCommand, CaptionsCommand, @@ -126,6 +126,7 @@ interface ServerInfo { sqlCommand?: SQLCommand notificationsCommand?: NotificationsCommand serversCommand?: ServersCommand + loginCommand?: LoginCommand } function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) { @@ -357,6 +358,7 @@ function assignCommands (server: ServerInfo) { server.sqlCommand = new SQLCommand(server) server.notificationsCommand = new NotificationsCommand(server) server.serversCommand = new ServersCommand(server) + server.loginCommand = new LoginCommand(server) } async function reRunServer (server: ServerInfo, configOverride?: any) { -- cgit v1.2.3 From 7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 14:23:01 +0200 Subject: Introduce user command --- shared/extra-utils/server/servers.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 4d9599680..b6d597c5d 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -16,7 +16,7 @@ import { AbusesCommand } from '../moderation' import { OverviewsCommand } from '../overviews' import { SearchCommand } from '../search' import { SocketIOCommand } from '../socket' -import { AccountsCommand, BlocklistCommand, LoginCommand, NotificationsCommand, SubscriptionsCommand } from '../users' +import { AccountsCommand, BlocklistCommand, LoginCommand, NotificationsCommand, SubscriptionsCommand, UsersCommand } from '../users' import { BlacklistCommand, CaptionsCommand, @@ -127,6 +127,7 @@ interface ServerInfo { notificationsCommand?: NotificationsCommand serversCommand?: ServersCommand loginCommand?: LoginCommand + usersCommand?: UsersCommand } function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) { @@ -359,6 +360,7 @@ function assignCommands (server: ServerInfo) { server.notificationsCommand = new NotificationsCommand(server) server.serversCommand = new ServersCommand(server) server.loginCommand = new LoginCommand(server) + server.usersCommand = new UsersCommand(server) } async function reRunServer (server: ServerInfo, configOverride?: any) { -- cgit v1.2.3 From d23dd9fbfc4d26026352c10f81d2795ceaf2908a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Jul 2021 10:02:54 +0200 Subject: Introduce videos command --- shared/extra-utils/server/servers.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index b6d597c5d..fda5c3d6d 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -27,7 +27,8 @@ import { LiveCommand, PlaylistsCommand, ServicesCommand, - StreamingPlaylistsCommand + StreamingPlaylistsCommand, + VideosCommand } from '../videos' import { CommentsCommand } from '../videos/comments-command' import { ConfigCommand } from './config-command' @@ -128,6 +129,7 @@ interface ServerInfo { serversCommand?: ServersCommand loginCommand?: LoginCommand usersCommand?: UsersCommand + videosCommand?: VideosCommand } function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) { @@ -361,6 +363,7 @@ function assignCommands (server: ServerInfo) { server.serversCommand = new ServersCommand(server) server.loginCommand = new LoginCommand(server) server.usersCommand = new UsersCommand(server) + server.videosCommand = new VideosCommand(server) } async function reRunServer (server: ServerInfo, configOverride?: any) { -- cgit v1.2.3 From 89d241a79c262b9775c233b73cff080043ebb5e6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 09:04:35 +0200 Subject: Shorter server command names --- shared/extra-utils/server/follows.ts | 4 +- shared/extra-utils/server/jobs.ts | 4 +- shared/extra-utils/server/plugins-command.ts | 2 +- shared/extra-utils/server/plugins.ts | 2 +- shared/extra-utils/server/servers-command.ts | 6 +- shared/extra-utils/server/servers.ts | 230 +++++++++++++-------------- 6 files changed, 124 insertions(+), 124 deletions(-) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/follows.ts b/shared/extra-utils/server/follows.ts index c23cebd81..50ae898cc 100644 --- a/shared/extra-utils/server/follows.ts +++ b/shared/extra-utils/server/follows.ts @@ -3,8 +3,8 @@ import { ServerInfo } from './servers' async function doubleFollow (server1: ServerInfo, server2: ServerInfo) { await Promise.all([ - server1.followsCommand.follow({ targets: [ server2.url ] }), - server2.followsCommand.follow({ targets: [ server1.url ] }) + server1.follows.follow({ targets: [ server2.url ] }), + server2.follows.follow({ targets: [ server1.url ] }) ]) // Wait request propagation diff --git a/shared/extra-utils/server/jobs.ts b/shared/extra-utils/server/jobs.ts index 36ef882b3..754530977 100644 --- a/shared/extra-utils/server/jobs.ts +++ b/shared/extra-utils/server/jobs.ts @@ -23,7 +23,7 @@ async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { // Check if each server has pending request for (const server of servers) { for (const state of states) { - const p = server.jobsCommand.getJobsList({ + const p = server.jobs.getJobsList({ state, start: 0, count: 10, @@ -39,7 +39,7 @@ async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { tasks.push(p) } - const p = server.debugCommand.getDebug() + const p = server.debug.getDebug() .then(obj => { if (obj.activityPubMessagesWaiting !== 0) { pendingRequests = true diff --git a/shared/extra-utils/server/plugins-command.ts b/shared/extra-utils/server/plugins-command.ts index 5bed51d1a..98049ce19 100644 --- a/shared/extra-utils/server/plugins-command.ts +++ b/shared/extra-utils/server/plugins-command.ts @@ -251,6 +251,6 @@ export class PluginsCommand extends AbstractCommand { } private getPackageJSONPath (npmName: string) { - return this.server.serversCommand.buildDirectory(join('plugins', 'node_modules', npmName, 'package.json')) + return this.server.servers.buildDirectory(join('plugins', 'node_modules', npmName, 'package.json')) } } diff --git a/shared/extra-utils/server/plugins.ts b/shared/extra-utils/server/plugins.ts index 1084ea4f4..d1cc7e383 100644 --- a/shared/extra-utils/server/plugins.ts +++ b/shared/extra-utils/server/plugins.ts @@ -4,7 +4,7 @@ import { expect } from 'chai' import { ServerInfo } from '../server/servers' async function testHelloWorldRegisteredSettings (server: ServerInfo) { - const body = await server.pluginsCommand.getRegisteredSettings({ npmName: 'peertube-plugin-hello-world' }) + const body = await server.plugins.getRegisteredSettings({ npmName: 'peertube-plugin-hello-world' }) const registeredSettings = body.registeredSettings expect(registeredSettings).to.have.length.at.least(1) diff --git a/shared/extra-utils/server/servers-command.ts b/shared/extra-utils/server/servers-command.ts index 9ef68fede..a7c5a868d 100644 --- a/shared/extra-utils/server/servers-command.ts +++ b/shared/extra-utils/server/servers-command.ts @@ -37,7 +37,7 @@ export class ServersCommand extends AbstractCommand { if (isGithubCI()) { await ensureDir('artifacts') - const origin = this.server.serversCommand.buildDirectory('logs/peertube.log') + const origin = this.server.servers.buildDirectory('logs/peertube.log') const destname = `peertube-${this.server.internalServerNumber}.log` console.log('Saving logs %s.', destname) @@ -56,7 +56,7 @@ export class ServersCommand extends AbstractCommand { } async waitUntilLog (str: string, count = 1, strictCount = true) { - const logfile = this.server.serversCommand.buildDirectory('logs/peertube.log') + const logfile = this.server.servers.buildDirectory('logs/peertube.log') while (true) { const buf = await readFile(logfile) @@ -74,7 +74,7 @@ export class ServersCommand extends AbstractCommand { } async getServerFileSize (subPath: string) { - const path = this.server.serversCommand.buildDirectory(subPath) + const path = this.server.servers.buildDirectory(subPath) return getFileSize(path) } diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index fda5c3d6d..ea3f19a92 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -53,83 +53,81 @@ interface ServerInfo { parallel?: boolean internalServerNumber: number + serverNumber?: number + customConfigFile?: string - client?: { - id?: string - secret?: string - } + store?: { + client?: { + id?: string + secret?: string + } - user?: { - username: string - password: string - email?: string - } + user?: { + username: string + password: string + email?: string + } - customConfigFile?: string + channel?: VideoChannel - accessToken?: string - refreshToken?: string - videoChannel?: VideoChannel + video?: { + id: number + uuid: string + shortUUID: string + name?: string + url?: string - video?: { - id: number - uuid: string - shortUUID: string - name?: string - url?: string + account?: { + name: string + } - account?: { - name: string + embedPath?: string } - embedPath?: string + videos?: { id: number, uuid: string }[] } - remoteVideo?: { - id: number - uuid: string - } + accessToken?: string + refreshToken?: string - videos?: { id: number, uuid: string }[] - - bulkCommand?: BulkCommand - cliCommand?: CLICommand - customPageCommand?: CustomPagesCommand - feedCommand?: FeedCommand - logsCommand?: LogsCommand - abusesCommand?: AbusesCommand - overviewsCommand?: OverviewsCommand - searchCommand?: SearchCommand - contactFormCommand?: ContactFormCommand - debugCommand?: DebugCommand - followsCommand?: FollowsCommand - jobsCommand?: JobsCommand - pluginsCommand?: PluginsCommand - redundancyCommand?: RedundancyCommand - statsCommand?: StatsCommand - configCommand?: ConfigCommand - socketIOCommand?: SocketIOCommand - accountsCommand?: AccountsCommand - blocklistCommand?: BlocklistCommand - subscriptionsCommand?: SubscriptionsCommand - liveCommand?: LiveCommand - servicesCommand?: ServicesCommand - blacklistCommand?: BlacklistCommand - captionsCommand?: CaptionsCommand - changeOwnershipCommand?: ChangeOwnershipCommand - playlistsCommand?: PlaylistsCommand - historyCommand?: HistoryCommand - importsCommand?: ImportsCommand - streamingPlaylistsCommand?: StreamingPlaylistsCommand - channelsCommand?: ChannelsCommand - commentsCommand?: CommentsCommand - sqlCommand?: SQLCommand - notificationsCommand?: NotificationsCommand - serversCommand?: ServersCommand - loginCommand?: LoginCommand - usersCommand?: UsersCommand - videosCommand?: VideosCommand + bulk?: BulkCommand + cli?: CLICommand + customPage?: CustomPagesCommand + feed?: FeedCommand + logs?: LogsCommand + abuses?: AbusesCommand + overviews?: OverviewsCommand + search?: SearchCommand + contactForm?: ContactFormCommand + debug?: DebugCommand + follows?: FollowsCommand + jobs?: JobsCommand + plugins?: PluginsCommand + redundancy?: RedundancyCommand + stats?: StatsCommand + config?: ConfigCommand + socketIO?: SocketIOCommand + accounts?: AccountsCommand + blocklist?: BlocklistCommand + subscriptions?: SubscriptionsCommand + live?: LiveCommand + services?: ServicesCommand + blacklist?: BlacklistCommand + captions?: CaptionsCommand + changeOwnership?: ChangeOwnershipCommand + playlists?: PlaylistsCommand + history?: HistoryCommand + imports?: ImportsCommand + streamingPlaylists?: StreamingPlaylistsCommand + channels?: ChannelsCommand + comments?: CommentsCommand + sql?: SQLCommand + notifications?: NotificationsCommand + servers?: ServersCommand + login?: LoginCommand + users?: UsersCommand + videos?: VideosCommand } function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) { @@ -189,13 +187,15 @@ async function flushAndRunServer (serverNumber: number, configOverride?: Object, url: `http://localhost:${port}`, host: `localhost:${port}`, hostname: 'localhost', - client: { - id: null, - secret: null - }, - user: { - username: null, - password: null + store: { + client: { + id: null, + secret: null + }, + user: { + username: null, + password: null + } } } @@ -291,10 +291,10 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] const regexp = regexps[key] const matches = data.toString().match(regexp) if (matches !== null) { - if (key === 'client_id') server.client.id = matches[1] - else if (key === 'client_secret') server.client.secret = matches[1] - else if (key === 'user_username') server.user.username = matches[1] - else if (key === 'user_password') server.user.password = matches[1] + if (key === 'client_id') server.store.client.id = matches[1] + else if (key === 'client_secret') server.store.client.secret = matches[1] + else if (key === 'user_username') server.store.user.username = matches[1] + else if (key === 'user_password') server.store.user.password = matches[1] } } @@ -327,43 +327,43 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] } function assignCommands (server: ServerInfo) { - server.bulkCommand = new BulkCommand(server) - server.cliCommand = new CLICommand(server) - server.customPageCommand = new CustomPagesCommand(server) - server.feedCommand = new FeedCommand(server) - server.logsCommand = new LogsCommand(server) - server.abusesCommand = new AbusesCommand(server) - server.overviewsCommand = new OverviewsCommand(server) - server.searchCommand = new SearchCommand(server) - server.contactFormCommand = new ContactFormCommand(server) - server.debugCommand = new DebugCommand(server) - server.followsCommand = new FollowsCommand(server) - server.jobsCommand = new JobsCommand(server) - server.pluginsCommand = new PluginsCommand(server) - server.redundancyCommand = new RedundancyCommand(server) - server.statsCommand = new StatsCommand(server) - server.configCommand = new ConfigCommand(server) - server.socketIOCommand = new SocketIOCommand(server) - server.accountsCommand = new AccountsCommand(server) - server.blocklistCommand = new BlocklistCommand(server) - server.subscriptionsCommand = new SubscriptionsCommand(server) - server.liveCommand = new LiveCommand(server) - server.servicesCommand = new ServicesCommand(server) - server.blacklistCommand = new BlacklistCommand(server) - server.captionsCommand = new CaptionsCommand(server) - server.changeOwnershipCommand = new ChangeOwnershipCommand(server) - server.playlistsCommand = new PlaylistsCommand(server) - server.historyCommand = new HistoryCommand(server) - server.importsCommand = new ImportsCommand(server) - server.streamingPlaylistsCommand = new StreamingPlaylistsCommand(server) - server.channelsCommand = new ChannelsCommand(server) - server.commentsCommand = new CommentsCommand(server) - server.sqlCommand = new SQLCommand(server) - server.notificationsCommand = new NotificationsCommand(server) - server.serversCommand = new ServersCommand(server) - server.loginCommand = new LoginCommand(server) - server.usersCommand = new UsersCommand(server) - server.videosCommand = new VideosCommand(server) + server.bulk = new BulkCommand(server) + server.cli = new CLICommand(server) + server.customPage = new CustomPagesCommand(server) + server.feed = new FeedCommand(server) + server.logs = new LogsCommand(server) + server.abuses = new AbusesCommand(server) + server.overviews = new OverviewsCommand(server) + server.search = new SearchCommand(server) + server.contactForm = new ContactFormCommand(server) + server.debug = new DebugCommand(server) + server.follows = new FollowsCommand(server) + server.jobs = new JobsCommand(server) + server.plugins = new PluginsCommand(server) + server.redundancy = new RedundancyCommand(server) + server.stats = new StatsCommand(server) + server.config = new ConfigCommand(server) + server.socketIO = new SocketIOCommand(server) + server.accounts = new AccountsCommand(server) + server.blocklist = new BlocklistCommand(server) + server.subscriptions = new SubscriptionsCommand(server) + server.live = new LiveCommand(server) + server.services = new ServicesCommand(server) + server.blacklist = new BlacklistCommand(server) + server.captions = new CaptionsCommand(server) + server.changeOwnership = new ChangeOwnershipCommand(server) + server.playlists = new PlaylistsCommand(server) + server.history = new HistoryCommand(server) + server.imports = new ImportsCommand(server) + server.streamingPlaylists = new StreamingPlaylistsCommand(server) + server.channels = new ChannelsCommand(server) + server.comments = new CommentsCommand(server) + server.sql = new SQLCommand(server) + server.notifications = new NotificationsCommand(server) + server.servers = new ServersCommand(server) + server.login = new LoginCommand(server) + server.users = new UsersCommand(server) + server.videos = new VideosCommand(server) } async function reRunServer (server: ServerInfo, configOverride?: any) { @@ -377,7 +377,7 @@ async function killallServers (servers: ServerInfo[]) { for (const server of servers) { if (!server.app) continue - await server.sqlCommand.cleanup() + await server.sql.cleanup() process.kill(-server.app.pid) @@ -394,7 +394,7 @@ async function cleanupTests (servers: ServerInfo[]) { let p: Promise[] = [] for (const server of servers) { - p = p.concat(server.serversCommand.cleanupTests()) + p = p.concat(server.servers.cleanupTests()) } return Promise.all(p) -- cgit v1.2.3 From 254d3579f5338f5fd775c17d15cdfc37078bcfb4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 09:47:51 +0200 Subject: Use an object to represent a server --- shared/extra-utils/server/directories.ts | 6 +- shared/extra-utils/server/follows-command.ts | 6 +- shared/extra-utils/server/follows.ts | 4 +- shared/extra-utils/server/index.ts | 1 + shared/extra-utils/server/jobs.ts | 10 +- shared/extra-utils/server/plugins.ts | 4 +- shared/extra-utils/server/server.ts | 376 +++++++++++++++++++++++++ shared/extra-utils/server/servers-command.ts | 2 +- shared/extra-utils/server/servers.ts | 400 ++------------------------- 9 files changed, 411 insertions(+), 398 deletions(-) create mode 100644 shared/extra-utils/server/server.ts (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/directories.ts b/shared/extra-utils/server/directories.ts index 3cd38a561..b6465cbf4 100644 --- a/shared/extra-utils/server/directories.ts +++ b/shared/extra-utils/server/directories.ts @@ -4,9 +4,9 @@ import { expect } from 'chai' import { pathExists, readdir } from 'fs-extra' import { join } from 'path' import { root } from '@server/helpers/core-utils' -import { ServerInfo } from './servers' +import { PeerTubeServer } from './server' -async function checkTmpIsEmpty (server: ServerInfo) { +async function checkTmpIsEmpty (server: PeerTubeServer) { await checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css', 'hls', 'resumable-uploads' ]) if (await pathExists(join('test' + server.internalServerNumber, 'tmp', 'hls'))) { @@ -14,7 +14,7 @@ async function checkTmpIsEmpty (server: ServerInfo) { } } -async function checkDirectoryIsEmpty (server: ServerInfo, directory: string, exceptions: string[] = []) { +async function checkDirectoryIsEmpty (server: PeerTubeServer, directory: string, exceptions: string[] = []) { const testDirectory = 'test' + server.internalServerNumber const directoryPath = join(root(), testDirectory, directory) diff --git a/shared/extra-utils/server/follows-command.ts b/shared/extra-utils/server/follows-command.ts index 4e1e56d7a..4e9ed9494 100644 --- a/shared/extra-utils/server/follows-command.ts +++ b/shared/extra-utils/server/follows-command.ts @@ -2,7 +2,7 @@ import { pick } from 'lodash' import { ActivityPubActorType, ActorFollow, FollowState, ResultList } from '@shared/models' import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' import { AbstractCommand, OverrideCommandOptions } from '../shared' -import { ServerInfo } from './servers' +import { PeerTubeServer } from './server' export class FollowsCommand extends AbstractCommand { @@ -70,7 +70,7 @@ export class FollowsCommand extends AbstractCommand { } async unfollow (options: OverrideCommandOptions & { - target: ServerInfo + target: PeerTubeServer }) { const path = '/api/v1/server/following/' + options.target.host @@ -112,7 +112,7 @@ export class FollowsCommand extends AbstractCommand { } removeFollower (options: OverrideCommandOptions & { - follower: ServerInfo + follower: PeerTubeServer }) { const path = '/api/v1/server/followers/peertube@' + options.follower.host diff --git a/shared/extra-utils/server/follows.ts b/shared/extra-utils/server/follows.ts index 50ae898cc..0188be1aa 100644 --- a/shared/extra-utils/server/follows.ts +++ b/shared/extra-utils/server/follows.ts @@ -1,7 +1,7 @@ import { waitJobs } from './jobs' -import { ServerInfo } from './servers' +import { PeerTubeServer } from './server' -async function doubleFollow (server1: ServerInfo, server2: ServerInfo) { +async function doubleFollow (server1: PeerTubeServer, server2: PeerTubeServer) { await Promise.all([ server1.follows.follow({ targets: [ server2.url ] }), server2.follows.follow({ targets: [ server1.url ] }) diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts index 669b004cd..9055dfc57 100644 --- a/shared/extra-utils/server/index.ts +++ b/shared/extra-utils/server/index.ts @@ -9,6 +9,7 @@ export * from './jobs-command' export * from './plugins-command' export * from './plugins' export * from './redundancy-command' +export * from './server' export * from './servers-command' export * from './servers' export * from './stats-command' diff --git a/shared/extra-utils/server/jobs.ts b/shared/extra-utils/server/jobs.ts index 754530977..64a0353eb 100644 --- a/shared/extra-utils/server/jobs.ts +++ b/shared/extra-utils/server/jobs.ts @@ -1,17 +1,17 @@ import { JobState } from '../../models' import { wait } from '../miscs' -import { ServerInfo } from './servers' +import { PeerTubeServer } from './server' -async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { +async function waitJobs (serversArg: PeerTubeServer[] | PeerTubeServer) { const pendingJobWait = process.env.NODE_PENDING_JOB_WAIT ? parseInt(process.env.NODE_PENDING_JOB_WAIT, 10) : 250 - let servers: ServerInfo[] + let servers: PeerTubeServer[] - if (Array.isArray(serversArg) === false) servers = [ serversArg as ServerInfo ] - else servers = serversArg as ServerInfo[] + if (Array.isArray(serversArg) === false) servers = [ serversArg as PeerTubeServer ] + else servers = serversArg as PeerTubeServer[] const states: JobState[] = [ 'waiting', 'active', 'delayed' ] const repeatableJobs = [ 'videos-views', 'activitypub-cleaner' ] diff --git a/shared/extra-utils/server/plugins.ts b/shared/extra-utils/server/plugins.ts index d1cc7e383..0f5fabd5a 100644 --- a/shared/extra-utils/server/plugins.ts +++ b/shared/extra-utils/server/plugins.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import { expect } from 'chai' -import { ServerInfo } from '../server/servers' +import { PeerTubeServer } from '../server/server' -async function testHelloWorldRegisteredSettings (server: ServerInfo) { +async function testHelloWorldRegisteredSettings (server: PeerTubeServer) { const body = await server.plugins.getRegisteredSettings({ npmName: 'peertube-plugin-hello-world' }) const registeredSettings = body.registeredSettings diff --git a/shared/extra-utils/server/server.ts b/shared/extra-utils/server/server.ts new file mode 100644 index 000000000..b1347661f --- /dev/null +++ b/shared/extra-utils/server/server.ts @@ -0,0 +1,376 @@ +import { ChildProcess, fork } from 'child_process' +import { copy } from 'fs-extra' +import { join } from 'path' +import { root } from '@server/helpers/core-utils' +import { randomInt } from '../../core-utils/miscs/miscs' +import { VideoChannel } from '../../models/videos' +import { BulkCommand } from '../bulk' +import { CLICommand } from '../cli' +import { CustomPagesCommand } from '../custom-pages' +import { FeedCommand } from '../feeds' +import { LogsCommand } from '../logs' +import { parallelTests, SQLCommand } from '../miscs' +import { AbusesCommand } from '../moderation' +import { OverviewsCommand } from '../overviews' +import { SearchCommand } from '../search' +import { SocketIOCommand } from '../socket' +import { AccountsCommand, BlocklistCommand, LoginCommand, NotificationsCommand, SubscriptionsCommand, UsersCommand } from '../users' +import { + BlacklistCommand, + CaptionsCommand, + ChangeOwnershipCommand, + ChannelsCommand, + HistoryCommand, + ImportsCommand, + LiveCommand, + PlaylistsCommand, + ServicesCommand, + StreamingPlaylistsCommand, + VideosCommand +} from '../videos' +import { CommentsCommand } from '../videos/comments-command' +import { ConfigCommand } from './config-command' +import { ContactFormCommand } from './contact-form-command' +import { DebugCommand } from './debug-command' +import { FollowsCommand } from './follows-command' +import { JobsCommand } from './jobs-command' +import { PluginsCommand } from './plugins-command' +import { RedundancyCommand } from './redundancy-command' +import { ServersCommand } from './servers-command' +import { StatsCommand } from './stats-command' + +export type RunServerOptions = { + hideLogs?: boolean + execArgv?: string[] +} + +export class PeerTubeServer { + app?: ChildProcess + + url: string + host?: string + hostname?: string + port?: number + + rtmpPort?: number + + parallel?: boolean + internalServerNumber: number + + serverNumber?: number + customConfigFile?: string + + store?: { + client?: { + id?: string + secret?: string + } + + user?: { + username: string + password: string + email?: string + } + + channel?: VideoChannel + + video?: { + id: number + uuid: string + shortUUID: string + name?: string + url?: string + + account?: { + name: string + } + + embedPath?: string + } + + videos?: { id: number, uuid: string }[] + } + + accessToken?: string + refreshToken?: string + + bulk?: BulkCommand + cli?: CLICommand + customPage?: CustomPagesCommand + feed?: FeedCommand + logs?: LogsCommand + abuses?: AbusesCommand + overviews?: OverviewsCommand + search?: SearchCommand + contactForm?: ContactFormCommand + debug?: DebugCommand + follows?: FollowsCommand + jobs?: JobsCommand + plugins?: PluginsCommand + redundancy?: RedundancyCommand + stats?: StatsCommand + config?: ConfigCommand + socketIO?: SocketIOCommand + accounts?: AccountsCommand + blocklist?: BlocklistCommand + subscriptions?: SubscriptionsCommand + live?: LiveCommand + services?: ServicesCommand + blacklist?: BlacklistCommand + captions?: CaptionsCommand + changeOwnership?: ChangeOwnershipCommand + playlists?: PlaylistsCommand + history?: HistoryCommand + imports?: ImportsCommand + streamingPlaylists?: StreamingPlaylistsCommand + channels?: ChannelsCommand + comments?: CommentsCommand + sql?: SQLCommand + notifications?: NotificationsCommand + servers?: ServersCommand + login?: LoginCommand + users?: UsersCommand + videos?: VideosCommand + + constructor (options: { serverNumber: number } | { url: string }) { + if ((options as any).url) { + this.setUrl((options as any).url) + } else { + this.setServerNumber((options as any).serverNumber) + } + + this.store = { + client: { + id: null, + secret: null + }, + user: { + username: null, + password: null + } + } + + this.assignCommands() + } + + setServerNumber (serverNumber: number) { + this.serverNumber = serverNumber + + this.parallel = parallelTests() + + this.internalServerNumber = this.parallel ? this.randomServer() : this.serverNumber + this.rtmpPort = this.parallel ? this.randomRTMP() : 1936 + this.port = 9000 + this.internalServerNumber + + this.url = `http://localhost:${this.port}` + this.host = `localhost:${this.port}` + this.hostname = 'localhost' + } + + setUrl (url: string) { + const parsed = new URL(url) + + this.url = url + this.host = parsed.host + this.hostname = parsed.hostname + this.port = parseInt(parsed.port) + } + + async flushAndRun (configOverride?: Object, args = [], options: RunServerOptions = {}) { + await ServersCommand.flushTests(this.internalServerNumber) + + return this.run(configOverride, args, options) + } + + async run (configOverrideArg?: any, args = [], options: RunServerOptions = {}) { + // These actions are async so we need to be sure that they have both been done + const serverRunString = { + 'HTTP server listening': false + } + const key = 'Database peertube_test' + this.internalServerNumber + ' is ready' + serverRunString[key] = false + + const regexps = { + client_id: 'Client id: (.+)', + client_secret: 'Client secret: (.+)', + user_username: 'Username: (.+)', + user_password: 'User password: (.+)' + } + + await this.assignCustomConfigFile() + + const configOverride = this.buildConfigOverride() + + if (configOverrideArg !== undefined) { + Object.assign(configOverride, configOverrideArg) + } + + // Share the environment + const env = Object.create(process.env) + env['NODE_ENV'] = 'test' + env['NODE_APP_INSTANCE'] = this.internalServerNumber.toString() + env['NODE_CONFIG'] = JSON.stringify(configOverride) + + const forkOptions = { + silent: true, + env, + detached: true, + execArgv: options.execArgv || [] + } + + return new Promise(res => { + this.app = fork(join(root(), 'dist', 'server.js'), args, forkOptions) + this.app.stdout.on('data', function onStdout (data) { + let dontContinue = false + + // Capture things if we want to + for (const key of Object.keys(regexps)) { + const regexp = regexps[key] + const matches = data.toString().match(regexp) + if (matches !== null) { + if (key === 'client_id') this.store.client.id = matches[1] + else if (key === 'client_secret') this.store.client.secret = matches[1] + else if (key === 'user_username') this.store.user.username = matches[1] + else if (key === 'user_password') this.store.user.password = matches[1] + } + } + + // Check if all required sentences are here + for (const key of Object.keys(serverRunString)) { + if (data.toString().indexOf(key) !== -1) serverRunString[key] = true + if (serverRunString[key] === false) dontContinue = true + } + + // If no, there is maybe one thing not already initialized (client/user credentials generation...) + if (dontContinue === true) return + + if (options.hideLogs === false) { + console.log(data.toString()) + } else { + this.app.stdout.removeListener('data', onStdout) + } + + process.on('exit', () => { + try { + process.kill(this.server.app.pid) + } catch { /* empty */ } + }) + + res() + }) + }) + } + + async kill () { + if (!this.app) return + + await this.sql.cleanup() + + process.kill(-this.app.pid) + + this.app = null + } + + private randomServer () { + const low = 10 + const high = 10000 + + return randomInt(low, high) + } + + private randomRTMP () { + const low = 1900 + const high = 2100 + + return randomInt(low, high) + } + + private async assignCustomConfigFile () { + if (this.internalServerNumber === this.serverNumber) return + + const basePath = join(root(), 'config') + + const tmpConfigFile = join(basePath, `test-${this.internalServerNumber}.yaml`) + await copy(join(basePath, `test-${this.serverNumber}.yaml`), tmpConfigFile) + + this.customConfigFile = tmpConfigFile + } + + private buildConfigOverride () { + if (!this.parallel) return {} + + return { + listen: { + port: this.port + }, + webserver: { + port: this.port + }, + database: { + suffix: '_test' + this.internalServerNumber + }, + storage: { + tmp: `test${this.internalServerNumber}/tmp/`, + avatars: `test${this.internalServerNumber}/avatars/`, + videos: `test${this.internalServerNumber}/videos/`, + streaming_playlists: `test${this.internalServerNumber}/streaming-playlists/`, + redundancy: `test${this.internalServerNumber}/redundancy/`, + logs: `test${this.internalServerNumber}/logs/`, + previews: `test${this.internalServerNumber}/previews/`, + thumbnails: `test${this.internalServerNumber}/thumbnails/`, + torrents: `test${this.internalServerNumber}/torrents/`, + captions: `test${this.internalServerNumber}/captions/`, + cache: `test${this.internalServerNumber}/cache/`, + plugins: `test${this.internalServerNumber}/plugins/` + }, + admin: { + email: `admin${this.internalServerNumber}@example.com` + }, + live: { + rtmp: { + port: this.rtmpPort + } + } + } + } + + private assignCommands () { + this.bulk = new BulkCommand(this) + this.cli = new CLICommand(this) + this.customPage = new CustomPagesCommand(this) + this.feed = new FeedCommand(this) + this.logs = new LogsCommand(this) + this.abuses = new AbusesCommand(this) + this.overviews = new OverviewsCommand(this) + this.search = new SearchCommand(this) + this.contactForm = new ContactFormCommand(this) + this.debug = new DebugCommand(this) + this.follows = new FollowsCommand(this) + this.jobs = new JobsCommand(this) + this.plugins = new PluginsCommand(this) + this.redundancy = new RedundancyCommand(this) + this.stats = new StatsCommand(this) + this.config = new ConfigCommand(this) + this.socketIO = new SocketIOCommand(this) + this.accounts = new AccountsCommand(this) + this.blocklist = new BlocklistCommand(this) + this.subscriptions = new SubscriptionsCommand(this) + this.live = new LiveCommand(this) + this.services = new ServicesCommand(this) + this.blacklist = new BlacklistCommand(this) + this.captions = new CaptionsCommand(this) + this.changeOwnership = new ChangeOwnershipCommand(this) + this.playlists = new PlaylistsCommand(this) + this.history = new HistoryCommand(this) + this.imports = new ImportsCommand(this) + this.streamingPlaylists = new StreamingPlaylistsCommand(this) + this.channels = new ChannelsCommand(this) + this.comments = new CommentsCommand(this) + this.sql = new SQLCommand(this) + this.notifications = new NotificationsCommand(this) + this.servers = new ServersCommand(this) + this.login = new LoginCommand(this) + this.users = new UsersCommand(this) + this.videos = new VideosCommand(this) + } +} diff --git a/shared/extra-utils/server/servers-command.ts b/shared/extra-utils/server/servers-command.ts index a7c5a868d..1a7b2aade 100644 --- a/shared/extra-utils/server/servers-command.ts +++ b/shared/extra-utils/server/servers-command.ts @@ -37,7 +37,7 @@ export class ServersCommand extends AbstractCommand { if (isGithubCI()) { await ensureDir('artifacts') - const origin = this.server.servers.buildDirectory('logs/peertube.log') + const origin = this.buildDirectory('logs/peertube.log') const destname = `peertube-${this.server.internalServerNumber}.log` console.log('Saving logs %s.', destname) diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index ea3f19a92..87d7e9449 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -1,391 +1,30 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ +import { ensureDir } from 'fs-extra' +import { isGithubCI } from '../miscs' +import { PeerTubeServer, RunServerOptions } from './server' -import { ChildProcess, fork } from 'child_process' -import { copy, ensureDir } from 'fs-extra' -import { join } from 'path' -import { root } from '@server/helpers/core-utils' -import { randomInt } from '../../core-utils/miscs/miscs' -import { VideoChannel } from '../../models/videos' -import { BulkCommand } from '../bulk' -import { CLICommand } from '../cli' -import { CustomPagesCommand } from '../custom-pages' -import { FeedCommand } from '../feeds' -import { LogsCommand } from '../logs' -import { isGithubCI, parallelTests, SQLCommand } from '../miscs' -import { AbusesCommand } from '../moderation' -import { OverviewsCommand } from '../overviews' -import { SearchCommand } from '../search' -import { SocketIOCommand } from '../socket' -import { AccountsCommand, BlocklistCommand, LoginCommand, NotificationsCommand, SubscriptionsCommand, UsersCommand } from '../users' -import { - BlacklistCommand, - CaptionsCommand, - ChangeOwnershipCommand, - ChannelsCommand, - HistoryCommand, - ImportsCommand, - LiveCommand, - PlaylistsCommand, - ServicesCommand, - StreamingPlaylistsCommand, - VideosCommand -} from '../videos' -import { CommentsCommand } from '../videos/comments-command' -import { ConfigCommand } from './config-command' -import { ContactFormCommand } from './contact-form-command' -import { DebugCommand } from './debug-command' -import { FollowsCommand } from './follows-command' -import { JobsCommand } from './jobs-command' -import { PluginsCommand } from './plugins-command' -import { RedundancyCommand } from './redundancy-command' -import { ServersCommand } from './servers-command' -import { StatsCommand } from './stats-command' +async function createSingleServer (serverNumber: number, configOverride?: Object, args = [], options: RunServerOptions = {}) { + const server = new PeerTubeServer({ serverNumber }) -interface ServerInfo { - app?: ChildProcess + await server.flushAndRun(configOverride, args, options) - url: string - host?: string - hostname?: string - port?: number - - rtmpPort?: number - - parallel?: boolean - internalServerNumber: number - - serverNumber?: number - customConfigFile?: string - - store?: { - client?: { - id?: string - secret?: string - } - - user?: { - username: string - password: string - email?: string - } - - channel?: VideoChannel - - video?: { - id: number - uuid: string - shortUUID: string - name?: string - url?: string - - account?: { - name: string - } - - embedPath?: string - } - - videos?: { id: number, uuid: string }[] - } - - accessToken?: string - refreshToken?: string - - bulk?: BulkCommand - cli?: CLICommand - customPage?: CustomPagesCommand - feed?: FeedCommand - logs?: LogsCommand - abuses?: AbusesCommand - overviews?: OverviewsCommand - search?: SearchCommand - contactForm?: ContactFormCommand - debug?: DebugCommand - follows?: FollowsCommand - jobs?: JobsCommand - plugins?: PluginsCommand - redundancy?: RedundancyCommand - stats?: StatsCommand - config?: ConfigCommand - socketIO?: SocketIOCommand - accounts?: AccountsCommand - blocklist?: BlocklistCommand - subscriptions?: SubscriptionsCommand - live?: LiveCommand - services?: ServicesCommand - blacklist?: BlacklistCommand - captions?: CaptionsCommand - changeOwnership?: ChangeOwnershipCommand - playlists?: PlaylistsCommand - history?: HistoryCommand - imports?: ImportsCommand - streamingPlaylists?: StreamingPlaylistsCommand - channels?: ChannelsCommand - comments?: CommentsCommand - sql?: SQLCommand - notifications?: NotificationsCommand - servers?: ServersCommand - login?: LoginCommand - users?: UsersCommand - videos?: VideosCommand -} - -function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) { - const apps = [] - let i = 0 - - return new Promise(res => { - function anotherServerDone (serverNumber, app) { - apps[serverNumber - 1] = app - i++ - if (i === totalServers) { - return res(apps) - } - } - - for (let j = 1; j <= totalServers; j++) { - flushAndRunServer(j, configOverride).then(app => anotherServerDone(j, app)) - } - }) -} - -function randomServer () { - const low = 10 - const high = 10000 - - return randomInt(low, high) -} - -function randomRTMP () { - const low = 1900 - const high = 2100 - - return randomInt(low, high) -} - -type RunServerOptions = { - hideLogs?: boolean - execArgv?: string[] -} - -async function flushAndRunServer (serverNumber: number, configOverride?: Object, args = [], options: RunServerOptions = {}) { - const parallel = parallelTests() - - const internalServerNumber = parallel ? randomServer() : serverNumber - const rtmpPort = parallel ? randomRTMP() : 1936 - const port = 9000 + internalServerNumber - - await ServersCommand.flushTests(internalServerNumber) - - const server: ServerInfo = { - app: null, - port, - internalServerNumber, - rtmpPort, - parallel, - serverNumber, - url: `http://localhost:${port}`, - host: `localhost:${port}`, - hostname: 'localhost', - store: { - client: { - id: null, - secret: null - }, - user: { - username: null, - password: null - } - } - } - - return runServer(server, configOverride, args, options) + return server } -async function runServer (server: ServerInfo, configOverrideArg?: any, args = [], options: RunServerOptions = {}) { - // These actions are async so we need to be sure that they have both been done - const serverRunString = { - 'HTTP server listening': false - } - const key = 'Database peertube_test' + server.internalServerNumber + ' is ready' - serverRunString[key] = false - - const regexps = { - client_id: 'Client id: (.+)', - client_secret: 'Client secret: (.+)', - user_username: 'Username: (.+)', - user_password: 'User password: (.+)' - } - - if (server.internalServerNumber !== server.serverNumber) { - const basePath = join(root(), 'config') - - const tmpConfigFile = join(basePath, `test-${server.internalServerNumber}.yaml`) - await copy(join(basePath, `test-${server.serverNumber}.yaml`), tmpConfigFile) - - server.customConfigFile = tmpConfigFile - } - - const configOverride: any = {} - - if (server.parallel) { - Object.assign(configOverride, { - listen: { - port: server.port - }, - webserver: { - port: server.port - }, - database: { - suffix: '_test' + server.internalServerNumber - }, - storage: { - tmp: `test${server.internalServerNumber}/tmp/`, - avatars: `test${server.internalServerNumber}/avatars/`, - videos: `test${server.internalServerNumber}/videos/`, - streaming_playlists: `test${server.internalServerNumber}/streaming-playlists/`, - redundancy: `test${server.internalServerNumber}/redundancy/`, - logs: `test${server.internalServerNumber}/logs/`, - previews: `test${server.internalServerNumber}/previews/`, - thumbnails: `test${server.internalServerNumber}/thumbnails/`, - torrents: `test${server.internalServerNumber}/torrents/`, - captions: `test${server.internalServerNumber}/captions/`, - cache: `test${server.internalServerNumber}/cache/`, - plugins: `test${server.internalServerNumber}/plugins/` - }, - admin: { - email: `admin${server.internalServerNumber}@example.com` - }, - live: { - rtmp: { - port: server.rtmpPort - } - } - }) - } - - if (configOverrideArg !== undefined) { - Object.assign(configOverride, configOverrideArg) - } - - // Share the environment - const env = Object.create(process.env) - env['NODE_ENV'] = 'test' - env['NODE_APP_INSTANCE'] = server.internalServerNumber.toString() - env['NODE_CONFIG'] = JSON.stringify(configOverride) +function createMultipleServers (totalServers: number, configOverride?: Object) { + const serverPromises: Promise[] = [] - const forkOptions = { - silent: true, - env, - detached: true, - execArgv: options.execArgv || [] + for (let i = 1; i <= totalServers; i++) { + serverPromises.push(createSingleServer(i, configOverride)) } - return new Promise(res => { - server.app = fork(join(root(), 'dist', 'server.js'), args, forkOptions) - server.app.stdout.on('data', function onStdout (data) { - let dontContinue = false - - // Capture things if we want to - for (const key of Object.keys(regexps)) { - const regexp = regexps[key] - const matches = data.toString().match(regexp) - if (matches !== null) { - if (key === 'client_id') server.store.client.id = matches[1] - else if (key === 'client_secret') server.store.client.secret = matches[1] - else if (key === 'user_username') server.store.user.username = matches[1] - else if (key === 'user_password') server.store.user.password = matches[1] - } - } - - // Check if all required sentences are here - for (const key of Object.keys(serverRunString)) { - if (data.toString().indexOf(key) !== -1) serverRunString[key] = true - if (serverRunString[key] === false) dontContinue = true - } - - // If no, there is maybe one thing not already initialized (client/user credentials generation...) - if (dontContinue === true) return - - if (options.hideLogs === false) { - console.log(data.toString()) - } else { - server.app.stdout.removeListener('data', onStdout) - } - - process.on('exit', () => { - try { - process.kill(server.app.pid) - } catch { /* empty */ } - }) - - assignCommands(server) - - res(server) - }) - }) -} - -function assignCommands (server: ServerInfo) { - server.bulk = new BulkCommand(server) - server.cli = new CLICommand(server) - server.customPage = new CustomPagesCommand(server) - server.feed = new FeedCommand(server) - server.logs = new LogsCommand(server) - server.abuses = new AbusesCommand(server) - server.overviews = new OverviewsCommand(server) - server.search = new SearchCommand(server) - server.contactForm = new ContactFormCommand(server) - server.debug = new DebugCommand(server) - server.follows = new FollowsCommand(server) - server.jobs = new JobsCommand(server) - server.plugins = new PluginsCommand(server) - server.redundancy = new RedundancyCommand(server) - server.stats = new StatsCommand(server) - server.config = new ConfigCommand(server) - server.socketIO = new SocketIOCommand(server) - server.accounts = new AccountsCommand(server) - server.blocklist = new BlocklistCommand(server) - server.subscriptions = new SubscriptionsCommand(server) - server.live = new LiveCommand(server) - server.services = new ServicesCommand(server) - server.blacklist = new BlacklistCommand(server) - server.captions = new CaptionsCommand(server) - server.changeOwnership = new ChangeOwnershipCommand(server) - server.playlists = new PlaylistsCommand(server) - server.history = new HistoryCommand(server) - server.imports = new ImportsCommand(server) - server.streamingPlaylists = new StreamingPlaylistsCommand(server) - server.channels = new ChannelsCommand(server) - server.comments = new CommentsCommand(server) - server.sql = new SQLCommand(server) - server.notifications = new NotificationsCommand(server) - server.servers = new ServersCommand(server) - server.login = new LoginCommand(server) - server.users = new UsersCommand(server) - server.videos = new VideosCommand(server) -} - -async function reRunServer (server: ServerInfo, configOverride?: any) { - const newServer = await runServer(server, configOverride) - server.app = newServer.app - - return server + return Promise.all(serverPromises) } -async function killallServers (servers: ServerInfo[]) { - for (const server of servers) { - if (!server.app) continue - - await server.sql.cleanup() - - process.kill(-server.app.pid) - - server.app = null - } +async function killallServers (servers: PeerTubeServer[]) { + return Promise.all(servers.map(s => s.kill())) } -async function cleanupTests (servers: ServerInfo[]) { +async function cleanupTests (servers: PeerTubeServer[]) { await killallServers(servers) if (isGithubCI()) { @@ -403,11 +42,8 @@ async function cleanupTests (servers: ServerInfo[]) { // --------------------------------------------------------------------------- export { - ServerInfo, + createSingleServer, + createMultipleServers, cleanupTests, - flushAndRunMultipleServers, - flushAndRunServer, - killallServers, - reRunServer, - assignCommands + killallServers } -- cgit v1.2.3 From 08642a765ea514a00f159db898edf14c376fbe6c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 10:20:44 +0200 Subject: Fix server run --- shared/extra-utils/server/server.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/server.ts b/shared/extra-utils/server/server.ts index b1347661f..cc6df2efe 100644 --- a/shared/extra-utils/server/server.ts +++ b/shared/extra-utils/server/server.ts @@ -219,6 +219,8 @@ export class PeerTubeServer { } return new Promise(res => { + const self = this + this.app = fork(join(root(), 'dist', 'server.js'), args, forkOptions) this.app.stdout.on('data', function onStdout (data) { let dontContinue = false @@ -228,10 +230,10 @@ export class PeerTubeServer { const regexp = regexps[key] const matches = data.toString().match(regexp) if (matches !== null) { - if (key === 'client_id') this.store.client.id = matches[1] - else if (key === 'client_secret') this.store.client.secret = matches[1] - else if (key === 'user_username') this.store.user.username = matches[1] - else if (key === 'user_password') this.store.user.password = matches[1] + if (key === 'client_id') self.store.client.id = matches[1] + else if (key === 'client_secret') self.store.client.secret = matches[1] + else if (key === 'user_username') self.store.user.username = matches[1] + else if (key === 'user_password') self.store.user.password = matches[1] } } @@ -247,12 +249,12 @@ export class PeerTubeServer { if (options.hideLogs === false) { console.log(data.toString()) } else { - this.app.stdout.removeListener('data', onStdout) + self.app.stdout.removeListener('data', onStdout) } process.on('exit', () => { try { - process.kill(this.server.app.pid) + process.kill(self.server.app.pid) } catch { /* empty */ } }) -- cgit v1.2.3 From c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 10:42:24 +0200 Subject: Refactor requests --- shared/extra-utils/server/config-command.ts | 4 ++-- shared/extra-utils/server/contact-form-command.ts | 2 +- shared/extra-utils/server/debug-command.ts | 2 +- shared/extra-utils/server/follows-command.ts | 2 +- shared/extra-utils/server/jobs-command.ts | 2 +- shared/extra-utils/server/plugins-command.ts | 2 +- shared/extra-utils/server/redundancy-command.ts | 2 +- shared/extra-utils/server/server.ts | 2 +- shared/extra-utils/server/servers-command.ts | 2 +- shared/extra-utils/server/stats-command.ts | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/config-command.ts b/shared/extra-utils/server/config-command.ts index f5d7fc5e3..6e875fdf6 100644 --- a/shared/extra-utils/server/config-command.ts +++ b/shared/extra-utils/server/config-command.ts @@ -1,6 +1,6 @@ import { merge } from 'lodash' -import { DeepPartial, HttpStatusCode } from '@shared/core-utils' -import { About, ServerConfig } from '@shared/models' +import { DeepPartial } from '@shared/core-utils' +import { About, ServerConfig, HttpStatusCode } from '@shared/models' import { CustomConfig } from '../../models/server/custom-config.model' import { AbstractCommand, OverrideCommandOptions } from '../shared' diff --git a/shared/extra-utils/server/contact-form-command.ts b/shared/extra-utils/server/contact-form-command.ts index 8d034552b..0e8fd6d84 100644 --- a/shared/extra-utils/server/contact-form-command.ts +++ b/shared/extra-utils/server/contact-form-command.ts @@ -1,4 +1,4 @@ -import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/models' import { ContactForm } from '../../models/server' import { AbstractCommand, OverrideCommandOptions } from '../shared' diff --git a/shared/extra-utils/server/debug-command.ts b/shared/extra-utils/server/debug-command.ts index 8b24b3067..36704836d 100644 --- a/shared/extra-utils/server/debug-command.ts +++ b/shared/extra-utils/server/debug-command.ts @@ -1,5 +1,5 @@ import { Debug, SendDebugCommand } from '@shared/models' -import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/models' import { AbstractCommand, OverrideCommandOptions } from '../shared' export class DebugCommand extends AbstractCommand { diff --git a/shared/extra-utils/server/follows-command.ts b/shared/extra-utils/server/follows-command.ts index 4e9ed9494..694f5ea24 100644 --- a/shared/extra-utils/server/follows-command.ts +++ b/shared/extra-utils/server/follows-command.ts @@ -1,6 +1,6 @@ import { pick } from 'lodash' import { ActivityPubActorType, ActorFollow, FollowState, ResultList } from '@shared/models' -import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/models' import { AbstractCommand, OverrideCommandOptions } from '../shared' import { PeerTubeServer } from './server' diff --git a/shared/extra-utils/server/jobs-command.ts b/shared/extra-utils/server/jobs-command.ts index 392b868c1..09a299e5b 100644 --- a/shared/extra-utils/server/jobs-command.ts +++ b/shared/extra-utils/server/jobs-command.ts @@ -1,5 +1,5 @@ import { pick } from 'lodash' -import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/models' import { Job, JobState, JobType, ResultList } from '../../models' import { AbstractCommand, OverrideCommandOptions } from '../shared' diff --git a/shared/extra-utils/server/plugins-command.ts b/shared/extra-utils/server/plugins-command.ts index 98049ce19..59bc79b3d 100644 --- a/shared/extra-utils/server/plugins-command.ts +++ b/shared/extra-utils/server/plugins-command.ts @@ -3,7 +3,7 @@ import { readJSON, writeJSON } from 'fs-extra' import { join } from 'path' import { root } from '@server/helpers/core-utils' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { PeerTubePlugin, PeerTubePluginIndex, diff --git a/shared/extra-utils/server/redundancy-command.ts b/shared/extra-utils/server/redundancy-command.ts index 728332fdd..137d7f01c 100644 --- a/shared/extra-utils/server/redundancy-command.ts +++ b/shared/extra-utils/server/redundancy-command.ts @@ -1,5 +1,5 @@ import { ResultList, VideoRedundanciesTarget, VideoRedundancy } from '@shared/models' -import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/models' import { AbstractCommand, OverrideCommandOptions } from '../shared' export class RedundancyCommand extends AbstractCommand { diff --git a/shared/extra-utils/server/server.ts b/shared/extra-utils/server/server.ts index cc6df2efe..b33bb9d1e 100644 --- a/shared/extra-utils/server/server.ts +++ b/shared/extra-utils/server/server.ts @@ -254,7 +254,7 @@ export class PeerTubeServer { process.on('exit', () => { try { - process.kill(self.server.app.pid) + process.kill(self.app.pid) } catch { /* empty */ } }) diff --git a/shared/extra-utils/server/servers-command.ts b/shared/extra-utils/server/servers-command.ts index 1a7b2aade..107e2b4ad 100644 --- a/shared/extra-utils/server/servers-command.ts +++ b/shared/extra-utils/server/servers-command.ts @@ -2,7 +2,7 @@ import { exec } from 'child_process' import { copy, ensureDir, readFile, remove } from 'fs-extra' import { join } from 'path' import { root } from '@server/helpers/core-utils' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { getFileSize } from '@uploadx/core' import { isGithubCI, wait } from '../miscs' import { AbstractCommand, OverrideCommandOptions } from '../shared' diff --git a/shared/extra-utils/server/stats-command.ts b/shared/extra-utils/server/stats-command.ts index f0f02ca08..6db473588 100644 --- a/shared/extra-utils/server/stats-command.ts +++ b/shared/extra-utils/server/stats-command.ts @@ -1,5 +1,5 @@ import { ServerStats } from '@shared/models' -import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/models' import { AbstractCommand, OverrideCommandOptions } from '../shared' export class StatsCommand extends AbstractCommand { -- cgit v1.2.3 From 4c7e60bc17ee5830399bac4aa273356903421b4c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 14:27:30 +0200 Subject: Reorganize imports --- shared/extra-utils/server/config-command.ts | 2 +- shared/extra-utils/server/debug-command.ts | 3 +-- shared/extra-utils/server/follows-command.ts | 3 +-- shared/extra-utils/server/plugins-command.ts | 2 +- shared/extra-utils/server/redundancy-command.ts | 3 +-- shared/extra-utils/server/stats-command.ts | 3 +-- 6 files changed, 6 insertions(+), 10 deletions(-) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/config-command.ts b/shared/extra-utils/server/config-command.ts index 6e875fdf6..11148aa46 100644 --- a/shared/extra-utils/server/config-command.ts +++ b/shared/extra-utils/server/config-command.ts @@ -1,6 +1,6 @@ import { merge } from 'lodash' import { DeepPartial } from '@shared/core-utils' -import { About, ServerConfig, HttpStatusCode } from '@shared/models' +import { About, HttpStatusCode, ServerConfig } from '@shared/models' import { CustomConfig } from '../../models/server/custom-config.model' import { AbstractCommand, OverrideCommandOptions } from '../shared' diff --git a/shared/extra-utils/server/debug-command.ts b/shared/extra-utils/server/debug-command.ts index 36704836d..3c5a785bb 100644 --- a/shared/extra-utils/server/debug-command.ts +++ b/shared/extra-utils/server/debug-command.ts @@ -1,5 +1,4 @@ -import { Debug, SendDebugCommand } from '@shared/models' -import { HttpStatusCode } from '@shared/models' +import { Debug, HttpStatusCode, SendDebugCommand } from '@shared/models' import { AbstractCommand, OverrideCommandOptions } from '../shared' export class DebugCommand extends AbstractCommand { diff --git a/shared/extra-utils/server/follows-command.ts b/shared/extra-utils/server/follows-command.ts index 694f5ea24..dce674ac5 100644 --- a/shared/extra-utils/server/follows-command.ts +++ b/shared/extra-utils/server/follows-command.ts @@ -1,6 +1,5 @@ import { pick } from 'lodash' -import { ActivityPubActorType, ActorFollow, FollowState, ResultList } from '@shared/models' -import { HttpStatusCode } from '@shared/models' +import { ActivityPubActorType, ActorFollow, FollowState, HttpStatusCode, ResultList } from '@shared/models' import { AbstractCommand, OverrideCommandOptions } from '../shared' import { PeerTubeServer } from './server' diff --git a/shared/extra-utils/server/plugins-command.ts b/shared/extra-utils/server/plugins-command.ts index 59bc79b3d..b944475a2 100644 --- a/shared/extra-utils/server/plugins-command.ts +++ b/shared/extra-utils/server/plugins-command.ts @@ -3,8 +3,8 @@ import { readJSON, writeJSON } from 'fs-extra' import { join } from 'path' import { root } from '@server/helpers/core-utils' -import { HttpStatusCode } from '@shared/models' import { + HttpStatusCode, PeerTubePlugin, PeerTubePluginIndex, PeertubePluginIndexList, diff --git a/shared/extra-utils/server/redundancy-command.ts b/shared/extra-utils/server/redundancy-command.ts index 137d7f01c..e7a8b3c29 100644 --- a/shared/extra-utils/server/redundancy-command.ts +++ b/shared/extra-utils/server/redundancy-command.ts @@ -1,5 +1,4 @@ -import { ResultList, VideoRedundanciesTarget, VideoRedundancy } from '@shared/models' -import { HttpStatusCode } from '@shared/models' +import { HttpStatusCode, ResultList, VideoRedundanciesTarget, VideoRedundancy } from '@shared/models' import { AbstractCommand, OverrideCommandOptions } from '../shared' export class RedundancyCommand extends AbstractCommand { diff --git a/shared/extra-utils/server/stats-command.ts b/shared/extra-utils/server/stats-command.ts index 6db473588..64a452306 100644 --- a/shared/extra-utils/server/stats-command.ts +++ b/shared/extra-utils/server/stats-command.ts @@ -1,5 +1,4 @@ -import { ServerStats } from '@shared/models' -import { HttpStatusCode } from '@shared/models' +import { HttpStatusCode, ServerStats } from '@shared/models' import { AbstractCommand, OverrideCommandOptions } from '../shared' export class StatsCommand extends AbstractCommand { -- cgit v1.2.3 From 4d029ef8ec3d5274eeaa3ee6d808eb7035e7faef Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 20 Jul 2021 14:15:15 +0200 Subject: Add ability for instances to follow any actor --- shared/extra-utils/server/follows-command.ts | 35 ++++++++++++++++++++-------- shared/extra-utils/server/follows.ts | 4 ++-- 2 files changed, 27 insertions(+), 12 deletions(-) (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/follows-command.ts b/shared/extra-utils/server/follows-command.ts index dce674ac5..2b889cf66 100644 --- a/shared/extra-utils/server/follows-command.ts +++ b/shared/extra-utils/server/follows-command.ts @@ -1,5 +1,5 @@ import { pick } from 'lodash' -import { ActivityPubActorType, ActorFollow, FollowState, HttpStatusCode, ResultList } from '@shared/models' +import { ActivityPubActorType, ActorFollow, FollowState, HttpStatusCode, ResultList, ServerFollowCreate } from '@shared/models' import { AbstractCommand, OverrideCommandOptions } from '../shared' import { PeerTubeServer } from './server' @@ -29,13 +29,13 @@ export class FollowsCommand extends AbstractCommand { } getFollowings (options: OverrideCommandOptions & { - start: number - count: number - sort: string + start?: number + count?: number + sort?: string search?: string actorType?: ActivityPubActorType state?: FollowState - }) { + } = {}) { const path = '/api/v1/server/following' const toPick = [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ] @@ -52,26 +52,41 @@ export class FollowsCommand extends AbstractCommand { } follow (options: OverrideCommandOptions & { - targets: string[] + hosts?: string[] + handles?: string[] }) { const path = '/api/v1/server/following' - const hosts = options.targets.map(f => f.replace(/^http:\/\//, '')) + const fields: ServerFollowCreate = {} + + if (options.hosts) { + fields.hosts = options.hosts.map(f => f.replace(/^http:\/\//, '')) + } + + if (options.handles) { + fields.handles = options.handles + } return this.postBodyRequest({ ...options, path, - fields: { hosts }, + fields, implicitToken: true, defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 }) } async unfollow (options: OverrideCommandOptions & { - target: PeerTubeServer + target: PeerTubeServer | string }) { - const path = '/api/v1/server/following/' + options.target.host + const { target } = options + + const handle = typeof target === 'string' + ? target + : target.host + + const path = '/api/v1/server/following/' + handle return this.deleteRequest({ ...options, diff --git a/shared/extra-utils/server/follows.ts b/shared/extra-utils/server/follows.ts index 0188be1aa..698238f29 100644 --- a/shared/extra-utils/server/follows.ts +++ b/shared/extra-utils/server/follows.ts @@ -3,8 +3,8 @@ import { PeerTubeServer } from './server' async function doubleFollow (server1: PeerTubeServer, server2: PeerTubeServer) { await Promise.all([ - server1.follows.follow({ targets: [ server2.url ] }), - server2.follows.follow({ targets: [ server1.url ] }) + server1.follows.follow({ hosts: [ server2.url ] }), + server2.follows.follow({ hosts: [ server1.url ] }) ]) // Wait request propagation -- cgit v1.2.3