feat: backup plugin
Signed-off-by: MiaoWoo <admin@yumc.pw>
parent
878a5368af
commit
561d5b60e8
|
@ -137,14 +137,15 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
|||
}
|
||||
}
|
||||
|
||||
cmdupgrade(sender: any, name: string) {
|
||||
if (!name) { return this.i18n(sender, 'upgrade.confirm') }
|
||||
if (name == "comfirm") {
|
||||
let enginePath = fs.path(fs.file(fs.concat(root, 'node_modules', '@ccms')))
|
||||
cmdupgrade(sender: any, name: string, confirm: boolean) {
|
||||
if (name == "system") {
|
||||
if (!confirm) { return this.i18n(sender, 'upgrade.confirm') }
|
||||
let enginePath = fs.path(fs.file(root, 'node_modules'))
|
||||
if (enginePath.startsWith(root)) {
|
||||
base.delete(enginePath)
|
||||
this.cmdrestart(sender)
|
||||
}
|
||||
return
|
||||
}
|
||||
if (this.checkPlugin(sender, name)) {
|
||||
this.update(sender, name)
|
||||
|
@ -241,7 +242,7 @@ return '§a返回结果: §r'+ eval(${JSON.stringify(code)});`)
|
|||
name,
|
||||
author: plugin.description.author,
|
||||
version: plugin.description.version,
|
||||
source: base.read(plugin.description.source.toString())
|
||||
source: base.read((plugin.description.source || plugin.description.loadMetadata.file).toString())
|
||||
})
|
||||
this.i18n(sender, result.code == 200 ? 'deploy.success' : 'deploy.fail', { name, msg: result.msg })
|
||||
}
|
||||
|
@ -263,8 +264,11 @@ return '§a返回结果: §r'+ eval(${JSON.stringify(code)});`)
|
|||
return ["install", "cloud"]
|
||||
case "install":
|
||||
return this.packageNameCache
|
||||
case "update":
|
||||
case "upgrade":
|
||||
if (args.length == 2) return ["system", ...this.pluginManager.getPlugins().keys()]
|
||||
if (args.length == 3 && args[1] == "system") return ["confirm"]
|
||||
return []
|
||||
case "update":
|
||||
case "load":
|
||||
case "unload":
|
||||
case "reload":
|
||||
|
|
|
@ -5,12 +5,47 @@ import { constants, database, plugin, web } from "@ccms/api"
|
|||
import { inject, ContainerInstance, Container, JSClass, postConstruct } from "@ccms/container"
|
||||
import { JSPlugin, interfaces, cmd } from "@ccms/plugin"
|
||||
import { DataBase, DataBaseManager } from '@ccms/database'
|
||||
import { Server, Context, RequestHandler, Controller, Get, Post, Param, Body } from '@ccms/web'
|
||||
import { Server, Context, RequestHandler, Controllers, Controller, Get, Post, Param, Body } from '@ccms/web'
|
||||
|
||||
import * as fs from '@ccms/common/dist/fs'
|
||||
import * as reflect from '@ccms/common/dist/reflect'
|
||||
|
||||
@JSPlugin({ name: 'MiaoSpring', prefix: 'MSpring', version: '1.0.1', author: 'MiaoWoo', servers: [constants.ServerType.Spring], source: __filename })
|
||||
@Controller()
|
||||
class PluginController {
|
||||
@inject(plugin.PluginManager)
|
||||
private pluginManager: plugin.PluginManager
|
||||
@inject(database.DataBaseManager)
|
||||
private databaseManager: DataBaseManager
|
||||
|
||||
private mainDB: DataBase
|
||||
|
||||
@postConstruct()
|
||||
initialize() {
|
||||
this.mainDB = this.databaseManager.getMainDatabase()
|
||||
}
|
||||
|
||||
@Get()
|
||||
list(@Param('install') install: boolean) {
|
||||
if (install) {
|
||||
return { status: 200, data: [...this.pluginManager.getPlugins().values()].map((plugin) => plugin.description), msg: '插件列表获取成功!' }
|
||||
} else {
|
||||
return { status: 200, data: this.mainDB.query<Plugin>("SELECT name FROM plugins WHERE deleted = 0") }
|
||||
}
|
||||
}
|
||||
@Post()
|
||||
deploy(@Body() info: Plugin) {
|
||||
let plugin = this.mainDB.query<Plugin>("SELECT name FROM plugins WHERE name = ?", info.name)
|
||||
if (plugin.length == 0) {
|
||||
this.mainDB.update("INSERT INTO `plugins`(`name`, `source`) VALUES (?, ?)", info.name, info.source)
|
||||
return { status: 200, msg: `插件 ${info.name} 新增成功!` }
|
||||
} else {
|
||||
this.mainDB.update("UPDATE `plugins` SET `source` = ? WHERE id = ?", info.source, plugin[0].id)
|
||||
return { status: 200, msg: `插件 ${info.name} 更新成功!` }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JSPlugin({ author: 'MiaoWoo', servers: [constants.ServerType.Spring], source: __filename })
|
||||
export class MiaoSpring extends interfaces.Plugin {
|
||||
@inject(ContainerInstance)
|
||||
private container: Container
|
||||
|
@ -40,6 +75,7 @@ export class MiaoSpring extends interfaces.Plugin {
|
|||
this.mappings = new Set()
|
||||
}
|
||||
|
||||
@Controllers(PluginController)
|
||||
enable() {
|
||||
this.registryDefault()
|
||||
this.registryPages()
|
||||
|
@ -173,6 +209,7 @@ export class MiaoSpring extends interfaces.Plugin {
|
|||
'pluginManager'
|
||||
]
|
||||
let params = [
|
||||
base.getInstance().getAutowireCapableBeanFactory(),
|
||||
this.mainDatabase,
|
||||
reflect,
|
||||
this.container,
|
||||
|
@ -187,6 +224,8 @@ return eval(${JSON.stringify(code)});`)
|
|||
|
||||
disable() {
|
||||
Object.keys(this.mappings).forEach((r) => this.webServer.unregistryMapping(r))
|
||||
this.webServer.unregistryInterceptor({ name: 'RedirectHandle' })
|
||||
this.webServer.unregistryInterceptor({ name: 'StaticHandle' })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,38 +234,3 @@ class Plugin {
|
|||
name: string
|
||||
source: string
|
||||
}
|
||||
|
||||
@Controller()
|
||||
class PluginController {
|
||||
@inject(plugin.PluginManager)
|
||||
private pluginManager: plugin.PluginManager
|
||||
@inject(database.DataBaseManager)
|
||||
private databaseManager: DataBaseManager
|
||||
|
||||
private mainDB: DataBase
|
||||
|
||||
@postConstruct()
|
||||
initialize() {
|
||||
this.mainDB = this.databaseManager.getMainDatabase()
|
||||
}
|
||||
|
||||
@Get()
|
||||
list(@Param('install') install: boolean) {
|
||||
if (install) {
|
||||
return { status: 200, data: [...this.pluginManager.getPlugins().values()].map((plugin) => plugin.description), msg: '插件列表获取成功!' }
|
||||
} else {
|
||||
return { status: 200, data: this.mainDB.query<Plugin>("SELECT name FROM plugins WHERE deleted = 0") }
|
||||
}
|
||||
}
|
||||
@Post()
|
||||
deploy(@Body() info: Plugin) {
|
||||
let plugin = this.mainDB.query<Plugin>("SELECT name FROM plugins WHERE name = ?", info.name)
|
||||
if (plugin.length == 0) {
|
||||
this.mainDB.update("INSERT INTO `plugins`(`name`, `source`) VALUES (?, ?)", info.name, info.source)
|
||||
return { status: 200, msg: `插件 ${info.name} 新增成功!` }
|
||||
} else {
|
||||
this.mainDB.update("UPDATE `plugins` SET `source` = ? WHERE id = ?", info.source, plugin[0].id)
|
||||
return { status: 200, msg: `插件 ${info.name} 更新成功!` }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,6 @@
|
|||
import { constants, web } from "@ccms/api"
|
||||
import { inject } from "@ccms/container"
|
||||
import { constants } from "@ccms/api"
|
||||
import { plugin, interfaces } from "@ccms/plugin"
|
||||
import { Controller, Get, Server, Body, Post, Cookie, Header, Param } from "@ccms/web"
|
||||
|
||||
@plugin({ name: 'MiaoWeb', version: '1.0.0', author: 'MiaoWoo', servers: [constants.ServerType.Spring], source: __filename })
|
||||
export class MiaoWeb extends interfaces.Plugin {
|
||||
@inject(web.Server)
|
||||
private webServer: Server
|
||||
|
||||
enable() {
|
||||
this.webServer.registryController(TestController)
|
||||
}
|
||||
|
||||
disable() {
|
||||
this.webServer.unregistryController(TestController)
|
||||
}
|
||||
}
|
||||
import { Controllers, Controller, Get, Body, Post, Cookie, Header, Param } from "@ccms/web"
|
||||
|
||||
@Controller()
|
||||
export class TestController {
|
||||
|
@ -36,4 +21,11 @@ export class TestController {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@plugin({ author: 'MiaoWoo', servers: [constants.ServerType.Spring], source: __filename })
|
||||
export class MiaoWeb extends interfaces.Plugin {
|
||||
@Controllers(TestController)
|
||||
enable() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue