customAutoLoad management fixes

install-with-shinobicctv-user-instead-of-root
Moe 2020-08-10 15:58:56 -07:00
parent e119bd10d6
commit 36d7c71a54
4 changed files with 75 additions and 35 deletions

View File

@ -483,6 +483,7 @@
"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>.",
"Mode": "Mode",
"Run Installer": "Run Installer",
"Install": "Install",
"Enable": "Enable",
"Disable": "Disable",

View File

@ -1,4 +1,4 @@
const fs = require('fs')
const fs = require('fs-extra');
const express = require('express')
const request = require('request')
const unzipper = require('unzipper')
@ -26,16 +26,20 @@ module.exports = async (s,config,lang,app,io) => {
isDirectory: isDirectory,
}
if(isDirectory){
var hasInstaller = false
if(!fs.existsSync(modulePath + '/index.js')){
hasInstaller = true
newModule.noIndex = true
}
if(fs.existsSync(modulePath + '/package.json')){
hasInstaller = true
newModule.properties = getModuleProperties(moduleName)
}else{
newModule.properties = {
name: moduleName
}
}
newModule.hasInstaller = hasInstaller
}else{
newModule.isIgnitor = (moduleName.indexOf('.js') > -1)
newModule.properties = {
@ -55,22 +59,32 @@ module.exports = async (s,config,lang,app,io) => {
const downloadPath = modulesBasePath + packageName
fs.mkdirSync(downloadPath)
return new Promise(async (resolve, reject) => {
var completed = 0
const directory = await unzipper.Open.url(request,downloadUrl);
if(directory.files.length > 0){
directory.files.forEach(async (file) => {
const content = await file.buffer();
fs.writeFile(downloadPath + '/' + file.path,content,(err) => {
if(err)console.log(err)
++completed
if(directory.files.length === completed){
resolve()
fs.mkdir(downloadPath, () => {
request(downloadUrl).pipe(fs.createWriteStream(downloadPath + '.zip'))
.on('finish',() => {
zip = fs.createReadStream(downloadPath + '.zip')
.pipe(unzipper.Parse())
.on('entry', async (file) => {
if(file.type === 'Directory'){
try{
fs.mkdirSync(modulesBasePath + file.path, { recursive: true })
}catch(err){
}
}else{
const content = await file.buffer();
fs.writeFile(modulesBasePath + file.path,content,(err) => {
if(err)console.log(err)
})
}
})
});
}else{
resolve()
}
.promise()
.then(() => {
fs.remove(downloadPath + '.zip', () => {})
resolve()
})
})
})
})
}
const getModuleProperties = (name) => {
@ -89,8 +103,12 @@ module.exports = async (s,config,lang,app,io) => {
const installerPath = modulePath + `INSTALL.sh`
const propertiesPath = modulePath + 'package.json'
// check for INSTALL.sh (ubuntu only)
console.log(name)
console.log(modulePath)
console.log(installerPath)
console.log(propertiesPath)
if(fs.existsSync(installerPath)){
const installProcess = spawn(`sh`,installerPath)
const installProcess = spawn(`sh`,[installerPath])
installProcess.stderr.on('data',(data) => {
console.log(data.toString())
})
@ -137,8 +155,9 @@ module.exports = async (s,config,lang,app,io) => {
// requires restart for changes to take effect
try{
const modulePath = modulesBasePath + name
fs.unlinkSync(modulePath)
s.file('delete',modulePath)
fs.remove(modulePath, (err) => {
console.log(err)
})
return true
}catch(err){
console.log(err)
@ -272,9 +291,16 @@ 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)
return new Promise((resolve,reject) => {
const packageRootParts = packageRoot.split('/')
const filename = packageRootParts[packageRootParts.length - 1]
fs.move(modulePath + packageRoot,modulesBasePath + filename,(err) => {
fs.remove(modulePath, (err) => {
if(err)console.log(err)
resolve(filename)
})
})
})
}
const initializeAllModules = async () => {
s.customAutoLoadModules = {}

View File

@ -48,7 +48,8 @@
"googleapis": "^39.2.0",
"tree-kill":"1.2.2",
"unzipper":"0.10.11",
"node-fetch":"2.6.0"
"node-fetch":"2.6.0",
"fs-extra": "9.0.1"
},
"devDependencies": {},
"bin": "camera.js",

View File

@ -5,18 +5,27 @@ $(document).ready(function(){
$.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>
var humanName = module.properties.name ? module.properties.name : module.name
if(listElement.find('[package-name="${module.name}"]').length > 0){
var existingElement = listElement.find('[package-name="${module.name}"]')
existingElement.find('.title').text(humanName)
existingElement.find('[calm-action="status"]').text(module.disabled ? lang.Enable : lang.Disable)
}else{
listElement.append(`<div class="card" package-name="${module.name}">
<div class="card-body">
<div><h4 class="title">${humanName}</h4></div>
<div>
${!module.isIgnitor ? `
${module.hasInstaller ? `
<a class="btn btn-sm btn-success" calm-action="install">${lang['Run Installer']}</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>
</div>`)
</div>`)
}
}
var downloadModule = function(url,packageRoot,callback){
$.confirm.create({
@ -73,7 +82,8 @@ $(document).ready(function(){
$('body').on(`click`,`[calm-action]`,function(){
var el = $(this)
var action = el.attr('calm-action')
var card = el.parent('[package-name]')
var card = el.parents('[package-name]')
console.log(card.length)
var packageName = card.attr('package-name')
switch(action){
case'install':
@ -100,7 +110,8 @@ $(document).ready(function(){
break;
}
})
$('#downloadNewModule').submit(function(){
$('#downloadNewModule').submit(function(e){
e.preventDefault();
var el = $(this)
var form = el.serializeObject()
downloadModule(form.downloadUrl,form.packageRoot,function(data){
@ -109,6 +120,7 @@ $(document).ready(function(){
drawModuleBlock(data.newModule)
}
})
return false
})
setTimeout(function(){
getModules(function(data){