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AAK,IAAQ,WAAW,EAAK,EAAK,iBAW5C,SAAS,SAAS,GACV,EAAM,SAAW,EAAM,MACvB,IAAI,CAAC,EAAM,QAAS,EAAM,OAAO,KAAK,WAGtC,IAAI,EAEZ,CAfA,KAAK,cAAa,SAAU,EAAK,GAC7B,QAAQ,IAAI,GAAG,EAAI,UAAU,EAAI,OACjC,MAAM,EAAU,oBAAoB,EAAI,QACpC,GACA,EAAQ,EAAK,EAErB,IAAG,OAAO,KAUV,QAAQ,GAAG,qBAAsB,UACjC,QAAQ,GAAG,oBAAqB,UAEhC,QAAQ,IAAI","file":"/npm/raspberry-pi-remote-scripting@1.0.1/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/raspberry-pi-remote-scripting@1.0.1/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const http = require('http');\r\nconst path = require('path');\r\nconst fs = require('fs');\r\nconst { viewEditScript } = require('./templates/viewEditScript');\r\nconst { listScripts } = require('./templates/listScripts');\r\nconst { home } = require('./templates/home');\r\nconst { listLogs } = require('./templates/listLogs');\r\nconst scriptLifecycle = require('./scriptLifecycle');\r\nconst scriptHelpers = require('./scriptHelpers');\r\n\r\nconst {getActiveLogFile, log} = scriptHelpers('///index///');\r\n\r\nglobal.rootDir = __dirname;\r\n\r\nfunction handleGUI(req, res) {\r\n    if (req.url === '/') {\r\n        home(req, res);\r\n    }\r\n    else if (req.url === '/scripts') {\r\n        listScripts(req, res);\r\n    }\r\n    else if (req.url.startsWith('/logs')) {\r\n        listLogs(req, res);\r\n    }\r\n    else if (req.url.startsWith('/execute/scripts')) {\r\n        const file = path.join(__dirname, req.url.replace('/execute', ''));\r\n        scriptLifecycle.setActiveScript(file);\r\n        log('Executing ' + file);\r\n        res.writeHead(302, {'Location': '/logs/' + getActiveLogFile()});\r\n        res.end();\r\n    }\r\n    else if (req.url.startsWith('/scripts')) {\r\n        viewEditScript(req, res);\r\n    }\r\n    else {\r\n        res.end('404');\r\n    }\r\n}\r\n\r\nfunction handleSaveFile(req, res) {\r\n    if (req.url.startsWith('/scripts/')) {\r\n        const fileContent = req.body;\r\n        fs.writeFileSync(path.join(__dirname, req.url), fileContent);\r\n        viewEditScript(req, res, fileContent);\r\n    }\r\n    else {\r\n        res.end('404');\r\n    }\r\n}\r\n\r\nfunction bodyParser(req, res, next) {\r\n    let body = '';\r\n    req.on('data', chunk => {\r\n        body += chunk.toString(); // convert Buffer to string\r\n    });\r\n    req.on('end', () => {\r\n        req.body = body;\r\n        next(req, res);\r\n    });\r\n}\r\n\r\nconst mapMethodToFunction = {\r\n    GET: handleGUI,\r\n    PUT: (req, res) => bodyParser(req, res, handleSaveFile)\r\n};\r\n\r\nhttp.createServer(function (req, res) {\r\n    console.log(`${req.method} ${req.url}`);\r\n    const handler = mapMethodToFunction[req.method];\r\n    if (handler) {\r\n        handler(req, res);\r\n    }\r\n}).listen(9000);\r\n\r\nfunction logError(error) {\r\n    if (error.message && error.stack) {\r\n        log([error.message, error.stack].join('======'))\r\n    }\r\n    else {\r\n        log(error);\r\n    }\r\n}\r\nprocess.on('unhandledRejection', logError);\r\nprocess.on('uncaughtException', logError);\r\n\r\nconsole.log('Server listening on port 9000');\r\n"]}