X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=shared%2Fextra-utils%2Fserver%2Fplugins.ts;h=b6b5e395826f648ec74016c80ba29a8a1aae380e;hb=5baee5fca418487e72ddcd6419d31bca8659b668;hp=6cd7cd17adcf27f69fe2e47a0f80278ab83d5125;hpb=8d2be0ed7bb87283a1ec98609df6b82d83db706a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/shared/extra-utils/server/plugins.ts b/shared/extra-utils/server/plugins.ts index 6cd7cd17a..b6b5e3958 100644 --- a/shared/extra-utils/server/plugins.ts +++ b/shared/extra-utils/server/plugins.ts @@ -1,16 +1,22 @@ -import { makeGetRequest, makePostBodyRequest } from '../requests/requests' +import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' import { PluginType } from '../../models/plugins/plugin.type' +import { PeertubePluginIndexList } from '../../models/plugins/peertube-plugin-index-list.model' +import { readJSON, writeJSON } from 'fs-extra' +import { ServerInfo } from './servers' +import { root } from '../miscs/miscs' +import { join } from 'path' function listPlugins (parameters: { - url: string, - accessToken: string, - start?: number, - count?: number, - sort?: string, - type?: PluginType, + url: string + accessToken: string + start?: number + count?: number + sort?: string + pluginType?: PluginType + uninstalled?: boolean expectedStatus?: number }) { - const { url, accessToken, start, count, sort, type, expectedStatus = 200 } = parameters + const { url, accessToken, start, count, sort, pluginType, uninstalled, expectedStatus = 200 } = parameters const path = '/api/v1/plugins' return makeGetRequest({ @@ -21,16 +27,49 @@ function listPlugins (parameters: { start, count, sort, - type + pluginType, + uninstalled }, statusCodeExpected: expectedStatus }) } +function listAvailablePlugins (parameters: { + url: string + accessToken: string + start?: number + count?: number + sort?: string + pluginType?: PluginType + currentPeerTubeEngine?: string + search?: string + expectedStatus?: number +}) { + const { url, accessToken, start, count, sort, pluginType, search, currentPeerTubeEngine, expectedStatus = 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, + url: string + accessToken: string + npmName: string expectedStatus?: number }) { const { url, accessToken, npmName, expectedStatus = 200 } = parameters @@ -44,27 +83,29 @@ function getPlugin (parameters: { }) } -function getPluginSettings (parameters: { - url: string, - accessToken: string, - npmName: string, +function updatePluginSettings (parameters: { + url: string + accessToken: string + npmName: string + settings: any expectedStatus?: number }) { - const { url, accessToken, npmName, expectedStatus = 200 } = parameters + const { url, accessToken, npmName, settings, expectedStatus = 204 } = parameters const path = '/api/v1/plugins/' + npmName + '/settings' - return makeGetRequest({ + return makePutBodyRequest({ url, path, token: accessToken, + fields: { settings }, statusCodeExpected: expectedStatus }) } function getPluginRegisteredSettings (parameters: { - url: string, - accessToken: string, - npmName: string, + url: string + accessToken: string + npmName: string expectedStatus?: number }) { const { url, accessToken, npmName, expectedStatus = 200 } = parameters @@ -78,14 +119,44 @@ function getPluginRegisteredSettings (parameters: { }) } +function getPublicSettings (parameters: { + url: string + npmName: string + expectedStatus?: number +}) { + const { url, npmName, expectedStatus = 200 } = parameters + const path = '/api/v1/plugins/' + npmName + '/public-settings' + + return makeGetRequest({ + url, + path, + statusCodeExpected: expectedStatus + }) +} + +function getPluginTranslations (parameters: { + url: string + locale: string + expectedStatus?: number +}) { + const { url, locale, expectedStatus = 200 } = parameters + const path = '/plugins/translations/' + locale + '.json' + + return makeGetRequest({ + url, + path, + statusCodeExpected: expectedStatus + }) +} + function installPlugin (parameters: { - url: string, - accessToken: string, - path?: string, + url: string + accessToken: string + path?: string npmName?: string expectedStatus?: number }) { - const { url, accessToken, npmName, path, expectedStatus = 204 } = parameters + const { url, accessToken, npmName, path, expectedStatus = 200 } = parameters const apiPath = '/api/v1/plugins/install' return makePostBodyRequest({ @@ -97,9 +168,28 @@ function installPlugin (parameters: { }) } +function updatePlugin (parameters: { + url: string + accessToken: string + path?: string + npmName?: string + expectedStatus?: number +}) { + const { url, accessToken, npmName, path, expectedStatus = 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, + url: string + accessToken: string npmName: string expectedStatus?: number }) { @@ -115,11 +205,72 @@ function uninstallPlugin (parameters: { }) } +function getPluginsCSS (url: string) { + const path = '/plugins/global.css' + + return makeGetRequest({ + url, + path, + statusCodeExpected: 200 + }) +} + +function getPackageJSONPath (server: ServerInfo, npmName: string) { + return join(root(), 'test' + server.internalServerNumber, '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?: number +}) { + const { url, npmName, npmVersion, authName, statusCodeExpected, query } = options + + const path = '/plugins/' + npmName + '/' + npmVersion + '/auth/' + authName + + return makeGetRequest({ + url, + path, + query, + statusCodeExpected: statusCodeExpected || 200, + redirects: 0 + }) +} + export { listPlugins, + listAvailablePlugins, installPlugin, + getPluginTranslations, + getPluginsCSS, + updatePlugin, getPlugin, uninstallPlugin, - getPluginSettings, - getPluginRegisteredSettings + updatePluginSettings, + getPluginRegisteredSettings, + getPackageJSONPath, + updatePluginPackageJSON, + getPluginPackageJSON, + getPluginTestPath, + getPublicSettings, + getExternalAuth }