mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
update: model extended
update: plugin remote std lib
This commit is contained in:
parent
7dcad5b9bb
commit
e5991cb678
@ -40,6 +40,7 @@
|
|||||||
"axios": "^0.19.2",
|
"axios": "^0.19.2",
|
||||||
"babel-core": "^6.26.3",
|
"babel-core": "^6.26.3",
|
||||||
"classnames": "^2.2.6",
|
"classnames": "^2.2.6",
|
||||||
|
"concat-stream": "^2.0.0",
|
||||||
"cookie_js": "^1.4.0",
|
"cookie_js": "^1.4.0",
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"electron-config": "^2.0.0",
|
"electron-config": "^2.0.0",
|
||||||
@ -80,12 +81,14 @@
|
|||||||
"redux-socket.io": "^1.4.0",
|
"redux-socket.io": "^1.4.0",
|
||||||
"redux-thunk": "^2.3.0",
|
"redux-thunk": "^2.3.0",
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
|
"requirejs": "^2.3.6",
|
||||||
"simple-icons": "^3.8.0",
|
"simple-icons": "^3.8.0",
|
||||||
"socket.io-client": "^2.3.0",
|
"socket.io-client": "^2.3.0",
|
||||||
"stack-trace": "0.0.10",
|
"stack-trace": "0.0.10",
|
||||||
"store": "^2.0.12",
|
"store": "^2.0.12",
|
||||||
"styled-components": "^5.2.0",
|
"styled-components": "^5.2.0",
|
||||||
"timeago.js": "^4.0.2",
|
"timeago.js": "^4.0.2",
|
||||||
|
"vm": "^0.1.0",
|
||||||
"wait-on": "^5.2.0"
|
"wait-on": "^5.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
26
plugins/index.js
Normal file
26
plugins/index.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import verbosity from 'core/libs/verbosity';
|
||||||
|
|
||||||
|
const http = require('http')
|
||||||
|
, vm = require('vm')
|
||||||
|
, concat = require('concat-stream')
|
||||||
|
, async = require('async');
|
||||||
|
|
||||||
|
export function http_require(url, callback) {
|
||||||
|
http.get(url, function(res) {
|
||||||
|
// console.log('fetching: ' + url)
|
||||||
|
res.setEncoding('utf8');
|
||||||
|
res.pipe(concat({encoding: 'string'}, function(data) {
|
||||||
|
callback(null, vm.runInThisContext(data));
|
||||||
|
}));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function usePlugins(array, callback){
|
||||||
|
async.map(array, http_require, function(err, results) {
|
||||||
|
// `results` is an array of values returned by `runInThisContext`
|
||||||
|
// the rest of your program logic
|
||||||
|
if(callback){
|
||||||
|
callback(err, results)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
@ -7,7 +7,7 @@ import Sider_Default from './default'
|
|||||||
import { connect } from 'umi'
|
import { connect } from 'umi'
|
||||||
import MenuList from 'globals/sidebar_menu.js'
|
import MenuList from 'globals/sidebar_menu.js'
|
||||||
|
|
||||||
@connect(({ app }) => ({ app }))
|
@connect(({ app, extended }) => ({ app, extended }))
|
||||||
class Sider extends React.PureComponent {
|
class Sider extends React.PureComponent {
|
||||||
state = {
|
state = {
|
||||||
loading: true,
|
loading: true,
|
||||||
@ -61,6 +61,11 @@ class Sider extends React.PureComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount(){
|
componentDidMount(){
|
||||||
|
const extended = this.props.extended.sidebar
|
||||||
|
if(extended){
|
||||||
|
console.log("Extending state with => ", extended)
|
||||||
|
this.setState({ ...this.state, extended })
|
||||||
|
}
|
||||||
this.menuQuery(MenuList)
|
this.menuQuery(MenuList)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
25
src/core/libs/extension/index.js
Normal file
25
src/core/libs/extension/index.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import localforage from 'localforage'
|
||||||
|
import { package_json } from 'core'
|
||||||
|
|
||||||
|
// Dynamic secure data container processor
|
||||||
|
export class DynamicSDCP {
|
||||||
|
constructor(props){
|
||||||
|
if(props){
|
||||||
|
this.props = props
|
||||||
|
}
|
||||||
|
this.instanceConfig = {
|
||||||
|
name: props.name? props.name : `dynamicSDCP_${Math.random().toFixed()}`,
|
||||||
|
driver : localforage.WEBSQL, // Force WebSQL; same as using setDriver()
|
||||||
|
version : 1.0,
|
||||||
|
size : 4980736, // Size of database, in bytes. WebSQL-only for now.
|
||||||
|
storeName : package_json.UUID, // Should be alphanumeric, with underscores.
|
||||||
|
}
|
||||||
|
|
||||||
|
localforage.config(this.instanceConfig)
|
||||||
|
this.instance = localforage.createInstance(this.instanceConfig)
|
||||||
|
}
|
||||||
|
useInstance(){
|
||||||
|
console.log('Using ', this.instance)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,5 +3,6 @@ import * as appInterface from './appInterface'
|
|||||||
export * from './settings'
|
export * from './settings'
|
||||||
export * from './router'
|
export * from './router'
|
||||||
export * from './verbosity'
|
export * from './verbosity'
|
||||||
|
export * from './extension'
|
||||||
|
|
||||||
export { v3_model, appInterface }
|
export { v3_model, appInterface }
|
||||||
|
@ -5,9 +5,11 @@ import { user, session } from 'core/helpers'
|
|||||||
import { router, verbosity, appInterface } from 'core/libs'
|
import { router, verbosity, appInterface } from 'core/libs'
|
||||||
import settings from 'core/libs/settings'
|
import settings from 'core/libs/settings'
|
||||||
import { uri_resolver } from 'api/lib'
|
import { uri_resolver } from 'api/lib'
|
||||||
|
import { connect } from 'umi'
|
||||||
|
|
||||||
import jwt from 'jsonwebtoken'
|
import jwt from 'jsonwebtoken'
|
||||||
import cookie from 'cookie_js'
|
import cookie from 'cookie_js'
|
||||||
|
import { usePlugins } from 'plugins'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
namespace: 'app',
|
namespace: 'app',
|
||||||
@ -57,7 +59,7 @@ export default {
|
|||||||
})
|
})
|
||||||
dispatch({ type: 'updateFrames' })
|
dispatch({ type: 'updateFrames' })
|
||||||
dispatch({ type: 'handleValidate' })
|
dispatch({ type: 'handleValidate' })
|
||||||
dispatch({ type: 'query' });
|
dispatch({ type: 'query', payload: { dispatcher: dispatch } });
|
||||||
},
|
},
|
||||||
setupHistory({ dispatch, history }) {
|
setupHistory({ dispatch, history }) {
|
||||||
history.listen(location => {
|
history.listen(location => {
|
||||||
@ -89,6 +91,8 @@ export default {
|
|||||||
const session = yield select(state => state.app.session_valid)
|
const session = yield select(state => state.app.session_valid)
|
||||||
const sessionDataframe = yield select(state => state.app.session_data)
|
const sessionDataframe = yield select(state => state.app.session_data)
|
||||||
|
|
||||||
|
window.PluginGlobals = []
|
||||||
|
|
||||||
if (!service) {
|
if (!service) {
|
||||||
console.error('❌ Cannot connect with validate session service!')
|
console.error('❌ Cannot connect with validate session service!')
|
||||||
}
|
}
|
||||||
@ -124,7 +128,6 @@ export default {
|
|||||||
verbosity.debug(res)
|
verbosity.debug(res)
|
||||||
})
|
})
|
||||||
yield put({ type: 'sessionErase' })
|
yield put({ type: 'sessionErase' })
|
||||||
|
|
||||||
},
|
},
|
||||||
*login({ payload }, { call, put, select }) {
|
*login({ payload }, { call, put, select }) {
|
||||||
if (!payload) return false;
|
if (!payload) return false;
|
||||||
@ -133,6 +136,55 @@ export default {
|
|||||||
},
|
},
|
||||||
*guestLogin({ payload }, { put, select }) {
|
*guestLogin({ payload }, { put, select }) {
|
||||||
|
|
||||||
|
},
|
||||||
|
*initializePlugins({ payload }, { select }){
|
||||||
|
const extended = yield select(state => state.extended)
|
||||||
|
|
||||||
|
if(!payload.array){
|
||||||
|
verbosity.error("Only array map for initialize plugins","Please read SDK documentation for more info.")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
usePlugins([payload.array], (err, results) => {
|
||||||
|
if (err) {
|
||||||
|
verbosity.error("Init error!", err)
|
||||||
|
appInterface.notify.error("Plugin initialize error!", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
const rootInit = results[0]
|
||||||
|
|
||||||
|
if (!rootInit.uuid) {
|
||||||
|
verbosity.error("Cannot initialize a plugin without UUID.","Please read SDK documentation for more info.")
|
||||||
|
appInterface.notify.error("Cannot initialize a plugin without UUID.")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
let plugin = {
|
||||||
|
uuid: null,
|
||||||
|
version: "n/a",
|
||||||
|
title: "Blank"
|
||||||
|
}
|
||||||
|
plugin = {...plugin, ...rootInit}
|
||||||
|
|
||||||
|
const rootClass = plugin.payload
|
||||||
|
|
||||||
|
class extendedPlugin extends rootClass{
|
||||||
|
constructor(props){
|
||||||
|
super(props)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.PluginGlobals[plugin.uuid] = new extendedPlugin(extended)
|
||||||
|
|
||||||
|
appInterface.notify.open({
|
||||||
|
message: `${plugin.title} v${plugin.version}`,
|
||||||
|
description: `New plugin is now installed !`
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
verbosity.error("Unexpected catched exception! ", error)
|
||||||
|
|
||||||
|
}
|
||||||
},
|
},
|
||||||
*updateTheme({payload}, {put, select}){
|
*updateTheme({payload}, {put, select}){
|
||||||
if (!payload) return false
|
if (!payload) return false
|
||||||
|
39
src/models/extended.js
Normal file
39
src/models/extended.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import store from 'store'
|
||||||
|
import { app_config } from 'config'
|
||||||
|
import keys from 'config/app_keys'
|
||||||
|
import { user, session } from 'core/helpers'
|
||||||
|
import { router, verbosity, appInterface } from 'core/libs'
|
||||||
|
import settings from 'core/libs/settings'
|
||||||
|
import { uri_resolver } from 'api/lib'
|
||||||
|
import { DynamicSDCP } from 'core/libs/extension'
|
||||||
|
|
||||||
|
import jwt from 'jsonwebtoken'
|
||||||
|
import cookie from 'cookie_js'
|
||||||
|
|
||||||
|
|
||||||
|
export default {
|
||||||
|
namespace: 'extended',
|
||||||
|
state: {
|
||||||
|
sidebar: null,
|
||||||
|
contextMenu: null,
|
||||||
|
core: null
|
||||||
|
},
|
||||||
|
subscriptions: {
|
||||||
|
setup({ dispatch }) {
|
||||||
|
dispatch({ type: 'query' });
|
||||||
|
},
|
||||||
|
},
|
||||||
|
effects: {
|
||||||
|
*query({ payload }, { call, put, select }) {
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
reducers: {
|
||||||
|
updateState(state, { payload }) {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
...payload,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
@ -1,13 +1,31 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import * as antd from 'antd'
|
import * as antd from 'antd'
|
||||||
import * as core from 'core'
|
import * as core from 'core'
|
||||||
|
import { connect } from 'umi'
|
||||||
|
|
||||||
|
@connect(({ app, extended }) => ({ app, extended }))
|
||||||
export default class CoreDebug extends React.Component {
|
export default class CoreDebug extends React.Component {
|
||||||
|
state = {
|
||||||
|
rawPluginInitInput: null
|
||||||
|
}
|
||||||
|
handleInitPlugin(e){
|
||||||
|
this.props.dispatch({
|
||||||
|
type: "app/initializePlugins",
|
||||||
|
payload: {
|
||||||
|
array: e
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
render(){
|
render(){
|
||||||
const handleGenerateUUID = () => { console.log(core.generateUUID()) }
|
const handleGenerateUUID = () => { console.log(core.generateUUID()) }
|
||||||
|
const handleChange = (e) => { this.setState({ rawPluginInitInput: e.target.value }) }
|
||||||
return(
|
return(
|
||||||
<div>
|
<div>
|
||||||
<antd.Button onClick={() => handleGenerateUUID()} >generate uuid</antd.Button>
|
<antd.Button onClick={() => handleGenerateUUID()} >generate uuid</antd.Button>
|
||||||
|
<antd.Card>
|
||||||
|
<antd.Input onChange={handleChange} value={this.state.rawPluginInitInput} placeholder="https://api.ragestudio.net/std/example.js" />
|
||||||
|
<antd.Button onClick={() => { this.handleInitPlugin(this.state.rawPluginInitInput) }} > init </antd.Button>
|
||||||
|
</antd.Card>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user