implemented fetchReleaseList
This commit is contained in:
@@ -3,44 +3,75 @@
|
||||
import * as Logger from 'log4js'
|
||||
import { Plugin, socketioRPC } from 'frontblock-generic/Plugin';
|
||||
import { ErrorResponse, SuccessResponse } from 'frontblock-generic/Types';
|
||||
//import { FrontblockApiConf } from "frontblock/FrontblockApiClient"
|
||||
import {PluginManager} from "live-plugin-manager";
|
||||
import express = require('express');
|
||||
import http = require('http');
|
||||
import https = require('https');
|
||||
import fs = require('fs');
|
||||
import bsock = require('bsock');
|
||||
import fetch = require("node-fetch");
|
||||
import { async } from 'q';
|
||||
|
||||
type pluginEntry = {pluginName:string}
|
||||
const pluginList:pluginEntry[] = [
|
||||
{pluginName: 'frontblock'}
|
||||
//{ pluginPath: '../../paymentmanager/static/Plugin', conf:<FrontblockApiConf>{ apiHost: 'localhost' /*/ 'api.testnet.frontblock.me' */, apiPort: 10001 } },
|
||||
//{ pluginPath: '../../htmlsupplier/static/Plugin' },
|
||||
// { pluginPath: 'frontblock/FrontblockApiClient', conf:<FrontblockApiConf>{ apiHost: /*/ 'localhost' */ 'api.testnet.frontblock.me' , apiPort: 10001 } }
|
||||
]
|
||||
const kfs = require("key-file-storage").default('kfs')
|
||||
|
||||
type pluginEntry =
|
||||
{
|
||||
pluginName:string
|
||||
}
|
||||
|
||||
const pluginList:pluginEntry[] =
|
||||
[
|
||||
//{ pluginName: 'apiclient' },
|
||||
//{ pluginName: 'paymentmanager' },
|
||||
//{ pluginName: 'wallet' },
|
||||
{ pluginName: 'htmlsupplier' }
|
||||
]
|
||||
|
||||
type releaseEntry =
|
||||
{
|
||||
tagName: string,
|
||||
staticZipURL: URL,
|
||||
checksumFileURL: URL
|
||||
}
|
||||
|
||||
const express = require('express')
|
||||
const http = require('http')
|
||||
const bsock = require('bsock')
|
||||
const kfs = require("key-file-storage").default('conf') //'conf' is a directory that will be generated if it doesn't exist
|
||||
Logger.configure({
|
||||
appenders: {
|
||||
"admin": { type: 'stdout' },
|
||||
//app: { type: 'file', filename: 'application.log' }
|
||||
},
|
||||
categories: {
|
||||
default: { appenders: [ 'admin' ], level: 'debug' }
|
||||
}
|
||||
appenders:
|
||||
{
|
||||
"admin": { type: 'stdout' },
|
||||
//app: { type: 'file', filename: 'application.log' }
|
||||
},
|
||||
categories:
|
||||
{
|
||||
default: { appenders: [ 'admin' ], level: 'debug' }
|
||||
}
|
||||
})
|
||||
const logger = Logger.getLogger("admin")
|
||||
|
||||
const manager = new PluginManager();
|
||||
type hookRPC =
|
||||
{
|
||||
type: 'hook',
|
||||
generator: (socket) => Function,
|
||||
unhook:(uid:string)=>Promise<ErrorResponse|SuccessResponse>
|
||||
}
|
||||
|
||||
type hookRPC = { type: 'hook', generator: (socket) => Function, unhook:(uid:string)=>Promise<ErrorResponse|SuccessResponse>}
|
||||
type unhookRPC = { type: 'unhook', fn: Function}
|
||||
type callRPC = { type: 'call', fn: Function}
|
||||
type unhookRPC =
|
||||
{
|
||||
type: 'unhook',
|
||||
fn: Function
|
||||
}
|
||||
|
||||
export type rpcInfo = {
|
||||
type callRPC =
|
||||
{
|
||||
type: 'call',
|
||||
fn: Function
|
||||
}
|
||||
|
||||
export type rpcInfo =
|
||||
{
|
||||
owner: string,
|
||||
name: string,
|
||||
args: string,
|
||||
info: hookRPC | unhookRPC | callRPC
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* FrontblockAdmin
|
||||
@@ -61,36 +92,46 @@ export class FrontblockAdmin{
|
||||
private wsServer = http.createServer()
|
||||
|
||||
constructor(){
|
||||
if(!('FrontblockAdmin' in kfs)){
|
||||
logger.warn('No config file found! Generating one')
|
||||
kfs.FrontblockAdmin = { httpPort: 8080 }
|
||||
if(!('admin.conf' in kfs)){
|
||||
logger.info('Generating ./kfs/admin.conf')
|
||||
kfs['admin.conf'] = { httpPort: 8080 }
|
||||
}
|
||||
|
||||
this.initialize()
|
||||
}
|
||||
|
||||
private async initialize(){
|
||||
await this.loadPlugins()
|
||||
this.plugins.forEach(plugin => plugin.start())
|
||||
this.startWebsocket()
|
||||
this.startWebserver()
|
||||
const wat = await this.fetchReleaseList('htmlsupplier')
|
||||
logger.debug(wat)
|
||||
//await this.downloadPlugins()
|
||||
//this.plugins.forEach(plugin => plugin.start())
|
||||
//this.startWebsocket()
|
||||
//this.startWebserver()
|
||||
}
|
||||
|
||||
private async loadPlugins(){
|
||||
this.plugins = []
|
||||
|
||||
pluginList.forEach(async (entry:pluginEntry) => {
|
||||
private async fetchReleaseList(pluginName:string): Promise<releaseEntry[]>{
|
||||
const res = await fetch('https://gitea.frontblock.me/api/v1/repos/fb-vendor/' + pluginName + '/releases')
|
||||
const json = await res.json();
|
||||
const releaseList:releaseEntry[] = []
|
||||
|
||||
logger.info("installing plugin " + entry.pluginName)
|
||||
const info = await manager.installFromNpm(entry.pluginName);
|
||||
|
||||
logger.info("loading plugin " + JSON.stringify(info) )
|
||||
const clazz = manager.require(entry.pluginName);
|
||||
|
||||
//let obj = new clazz.default(entry.conf)
|
||||
//this.plugins.push(obj)
|
||||
json.forEach((release) => {
|
||||
const tagName = release.tag_name
|
||||
const staticZipURL = release.assets.filter(asset => asset.name === pluginName + '.zip')[0].browser_download_url
|
||||
const checksumFileURL = release.assets.filter(asset => asset.name === 'md5sum.txt')[0].browser_download_url
|
||||
releaseList.push({tagName,staticZipURL,checksumFileURL})
|
||||
})
|
||||
|
||||
return releaseList
|
||||
}
|
||||
|
||||
private async downloadPlugin(release:releaseEntry) {
|
||||
}
|
||||
|
||||
private async verifyPlugin(release:releaseEntry) {
|
||||
}
|
||||
|
||||
private async extractPlugin(release:releaseEntry) {
|
||||
}
|
||||
|
||||
private async installPlugin(release:releaseEntry) {
|
||||
}
|
||||
|
||||
private initApis(socket){
|
||||
@@ -176,7 +217,7 @@ export class FrontblockAdmin{
|
||||
this.express = express()
|
||||
this.express.use(express.static('static'))
|
||||
|
||||
this.httpServer = http.Server(this.express)
|
||||
this.httpServer = new http.Server(this.express)
|
||||
this.httpServer.listen(port, () => {
|
||||
logger.info('Admin panel listening for HTTP on *'+port)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user