mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 02:09:37 +02:00
WIP plugins: move plugin CLI in peertube script
Install/uninstall/list plugins remotely
This commit is contained in:
parent
dba85a1e9e
commit
8d2be0ed7b
26 changed files with 452 additions and 191 deletions
125
shared/extra-utils/server/plugins.ts
Normal file
125
shared/extra-utils/server/plugins.ts
Normal file
|
@ -0,0 +1,125 @@
|
|||
import { makeGetRequest, makePostBodyRequest } from '../requests/requests'
|
||||
import { PluginType } from '../../models/plugins/plugin.type'
|
||||
|
||||
function listPlugins (parameters: {
|
||||
url: string,
|
||||
accessToken: string,
|
||||
start?: number,
|
||||
count?: number,
|
||||
sort?: string,
|
||||
type?: PluginType,
|
||||
expectedStatus?: number
|
||||
}) {
|
||||
const { url, accessToken, start, count, sort, type, expectedStatus = 200 } = parameters
|
||||
const path = '/api/v1/plugins'
|
||||
|
||||
return makeGetRequest({
|
||||
url,
|
||||
path,
|
||||
token: accessToken,
|
||||
query: {
|
||||
start,
|
||||
count,
|
||||
sort,
|
||||
type
|
||||
},
|
||||
statusCodeExpected: expectedStatus
|
||||
})
|
||||
}
|
||||
|
||||
function getPlugin (parameters: {
|
||||
url: string,
|
||||
accessToken: string,
|
||||
npmName: string,
|
||||
expectedStatus?: number
|
||||
}) {
|
||||
const { url, accessToken, npmName, expectedStatus = 200 } = parameters
|
||||
const path = '/api/v1/plugins/' + npmName
|
||||
|
||||
return makeGetRequest({
|
||||
url,
|
||||
path,
|
||||
token: accessToken,
|
||||
statusCodeExpected: expectedStatus
|
||||
})
|
||||
}
|
||||
|
||||
function getPluginSettings (parameters: {
|
||||
url: string,
|
||||
accessToken: string,
|
||||
npmName: string,
|
||||
expectedStatus?: number
|
||||
}) {
|
||||
const { url, accessToken, npmName, expectedStatus = 200 } = parameters
|
||||
const path = '/api/v1/plugins/' + npmName + '/settings'
|
||||
|
||||
return makeGetRequest({
|
||||
url,
|
||||
path,
|
||||
token: accessToken,
|
||||
statusCodeExpected: expectedStatus
|
||||
})
|
||||
}
|
||||
|
||||
function getPluginRegisteredSettings (parameters: {
|
||||
url: string,
|
||||
accessToken: string,
|
||||
npmName: string,
|
||||
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
|
||||
})
|
||||
}
|
||||
|
||||
function installPlugin (parameters: {
|
||||
url: string,
|
||||
accessToken: string,
|
||||
path?: string,
|
||||
npmName?: string
|
||||
expectedStatus?: number
|
||||
}) {
|
||||
const { url, accessToken, npmName, path, expectedStatus = 204 } = parameters
|
||||
const apiPath = '/api/v1/plugins/install'
|
||||
|
||||
return makePostBodyRequest({
|
||||
url,
|
||||
path: apiPath,
|
||||
token: accessToken,
|
||||
fields: { npmName, path },
|
||||
statusCodeExpected: expectedStatus
|
||||
})
|
||||
}
|
||||
|
||||
function uninstallPlugin (parameters: {
|
||||
url: string,
|
||||
accessToken: string,
|
||||
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
|
||||
})
|
||||
}
|
||||
|
||||
export {
|
||||
listPlugins,
|
||||
installPlugin,
|
||||
getPlugin,
|
||||
uninstallPlugin,
|
||||
getPluginSettings,
|
||||
getPluginRegisteredSettings
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue