customAutoLoad Module UI : Enable, Disable, Delete, Install functions
parent
c95f34d7da
commit
7f997649df
|
@ -199,6 +199,7 @@
|
||||||
"File Type": "File Type",
|
"File Type": "File Type",
|
||||||
"Filesize": "Filesize",
|
"Filesize": "Filesize",
|
||||||
"Video Status": "Video Status",
|
"Video Status": "Video Status",
|
||||||
|
"Custom Auto Load": "Custom Auto Load",
|
||||||
"Preferences": "Preferences",
|
"Preferences": "Preferences",
|
||||||
"Equal to": "Equal to",
|
"Equal to": "Equal to",
|
||||||
"Not Equal to": "Not Equal to",
|
"Not Equal to": "Not Equal to",
|
||||||
|
@ -482,6 +483,10 @@
|
||||||
"DetectorText": "<p>When the Width and Height boxes are shown you should set them to 640x480 or below. This will optimize the read speed of frames.</p>",
|
"DetectorText": "<p>When the Width and Height boxes are shown you should set them to 640x480 or below. This will optimize the read speed of frames.</p>",
|
||||||
"RecordingText": "It is recommended that you set <b>Record File Type</b> to <b class=\"h_t_input h_t_jpeg h_t_socket\">WebM</b><b class=\"h_t_input h_t_mjpeg h_t_h264 h_t_hls h_t_mp4 h_t_local\">MP4</b> and <b>Video Codec</b> to <b class=\"h_t_input h_t_jpeg h_t_socket\">libvpx</b><b class=\"h_t_input h_t_h264 h_t_hls h_t_mp4\">copy or </b><b class=\"h_t_input h_t_mjpeg h_t_h264 h_t_hls h_t_mp4 h_t_local\">libx264</b> because your <b>Input Type</b> is set to <b class=\"h_t_text\"></b>.",
|
"RecordingText": "It is recommended that you set <b>Record File Type</b> to <b class=\"h_t_input h_t_jpeg h_t_socket\">WebM</b><b class=\"h_t_input h_t_mjpeg h_t_h264 h_t_hls h_t_mp4 h_t_local\">MP4</b> and <b>Video Codec</b> to <b class=\"h_t_input h_t_jpeg h_t_socket\">libvpx</b><b class=\"h_t_input h_t_h264 h_t_hls h_t_mp4\">copy or </b><b class=\"h_t_input h_t_mjpeg h_t_h264 h_t_hls h_t_mp4 h_t_local\">libx264</b> because your <b>Input Type</b> is set to <b class=\"h_t_text\"></b>.",
|
||||||
"Mode": "Mode",
|
"Mode": "Mode",
|
||||||
|
"Install": "Install",
|
||||||
|
"Enable": "Enable",
|
||||||
|
"Disable": "Disable",
|
||||||
|
"Delete": "Delete",
|
||||||
"Name": "Name",
|
"Name": "Name",
|
||||||
"Skip Ping": "Skip Ping",
|
"Skip Ping": "Skip Ping",
|
||||||
"Retry Connection": "Retry Connection <small>Number of times allowed to fail</small>",
|
"Retry Connection": "Retry Connection <small>Number of times allowed to fail</small>",
|
||||||
|
|
|
@ -31,8 +31,12 @@ module.exports = async (s,config,lang,app,io) => {
|
||||||
if(!fs.existsSync(modulePath + '/index.js')){
|
if(!fs.existsSync(modulePath + '/index.js')){
|
||||||
foundModules[moduleName].noIndex = true
|
foundModules[moduleName].noIndex = true
|
||||||
}
|
}
|
||||||
if(!fs.existsSync(modulePath + '/package.json')){
|
if(fs.existsSync(modulePath + '/package.json')){
|
||||||
foundModules[moduleName].properties = getModuleProperties(moduleName)
|
foundModules[moduleName].properties = getModuleProperties(moduleName)
|
||||||
|
}else{
|
||||||
|
foundModules[moduleName].properties = {
|
||||||
|
name: moduleName
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
foundModules[moduleName].isIgnitor = (moduleName.indexOf('.js') > -1)
|
foundModules[moduleName].isIgnitor = (moduleName.indexOf('.js') > -1)
|
||||||
|
@ -104,6 +108,8 @@ module.exports = async (s,config,lang,app,io) => {
|
||||||
installProcess.on('exit',(data) => {
|
installProcess.on('exit',(data) => {
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
|
}else{
|
||||||
|
resolve()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -112,15 +118,28 @@ module.exports = async (s,config,lang,app,io) => {
|
||||||
const modulePath = getModulePath(name)
|
const modulePath = getModulePath(name)
|
||||||
const properties = getModuleProperties(name);
|
const properties = getModuleProperties(name);
|
||||||
const propertiesPath = modulePath + 'package.json'
|
const propertiesPath = modulePath + 'package.json'
|
||||||
var packageJson = JSON.parse(fs.readFileSync(propertiesPath))
|
var packageJson = {
|
||||||
|
name: name
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
packageJson = JSON.parse(fs.readFileSync(propertiesPath))
|
||||||
|
}catch(err){
|
||||||
|
|
||||||
|
}
|
||||||
packageJson.disabled = status;
|
packageJson.disabled = status;
|
||||||
fs.writeFileSync(propertiesPath,s.prettyPrint(packageJson))
|
fs.writeFileSync(propertiesPath,s.prettyPrint(packageJson))
|
||||||
}
|
}
|
||||||
const deleteModule = (name) => {
|
const deleteModule = (name) => {
|
||||||
// requires restart for changes to take effect
|
// requires restart for changes to take effect
|
||||||
const modulePath = getModulePath(name)
|
try{
|
||||||
fs.unlink(modulePath)
|
const modulePath = modulesBasePath + name
|
||||||
s.file('delete',modulePath)
|
fs.unlinkSync(modulePath)
|
||||||
|
s.file('delete',modulePath)
|
||||||
|
return true
|
||||||
|
}catch(err){
|
||||||
|
console.log(err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const loadModule = (shinobiModule) => {
|
const loadModule = (shinobiModule) => {
|
||||||
const moduleName = shinobiModule.name
|
const moduleName = shinobiModule.name
|
||||||
|
@ -248,6 +267,11 @@ module.exports = async (s,config,lang,app,io) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const moveModuleToNameInProperties = (modulePath,packageRoot,properties) => {
|
||||||
|
fs.renameSync(modulePath + packageRoot,modulesBasePath + properties.name)
|
||||||
|
fs.unlinkSync(modulePath)
|
||||||
|
s.file('delete',modulePath)
|
||||||
|
}
|
||||||
const initializeAllModules = async () => {
|
const initializeAllModules = async () => {
|
||||||
s.customAutoLoadModules = {}
|
s.customAutoLoadModules = {}
|
||||||
s.customAutoLoadTree = {
|
s.customAutoLoadTree = {
|
||||||
|
@ -271,25 +295,45 @@ module.exports = async (s,config,lang,app,io) => {
|
||||||
loadModule(shinobiModule)
|
loadModule(shinobiModule)
|
||||||
})
|
})
|
||||||
}else{
|
}else{
|
||||||
fs.mkdirSync(modulesBasePath)
|
fs.mkdir(modulesBasePath,() => {})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* API : Superuser : Custom Auto Load Package Download.
|
* API : Superuser : Custom Auto Load Package Download.
|
||||||
*/
|
*/
|
||||||
|
app.get(config.webPaths.superApiPrefix+':auth/package/list', async (req,res) => {
|
||||||
|
s.superAuth(req.params, async (resp) => {
|
||||||
|
s.closeJsonResponse(res,{
|
||||||
|
ok: true,
|
||||||
|
modules: getModules()
|
||||||
|
})
|
||||||
|
},res,req)
|
||||||
|
})
|
||||||
|
/**
|
||||||
|
* API : Superuser : Custom Auto Load Package Download.
|
||||||
|
*/
|
||||||
app.post(config.webPaths.superApiPrefix+':auth/package/download', async (req,res) => {
|
app.post(config.webPaths.superApiPrefix+':auth/package/download', async (req,res) => {
|
||||||
s.superAuth(req.params, async (resp) => {
|
s.superAuth(req.params, async (resp) => {
|
||||||
const url = req.body.downloadUrl
|
try{
|
||||||
const packageRoot = req.body.packageRoot || ''
|
const url = req.body.downloadUrl
|
||||||
const packageName = req.body.packageName || extractNameFromPackage(url)
|
const packageRoot = req.body.packageRoot || ''
|
||||||
const modulePath = getModulePath(packageName)
|
const packageName = req.body.packageName || extractNameFromPackage(url)
|
||||||
await downloadModule(url,packageName)
|
const modulePath = getModulePath(packageName)
|
||||||
const properties = getModuleProperties(packageName)
|
await downloadModule(url,packageName)
|
||||||
fs.renameSync(modulePath + packageRoot,modulesBasePath + properties.name)
|
const properties = getModuleProperties(packageName)
|
||||||
fs.unlinkSync(modulePath)
|
const newName = await moveModuleToNameInProperties(modulePath,packageRoot,properties)
|
||||||
s.file('delete',modulePath)
|
disableModule(newName,true)
|
||||||
s.closeJsonResponse(res,{ok: true})
|
s.closeJsonResponse(res,{
|
||||||
|
ok: true,
|
||||||
|
moduleName: newName
|
||||||
|
})
|
||||||
|
}catch(err){
|
||||||
|
console.log(err)
|
||||||
|
s.closeJsonResponse(res,{
|
||||||
|
ok: false
|
||||||
|
})
|
||||||
|
}
|
||||||
},res,req)
|
},res,req)
|
||||||
})
|
})
|
||||||
/**
|
/**
|
||||||
|
@ -309,7 +353,7 @@ module.exports = async (s,config,lang,app,io) => {
|
||||||
s.superAuth(req.params, async (resp) => {
|
s.superAuth(req.params, async (resp) => {
|
||||||
const status = req.body.status
|
const status = req.body.status
|
||||||
const packageName = req.body.packageName
|
const packageName = req.body.packageName
|
||||||
disableModule(packageName,status === 'true' ? true : false)
|
disableModule(packageName,status == 'true' ? true : false)
|
||||||
s.closeJsonResponse(res,{ok: true})
|
s.closeJsonResponse(res,{ok: true})
|
||||||
},res,req)
|
},res,req)
|
||||||
})
|
})
|
||||||
|
@ -319,8 +363,8 @@ module.exports = async (s,config,lang,app,io) => {
|
||||||
app.post(config.webPaths.superApiPrefix+':auth/package/delete', async (req,res) => {
|
app.post(config.webPaths.superApiPrefix+':auth/package/delete', async (req,res) => {
|
||||||
s.superAuth(req.params, async (resp) => {
|
s.superAuth(req.params, async (resp) => {
|
||||||
const packageName = req.body.packageName
|
const packageName = req.body.packageName
|
||||||
deleteModule(packageName)
|
const response = deleteModule(packageName)
|
||||||
s.closeJsonResponse(res,{ok: true})
|
s.closeJsonResponse(res,{ok: response})
|
||||||
},res,req)
|
},res,req)
|
||||||
})
|
})
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,114 @@
|
||||||
|
$(document).ready(function(){
|
||||||
|
var loadedModules = {}
|
||||||
|
var listElement = $('#customAutoLoadList')
|
||||||
|
var getModules = function(callback) {
|
||||||
|
$.get(superApiPrefix + $user.sessionKey + '/package/list',callback)
|
||||||
|
}
|
||||||
|
var drawModuleBlock = function(module){
|
||||||
|
listElement.append(`<div class="card" package-name="${module.name}">
|
||||||
|
<div class="card-body">
|
||||||
|
<div><h4>${module.properties.name ? module.properties.name : module.name}</h4></div>
|
||||||
|
<div>
|
||||||
|
${!module.isIgnitor ? `
|
||||||
|
<a class="btn btn-sm btn-success" calm-action="install">${lang.Install}</a>
|
||||||
|
<a class="btn btn-sm btn-default" calm-action="status">${module.disabled ? lang.Enable : lang.Disable}</a>
|
||||||
|
` : ''}
|
||||||
|
<a class="btn btn-sm btn-danger" calm-action="delete">${lang.Delete}</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>`)
|
||||||
|
}
|
||||||
|
var downloadModule = function(url,packageRoot){
|
||||||
|
$.confirm.create({
|
||||||
|
title: 'Module Download',
|
||||||
|
body: `Do you want to download the module from ${url}? `,
|
||||||
|
clickOptions: {
|
||||||
|
class: 'btn-success',
|
||||||
|
title: lang.Download,
|
||||||
|
},
|
||||||
|
clickCallback: function(){
|
||||||
|
$.post(superApiPrefix + $user.sessionKey + '/package/download',{
|
||||||
|
downloadUrl: url,
|
||||||
|
packageRoot: packageRoot,
|
||||||
|
},function(data){
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
var installModule = function(packageName,callback){
|
||||||
|
$.confirm.create({
|
||||||
|
title: 'Install Module',
|
||||||
|
body: `Do you want to install the module ${packageName}?`,
|
||||||
|
clickOptions: {
|
||||||
|
class: 'btn-success',
|
||||||
|
title: lang.Install,
|
||||||
|
},
|
||||||
|
clickCallback: function(){
|
||||||
|
$.post(superApiPrefix + $user.sessionKey + '/package/install',{
|
||||||
|
packageName: packageName,
|
||||||
|
},callback)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
var deleteModule = function(packageName,callback){
|
||||||
|
$.confirm.create({
|
||||||
|
title: 'Delete Module',
|
||||||
|
body: `Do you want to delete the module ${packageName}?`,
|
||||||
|
clickOptions: {
|
||||||
|
class: 'btn-danger',
|
||||||
|
title: lang.Delete,
|
||||||
|
},
|
||||||
|
clickCallback: function(){
|
||||||
|
$.post(superApiPrefix + $user.sessionKey + '/package/delete',{
|
||||||
|
packageName: packageName,
|
||||||
|
},callback)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
var setModuleStatus = function(packageName,status,callback){
|
||||||
|
$.post(superApiPrefix + $user.sessionKey + '/package/status',{
|
||||||
|
status: status,
|
||||||
|
packageName: packageName,
|
||||||
|
},callback)
|
||||||
|
}
|
||||||
|
$('body').on(`click`,`[calm-action]`,function(){
|
||||||
|
var el = $(this)
|
||||||
|
var action = el.attr('calm-action')
|
||||||
|
var card = el.parent('[package-name]')
|
||||||
|
var packageName = card.attr('package-name')
|
||||||
|
switch(action){
|
||||||
|
case'install':
|
||||||
|
installModule(packageName,function(data){
|
||||||
|
if(data.ok){
|
||||||
|
console.log(data)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
break;
|
||||||
|
case'status':
|
||||||
|
setModuleStatus(packageName,!!!loadedModules[packageName].disabled,function(data){
|
||||||
|
if(data.ok){
|
||||||
|
loadedModules[packageName].disabled = !!!loadedModules[packageName].disabled
|
||||||
|
el.text(loadedModules[packageName].disabled ? lang.Enable : lang.Disable)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
break;
|
||||||
|
case'delete':
|
||||||
|
deleteModule(packageName,function(data){
|
||||||
|
if(data.ok){
|
||||||
|
card.remove()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
setTimeout(function(){
|
||||||
|
getModules(function(data){
|
||||||
|
loadedModules = data.modules
|
||||||
|
console.log(loadedModules)
|
||||||
|
$.each(data.modules,function(n,module){
|
||||||
|
drawModuleBlock(module)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},2000)
|
||||||
|
})
|
|
@ -0,0 +1,4 @@
|
||||||
|
<div class="form-group-group red" id="customAutoLoadList">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<script src="<%-window.libURL%>libs/js/super.customAutoLoad.js" type="text/javascript"></script>
|
|
@ -40,6 +40,7 @@
|
||||||
<link rel="stylesheet" href="<%-window.libURL%>libs/css/<%-lib%>">
|
<link rel="stylesheet" href="<%-window.libURL%>libs/css/<%-lib%>">
|
||||||
<% }) %>
|
<% }) %>
|
||||||
</head>
|
</head>
|
||||||
|
<script>$user=<%-JSON.stringify($user)%></script>
|
||||||
|
|
||||||
<body class="index-page sidebar-collapse bg-hexagon">
|
<body class="index-page sidebar-collapse bg-hexagon">
|
||||||
<!-- Navbar -->
|
<!-- Navbar -->
|
||||||
|
@ -87,6 +88,9 @@
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" data-toggle="tab" href="#changeSuperPreferences" role="tab"><%-lang['Preferences']%></a>
|
<a class="nav-link" data-toggle="tab" href="#changeSuperPreferences" role="tab"><%-lang['Preferences']%></a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" data-toggle="tab" href="#customAutoLoad" role="tab"><%-lang['Custom Auto Load']%></a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<!-- Tab panes -->
|
<!-- Tab panes -->
|
||||||
|
@ -101,6 +105,9 @@
|
||||||
<div class="tab-pane text-left" id="system" role="tabpanel">
|
<div class="tab-pane text-left" id="system" role="tabpanel">
|
||||||
<% include blocks/superSystemTab.ejs %>
|
<% include blocks/superSystemTab.ejs %>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="tab-pane text-left" id="customAutoLoad" role="tabpanel">
|
||||||
|
<% include blocks/superCustomAutoLoadManager.ejs %>
|
||||||
|
</div>
|
||||||
<div class="tab-pane text-left" id="changeSuperPreferences" role="tabpanel">
|
<div class="tab-pane text-left" id="changeSuperPreferences" role="tabpanel">
|
||||||
<% include blocks/changeSuperPreferences.ejs %>
|
<% include blocks/changeSuperPreferences.ejs %>
|
||||||
</div>
|
</div>
|
||||||
|
@ -151,7 +158,6 @@
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>$user=<%-JSON.stringify($user)%></script>
|
|
||||||
<script>
|
<script>
|
||||||
$.ccio={accounts:{}};$.ls=localStorage;
|
$.ccio={accounts:{}};$.ls=localStorage;
|
||||||
if(!$user.lang||$user.lang==''){
|
if(!$user.lang||$user.lang==''){
|
||||||
|
|
Loading…
Reference in New Issue