@ -72,6 +72,12 @@ class PluginsManager {
* @ param { string } name Directory name , also known as plugin unique name
* @ param { string } name Directory name , also known as plugin unique name
* /
* /
downloadPlugin ( repoURL , name ) {
downloadPlugin ( repoURL , name ) {
if ( fs . existsSync ( this . pluginsDir + name ) ) {
log . info ( "plugin" , "Plugin folder already exists? Removing..." ) ;
fs . rmSync ( this . pluginsDir + name , {
recursive : true
} ) ;
}
log . info ( "plugin" , "Installing plugin: " + name + " " + repoURL ) ;
log . info ( "plugin" , "Installing plugin: " + name + " " + repoURL ) ;
let result = Git . clone ( repoURL , this . pluginsDir , name ) ;
let result = Git . clone ( repoURL , this . pluginsDir , name ) ;
log . info ( "plugin" , "Install result: " + result ) ;
log . info ( "plugin" , "Install result: " + result ) ;
@ -115,13 +121,19 @@ class PluginsManager {
* @ returns { Promise < [ ] > }
* @ returns { Promise < [ ] > }
* /
* /
async fetchPluginList ( ) {
async fetchPluginList ( ) {
const res = await axios . get ( "https://uptime.kuma.pet/c/plugins.json" ) ;
let remotePluginList ;
const list = res . data . pluginList ;
try {
const res = await axios . get ( "https://uptime.kuma.pet/c/plugins.json" ) ;
remotePluginList = res . data . pluginList ;
} catch ( e ) {
log . error ( "plugin" , "Failed to fetch plugin list: " + e . message ) ;
remotePluginList = [ ] ;
}
for ( let plugin of this . pluginList ) {
for ( let plugin of this . pluginList ) {
let find = false ;
let find = false ;
// Try to merge
// Try to merge
for ( let remotePlugin of list ) {
for ( let remotePlugin of remoteP luginL ist) {
if ( remotePlugin . name === plugin . info . name ) {
if ( remotePlugin . name === plugin . info . name ) {
find = true ;
find = true ;
remotePlugin . installed = true ;
remotePlugin . installed = true ;
@ -136,17 +148,17 @@ class PluginsManager {
// Local plugin
// Local plugin
if ( ! find ) {
if ( ! find ) {
plugin . info . local = true ;
plugin . info . local = true ;
list. push ( plugin . info ) ;
remoteP luginL ist. push ( plugin . info ) ;
}
}
}
}
// Sort Installed first, then sort by name
// Sort Installed first, then sort by name
return list. sort ( ( a , b ) => {
return remoteP luginL ist. sort ( ( a , b ) => {
if ( a . installed === b . installed ) {
if ( a . installed === b . installed ) {
if ( a . fullName < b . fullName ) {
if ( a . fullName < b . fullName ) {
return - 1 ;
return - 1 ;
}
}
if ( a . fullName > b . fullName ) {
if ( a . fullName > b . fullName ) {
return 1 ;
return 1 ;
}
}
return 0 ;
return 0 ;
@ -191,15 +203,24 @@ class PluginWrapper {
let indexFile = this . pluginDir + "/index.js" ;
let indexFile = this . pluginDir + "/index.js" ;
let packageJSON = this . pluginDir + "/package.json" ;
let packageJSON = this . pluginDir + "/package.json" ;
log . info ( "plugin" , "Installing dependencies" ) ;
if ( fs . existsSync ( indexFile ) ) {
if ( fs . existsSync ( indexFile ) ) {
// Install dependencies
// Install dependencies
childProcess . execSync ( "npm install" , {
let result = childProcess . spawnSync ( "npm" , [ "install" ] , {
cwd : this . pluginDir ,
cwd : this . pluginDir ,
env : {
env : {
... process . env ,
PLAYWRIGHT _BROWSERS _PATH : "../../browsers" , // Special handling for read-browser-monitor
PLAYWRIGHT _BROWSERS _PATH : "../../browsers" , // Special handling for read-browser-monitor
}
}
} ) ;
} ) ;
if ( result . stdout ) {
log . info ( "plugin" , "Install dependencies result: " + result . stdout . toString ( "utf-8" ) ) ;
} else {
log . warn ( "plugin" , "Install dependencies result: no output" ) ;
}
this . pluginClass = require ( path . join ( process . cwd ( ) , indexFile ) ) ;
this . pluginClass = require ( path . join ( process . cwd ( ) , indexFile ) ) ;
let pluginClassType = typeof this . pluginClass ;
let pluginClassType = typeof this . pluginClass ;