0.1.0 move to gitea dist for downloads
This commit is contained in:
+15
-138
@@ -2,7 +2,7 @@
|
||||
|
||||
import * as Logger from 'log4js'
|
||||
import { socketioRPC, ConfigLoader, Plugin } from 'frontblock-generic/Plugin';
|
||||
import { ErrorResponse, SuccessResponse } from 'frontblock-generic/Types';
|
||||
import { ErrorResponse, SuccessResponse, SubscriptionResponse } from 'frontblock-generic/Types';
|
||||
import express = require('express');
|
||||
import http = require('http');
|
||||
import bsock = require('bsock');
|
||||
@@ -10,21 +10,22 @@ import { FrontblockCherryPicker } from "git-cherrypicker"
|
||||
import { promises as fs } from "fs"
|
||||
import { GitUpdater, RepoFolderStatus, } from "./GitUpdater";
|
||||
import * as path from "path"
|
||||
import { UpdateManager } from './UpdateManger';
|
||||
|
||||
const kfs = require("key-file-storage").default('kfs')
|
||||
|
||||
Logger.configure({
|
||||
appenders:
|
||||
{
|
||||
"frontblock-admin": { type: 'stdout' },
|
||||
"admin": { type: 'stdout' },
|
||||
//app: { type: 'file', filename: 'application.log' }
|
||||
},
|
||||
categories:
|
||||
{
|
||||
default: { appenders: [ 'frontblock-admin' ], level: 'debug' }
|
||||
default: { appenders: [ 'admin' ], level: 'debug' }
|
||||
}
|
||||
})
|
||||
const logger = Logger.getLogger("frontblock-admin")
|
||||
const logger = Logger.getLogger("admin")
|
||||
|
||||
type hookRPC =
|
||||
{
|
||||
@@ -70,12 +71,7 @@ export class FrontblockAdmin extends ConfigLoader<AdminConf>{
|
||||
private httpServer
|
||||
private io = bsock.createServer()
|
||||
private wsServer = http.createServer()
|
||||
|
||||
private dashboardUpdater:GitUpdater
|
||||
private adminUpdater:GitUpdater
|
||||
private pluginUpdaters:{[name in string]:GitUpdater} = {}
|
||||
private loadedPlugins:{[name in string]:Plugin} = {}
|
||||
|
||||
private updateManager:UpdateManager = new UpdateManager()
|
||||
|
||||
constructor(){
|
||||
super("FrontblockAdmin")
|
||||
@@ -87,83 +83,10 @@ export class FrontblockAdmin extends ConfigLoader<AdminConf>{
|
||||
return {httpPort: 8080}
|
||||
}
|
||||
|
||||
private async updateFrontblockLib(){
|
||||
logger.warn("Picking FrontblockLib...")
|
||||
await (new FrontblockCherryPicker("fb-dist/admin", "master", "FrontblockLib.js")).write("./static/FrontblockLib.js")
|
||||
}
|
||||
|
||||
private async updateDashboard():Promise<RepoFolderStatus>{
|
||||
logger.warn("Cloning dashboard...")
|
||||
this.dashboardUpdater = new GitUpdater("./static")
|
||||
const status = await this.dashboardUpdater.cloneRepo("https://gitea.frontblock.me/fb-dist/dashboard.git", true)
|
||||
return(status)
|
||||
}
|
||||
|
||||
private async installPlugin(name: string):Promise<RepoFolderStatus>{
|
||||
logger.warn("Cloning "+name+"...")
|
||||
this.pluginUpdaters[name] = new GitUpdater("./plugins/"+name)
|
||||
const status = await this.pluginUpdaters[name].cloneRepo("https://gitea.frontblock.me/fb-dist/"+name.toLowerCase()+".git", true)
|
||||
return status
|
||||
}
|
||||
|
||||
private async startPlugin(name:string):Promise<boolean>{
|
||||
if(!this.pluginUpdaters[name]) return false
|
||||
const status = await this.pluginUpdaters[name].getStatus()
|
||||
if(!status.exists || status.empty || !status.tags || status.tags.length === 0){
|
||||
logger.error("Bad repo status", name, status)
|
||||
return false
|
||||
}
|
||||
|
||||
if(this.loadedPlugins[name]){
|
||||
logger.error("Plugin", name, "is already started")
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
let str = "../plugins/"+name+"/Plugin"
|
||||
const pluginClass = await import(str)
|
||||
const pluginObj = new pluginClass.default()
|
||||
await pluginObj.start()
|
||||
this.loadedPlugins[name] = pluginObj
|
||||
return true
|
||||
}
|
||||
|
||||
private async updatePlugin(name:string):Promise<boolean>{
|
||||
if(!this.pluginUpdaters[name]) return false
|
||||
const status = await this.pluginUpdaters[name].getStatus()
|
||||
if(!status.exists || status.empty || !status.tags || status.tags.length === 0){
|
||||
logger.error("Bad repo status", name, status)
|
||||
return false
|
||||
}
|
||||
if(status.currentTag == status.latestTag){
|
||||
logger.warn(name, "already at latest tag")
|
||||
return false
|
||||
}
|
||||
|
||||
if(this.loadedPlugins[name]){
|
||||
logger.error("Plugin", name, "is running. Stop it first")
|
||||
return false
|
||||
}
|
||||
|
||||
this.pluginUpdaters[name].checkoutTag(status.latestTag!)
|
||||
return true
|
||||
}
|
||||
|
||||
private async setPluginVersion(pluginName:string, tag:string):Promise<RepoFolderStatus>{
|
||||
const status = await this.pluginUpdaters[pluginName].getStatus()
|
||||
if(!status.exists || !status.tags || status.tags.length === 0 || !status.tags.includes(tag)){
|
||||
logger.error("Bad repo status", pluginName, status)
|
||||
return status
|
||||
}
|
||||
|
||||
return await this.pluginUpdaters[pluginName].checkoutTag(tag)
|
||||
}
|
||||
|
||||
private async initialize(){
|
||||
await this.updateDashboard()
|
||||
await this.updateFrontblockLib()
|
||||
await this.installPlugin("PluginManager")
|
||||
//await this.updatePluginmanager()
|
||||
await this.updateManager.updateAdmin()
|
||||
await this.updateManager.updateDashboard()
|
||||
await this.updateManager.updateFrontblockLib()
|
||||
|
||||
this.startWebsocket()
|
||||
this.startWebserver()
|
||||
@@ -188,61 +111,15 @@ export class FrontblockAdmin extends ConfigLoader<AdminConf>{
|
||||
type:'call',
|
||||
fn: () => { return rpcInfos }
|
||||
}
|
||||
},{
|
||||
owner: 'Admin',
|
||||
name: 'installPlugin',
|
||||
args: 'name',
|
||||
info: {
|
||||
type: 'call',
|
||||
fn: async (name:string) => {
|
||||
return await this.installPlugin(name)
|
||||
}
|
||||
}
|
||||
},{
|
||||
owner: 'Admin',
|
||||
name: 'startPlugin',
|
||||
args: 'name',
|
||||
info: {
|
||||
type: 'call',
|
||||
fn: async (name:string) => {
|
||||
return await this.startPlugin(name)
|
||||
}
|
||||
}
|
||||
},{
|
||||
owner: 'PluginManager',
|
||||
name: 'getLoadedPluginNames',
|
||||
args: '',
|
||||
info: {
|
||||
type: 'call',
|
||||
fn: () => Object.keys(this.loadedPlugins)
|
||||
}
|
||||
},{
|
||||
owner: 'Admin',
|
||||
name: 'updatePlugin',
|
||||
args: 'name',
|
||||
info: {
|
||||
type: 'call',
|
||||
fn: async (name) => {return await this.updatePlugin(name)}
|
||||
}
|
||||
},{
|
||||
owner: 'Admin',
|
||||
name: 'setPluginVersion',
|
||||
args: 'name, tag',
|
||||
info: {
|
||||
type: 'call',
|
||||
fn: async (name, tag) => {return await this.setPluginVersion(name, tag)}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
//translate RPCs to socket-bound function metadata
|
||||
const loadedPlugins = this.loadedPlugins
|
||||
for(const name in loadedPlugins){
|
||||
loadedPlugins[name].exportRPCs().forEach(rpc => {
|
||||
const info = this.rpcToRpcInfo(name, rpc)
|
||||
rpcInfos.push(info)
|
||||
})
|
||||
}
|
||||
const loadedPlugins:Plugin[] = [this.updateManager, ...this.updateManager.getLoadedPlugins()]
|
||||
loadedPlugins.forEach(plugin => plugin.exportRPCs().forEach(rpc => {
|
||||
const info = this.rpcToRpcInfo(plugin.name, rpc)
|
||||
rpcInfos.push(info)
|
||||
}))
|
||||
|
||||
//Hook up all the functions
|
||||
for(const api of rpcInfos){
|
||||
@@ -405,7 +282,7 @@ export class FrontblockAdmin extends ConfigLoader<AdminConf>{
|
||||
*
|
||||
* Note callbacks *need* to accept a singular argument and they have to be the last parameter!
|
||||
*/
|
||||
hookGenerator = (rpc:socketioRPC) => {
|
||||
hookGenerator = (rpc:socketioRPC): (socket)=>(...args:any[])=>Promise<SubscriptionResponse> => {
|
||||
const argsArr = this.extractArgs(rpc.rpc).split(',')
|
||||
argsArr.pop()
|
||||
const args = argsArr.join(',')
|
||||
|
||||
Reference in New Issue
Block a user