2019-07-19 08:36:04 -04:00
|
|
|
import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
|
2019-07-11 11:23:24 -04:00
|
|
|
import { PluginType } from '../../models/plugins/plugin.type'
|
2019-07-19 08:36:04 -04:00
|
|
|
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'
|
2019-07-11 11:23:24 -04:00
|
|
|
|
|
|
|
function listPlugins (parameters: {
|
2020-01-31 10:56:52 -05:00
|
|
|
url: string
|
|
|
|
accessToken: string
|
|
|
|
start?: number
|
|
|
|
count?: number
|
|
|
|
sort?: string
|
|
|
|
pluginType?: PluginType
|
|
|
|
uninstalled?: boolean
|
2019-07-11 11:23:24 -04:00
|
|
|
expectedStatus?: number
|
|
|
|
}) {
|
2019-07-19 08:36:04 -04:00
|
|
|
const { url, accessToken, start, count, sort, pluginType, uninstalled, expectedStatus = 200 } = parameters
|
2019-07-11 11:23:24 -04:00
|
|
|
const path = '/api/v1/plugins'
|
|
|
|
|
|
|
|
return makeGetRequest({
|
|
|
|
url,
|
|
|
|
path,
|
|
|
|
token: accessToken,
|
|
|
|
query: {
|
|
|
|
start,
|
|
|
|
count,
|
|
|
|
sort,
|
2019-07-19 08:36:04 -04:00
|
|
|
pluginType,
|
|
|
|
uninstalled
|
2019-07-11 11:23:24 -04:00
|
|
|
},
|
|
|
|
statusCodeExpected: expectedStatus
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-07-19 08:36:04 -04:00
|
|
|
function listAvailablePlugins (parameters: {
|
2020-01-31 10:56:52 -05:00
|
|
|
url: string
|
|
|
|
accessToken: string
|
|
|
|
start?: number
|
|
|
|
count?: number
|
|
|
|
sort?: string
|
|
|
|
pluginType?: PluginType
|
|
|
|
currentPeerTubeEngine?: string
|
2019-07-19 08:36:04 -04:00
|
|
|
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
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-07-11 11:23:24 -04:00
|
|
|
function getPlugin (parameters: {
|
2020-01-31 10:56:52 -05:00
|
|
|
url: string
|
|
|
|
accessToken: string
|
|
|
|
npmName: string
|
2019-07-11 11:23:24 -04:00
|
|
|
expectedStatus?: number
|
|
|
|
}) {
|
|
|
|
const { url, accessToken, npmName, expectedStatus = 200 } = parameters
|
|
|
|
const path = '/api/v1/plugins/' + npmName
|
|
|
|
|
|
|
|
return makeGetRequest({
|
|
|
|
url,
|
|
|
|
path,
|
|
|
|
token: accessToken,
|
|
|
|
statusCodeExpected: expectedStatus
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-07-19 08:36:04 -04:00
|
|
|
function updatePluginSettings (parameters: {
|
2020-01-31 10:56:52 -05:00
|
|
|
url: string
|
|
|
|
accessToken: string
|
|
|
|
npmName: string
|
|
|
|
settings: any
|
2019-07-11 11:23:24 -04:00
|
|
|
expectedStatus?: number
|
|
|
|
}) {
|
2019-07-19 08:36:04 -04:00
|
|
|
const { url, accessToken, npmName, settings, expectedStatus = 204 } = parameters
|
2019-07-11 11:23:24 -04:00
|
|
|
const path = '/api/v1/plugins/' + npmName + '/settings'
|
|
|
|
|
2019-07-19 08:36:04 -04:00
|
|
|
return makePutBodyRequest({
|
2019-07-11 11:23:24 -04:00
|
|
|
url,
|
|
|
|
path,
|
|
|
|
token: accessToken,
|
2019-07-19 08:36:04 -04:00
|
|
|
fields: { settings },
|
2019-07-11 11:23:24 -04:00
|
|
|
statusCodeExpected: expectedStatus
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPluginRegisteredSettings (parameters: {
|
2020-01-31 10:56:52 -05:00
|
|
|
url: string
|
|
|
|
accessToken: string
|
|
|
|
npmName: string
|
2019-07-11 11:23:24 -04:00
|
|
|
expectedStatus?: number
|
|
|
|
}) {
|
|
|
|
const { url, accessToken, npmName, expectedStatus = 200 } = parameters
|
|
|
|
const path = '/api/v1/plugins/' + npmName + '/registered-settings'
|
|
|
|
|
|
|
|
return makeGetRequest({
|
|
|
|
url,
|
|
|
|
path,
|
|
|
|
token: accessToken,
|
|
|
|
statusCodeExpected: expectedStatus
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-07-26 03:35:43 -04:00
|
|
|
function getPublicSettings (parameters: {
|
2020-01-31 10:56:52 -05:00
|
|
|
url: string
|
|
|
|
npmName: string
|
2019-07-26 03:35:43 -04:00
|
|
|
expectedStatus?: number
|
|
|
|
}) {
|
|
|
|
const { url, npmName, expectedStatus = 200 } = parameters
|
|
|
|
const path = '/api/v1/plugins/' + npmName + '/public-settings'
|
|
|
|
|
|
|
|
return makeGetRequest({
|
|
|
|
url,
|
|
|
|
path,
|
|
|
|
statusCodeExpected: expectedStatus
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-07-26 08:44:50 -04:00
|
|
|
function getPluginTranslations (parameters: {
|
2020-01-31 10:56:52 -05:00
|
|
|
url: string
|
|
|
|
locale: string
|
2019-07-26 08:44:50 -04:00
|
|
|
expectedStatus?: number
|
|
|
|
}) {
|
|
|
|
const { url, locale, expectedStatus = 200 } = parameters
|
|
|
|
const path = '/plugins/translations/' + locale + '.json'
|
|
|
|
|
|
|
|
return makeGetRequest({
|
|
|
|
url,
|
|
|
|
path,
|
|
|
|
statusCodeExpected: expectedStatus
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-07-11 11:23:24 -04:00
|
|
|
function installPlugin (parameters: {
|
2020-01-31 10:56:52 -05:00
|
|
|
url: string
|
|
|
|
accessToken: string
|
|
|
|
path?: string
|
2019-07-11 11:23:24 -04:00
|
|
|
npmName?: string
|
|
|
|
expectedStatus?: number
|
|
|
|
}) {
|
2019-07-12 05:39:58 -04:00
|
|
|
const { url, accessToken, npmName, path, expectedStatus = 200 } = parameters
|
2019-07-11 11:23:24 -04:00
|
|
|
const apiPath = '/api/v1/plugins/install'
|
|
|
|
|
|
|
|
return makePostBodyRequest({
|
|
|
|
url,
|
|
|
|
path: apiPath,
|
|
|
|
token: accessToken,
|
|
|
|
fields: { npmName, path },
|
|
|
|
statusCodeExpected: expectedStatus
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-07-12 05:39:58 -04:00
|
|
|
function updatePlugin (parameters: {
|
2020-01-31 10:56:52 -05:00
|
|
|
url: string
|
|
|
|
accessToken: string
|
|
|
|
path?: string
|
2019-07-12 05:39:58 -04:00
|
|
|
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
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-07-11 11:23:24 -04:00
|
|
|
function uninstallPlugin (parameters: {
|
2020-01-31 10:56:52 -05:00
|
|
|
url: string
|
|
|
|
accessToken: string
|
2019-07-11 11:23:24 -04:00
|
|
|
npmName: string
|
|
|
|
expectedStatus?: number
|
|
|
|
}) {
|
|
|
|
const { url, accessToken, npmName, expectedStatus = 204 } = parameters
|
|
|
|
const apiPath = '/api/v1/plugins/uninstall'
|
|
|
|
|
|
|
|
return makePostBodyRequest({
|
|
|
|
url,
|
|
|
|
path: apiPath,
|
|
|
|
token: accessToken,
|
|
|
|
fields: { npmName },
|
|
|
|
statusCodeExpected: expectedStatus
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-07-19 08:36:04 -04:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2019-07-19 11:30:41 -04:00
|
|
|
function getPluginTestPath (suffix = '') {
|
|
|
|
return join(root(), 'server', 'tests', 'fixtures', 'peertube-plugin-test' + suffix)
|
|
|
|
}
|
|
|
|
|
2019-07-11 11:23:24 -04:00
|
|
|
export {
|
|
|
|
listPlugins,
|
2019-07-19 08:36:04 -04:00
|
|
|
listAvailablePlugins,
|
2019-07-11 11:23:24 -04:00
|
|
|
installPlugin,
|
2019-07-26 08:44:50 -04:00
|
|
|
getPluginTranslations,
|
2019-07-19 08:36:04 -04:00
|
|
|
getPluginsCSS,
|
2019-07-12 05:39:58 -04:00
|
|
|
updatePlugin,
|
2019-07-11 11:23:24 -04:00
|
|
|
getPlugin,
|
|
|
|
uninstallPlugin,
|
2019-07-19 08:36:04 -04:00
|
|
|
updatePluginSettings,
|
|
|
|
getPluginRegisteredSettings,
|
|
|
|
getPackageJSONPath,
|
|
|
|
updatePluginPackageJSON,
|
2019-07-19 11:30:41 -04:00
|
|
|
getPluginPackageJSON,
|
2019-07-26 03:35:43 -04:00
|
|
|
getPluginTestPath,
|
|
|
|
getPublicSettings
|
2019-07-11 11:23:24 -04:00
|
|
|
}
|