diff --git a/languages/en_CA.json b/languages/en_CA.json index a33bb8a7..6f0ed94e 100644 --- a/languages/en_CA.json +++ b/languages/en_CA.json @@ -483,6 +483,7 @@ "DetectorText": "
When the Width and Height boxes are shown you should set them to 640x480 or below. This will optimize the read speed of frames.
", "RecordingText": "It is recommended that you set Record File Type to WebMMP4 and Video Codec to libvpxcopy or libx264 because your Input Type is set to .", "Mode": "Mode", + "Run Installer": "Run Installer", "Install": "Install", "Enable": "Enable", "Disable": "Disable", diff --git a/libs/customAutoLoad.js b/libs/customAutoLoad.js index 0f3b3043..fa032dc0 100644 --- a/libs/customAutoLoad.js +++ b/libs/customAutoLoad.js @@ -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 = {} diff --git a/package.json b/package.json index 754c7aa6..81bf1d30 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/web/libs/js/super.customAutoLoad.js b/web/libs/js/super.customAutoLoad.js index 1b127617..42f9d77c 100644 --- a/web/libs/js/super.customAutoLoad.js +++ b/web/libs/js/super.customAutoLoad.js @@ -5,18 +5,27 @@ $(document).ready(function(){ $.get(superApiPrefix + $user.sessionKey + '/package/list',callback) } var drawModuleBlock = function(module){ - listElement.append(`