Skip to content

Commit

Permalink
Locallize
Browse files Browse the repository at this point in the history
  • Loading branch information
naibo committed Mar 19, 2023
1 parent 3f21271 commit 820c1a2
Show file tree
Hide file tree
Showing 75 changed files with 47,000 additions and 78 deletions.
6 changes: 6 additions & 0 deletions ElectronJS/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"backend_port": 8074,
"websocket_port": 8084,
"backend_address": "http://localhost",
"user_browser_config_path":""
}
740 changes: 740 additions & 0 deletions ElectronJS/execution_instances/0.json

Large diffs are not rendered by default.

740 changes: 740 additions & 0 deletions ElectronJS/execution_instances/1.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ElectronJS/execution_instances/2.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ElectronJS/execution_instances/3.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ElectronJS/execution_instances/4.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ElectronJS/execution_instances/5.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ElectronJS/execution_instances/6.json

Large diffs are not rendered by default.

740 changes: 740 additions & 0 deletions ElectronJS/execution_instances/7.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ElectronJS/execution_instances/8.json

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions ElectronJS/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@
const { app, BrowserWindow, dialog, ipcMain, screen } = require('electron');
app.commandLine.appendSwitch("--disable-http-cache");
const path = require('path');
const fs = require('fs');
const {exec} = require('child_process');
const iconPath = path.join(__dirname, 'favicon.ico');
const task_server = require(path.join(__dirname, 'server.js'));

let config = fs.readFileSync(path.join(__dirname, `config.json`), 'utf8');
config = JSON.parse(config);
task_server.start(config.backend_port); //start local server
let backend_address = `${config.backend_address}:${config.backend_port}`;
let websocket_port = config.websocket_port;
let user_browser_config_path = path.join(__dirname, "user_browser_config.json");
console.log("backend_address: " + backend_address);
let driverPath = "";
let chromeBinaryPath = "";
let execute_path = "";
Expand Down
6 changes: 6 additions & 0 deletions ElectronJS/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ElectronJS/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@jitsi/robotjs": "^0.6.11",
"electron-squirrel-startup": "^1.0.0",
"ffi-napi": "^4.0.3",
"http": "^0.0.1-security",
"node-window-manager": "^2.2.4",
"ref-napi": "^3.0.3",
"selenium-webdriver": "^4.8.0",
Expand Down
186 changes: 186 additions & 0 deletions ElectronJS/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
const http = require('http');
const querystring = require('querystring');
const url = require('url');
const fs = require('fs');
const path=require('path');
function travel(dir,callback){
fs.readdirSync(dir).forEach((file)=>{
const pathname=path.join(dir,file)
if(fs.statSync(pathname).isDirectory()){
travel(pathname,callback)
}else{
callback(pathname)
}
})
}

exports.start = function(port = 8074) {
http.createServer(function(req, res) {
let body = "";
res.setHeader("Access-Control-Allow-Origin", "*"); // 设置可访问的源
res.writeHead(200, { 'Content-Type': 'application/json' });
req.on('data', function(chunk) {
body += chunk;
});
req.on('end', function() {
// 解析参数
const pathName = url.parse(req.url).pathname;
// 设置响应头部信息及编码
if (pathName == "/queryTasks") { //查询所有服务信息,只包括id和服务名称
output = [];
travel(path.join(__dirname, "tasks"),function(pathname){
const data = fs.readFileSync(pathname, 'utf8');
// parse JSON string to JSON object
const task = JSON.parse(data);
let item = {
"id": task.id,
"name": task.name,
"url": task.url,
}
if(item.id!= -2) {
output.push(item);
}
});
res.write(JSON.stringify(output));
res.end();
} else if (pathName == "/queryExecutionInstances") { //查询所有服务信息,只包括id和服务名称
output = [];
travel(path.join(__dirname, "execution_instances"),function(pathname){
const data = fs.readFileSync(pathname, 'utf8');
// parse JSON string to JSON object
const task = JSON.parse(data);
let item = {
"id": task.id,
"name": task.name,
"url": task.url,
}
if(item.id!= -2) {
output.push(item);
}
});
res.write(JSON.stringify(output));
res.end();
} else if (pathName == "/queryTask") {
var params = url.parse(req.url, true).query;
try {
var tid = parseInt(params.id);
const data = fs.readFileSync(path.join(__dirname, `tasks/${tid}.json`), 'utf8');
// parse JSON string to JSON object
res.write(data);
res.end();
} catch (error) {
res.write(JSON.stringify({ "error": "Cannot find task based on specified task ID." }));
res.end();
}
} else if (pathName == "/queryExecutionInstance") {
var params = url.parse(req.url, true).query;
try {
var tid = parseInt(params.id);
const data = fs.readFileSync(path.join(__dirname, `execution_instances/${tid}.json`), 'utf8');
// parse JSON string to JSON object
res.write(data);
res.end();
} catch (error) {
res.write(JSON.stringify({ "error": "Cannot find execution instance based on specified execution ID." }));
res.end();
}
} else if(pathName == "/"){
res.write("Hello World!", 'utf8');
res.end();
} else if(pathName == "/deleteTask"){
var params = url.parse(req.url, true).query;
try {
let tid = parseInt(params.id);
let data = fs.readFileSync(path.join(__dirname, `tasks/${tid}.json`), 'utf8');
data = JSON.parse(data);
data.id = -2;
data = JSON.stringify(data);
// write JSON string to a file
fs.writeFile(path.join(__dirname, `tasks/${tid}.json`), data, (err) => {
if (err) {
throw err;
}
});
res.write(JSON.stringify({ "success": "Task has been deleted successfully." }));
res.end();
} catch (error) {
res.write(JSON.stringify({ "error": "Cannot find task based on specified task ID." }));
res.end();
}
} else if(pathName == "/manageTask"){
body = querystring.parse(body);
data = JSON.parse(body.paras);
let id = data["id"];
if (data["id"] == -1) {
file_names = [];
fs.readdirSync(path.join(__dirname, "tasks")).forEach((file)=>{
try{
file_names.push(parseInt(file.split(".")[0]));
} catch (error) {

}
})
if(file_names.length == 0){
id = 0;
} else {
id = Math.max(...file_names) + 1;
}
data["id"] = id;
// write JSON string to a fil
}
data = JSON.stringify(data);
// write JSON string to a file
fs.writeFile(path.join(__dirname, `tasks/${id}.json`), data, (err) => {});
res.write(id.toString(), 'utf8');
res.end();
} else if(pathName == "/invokeTask"){
body = querystring.parse(body);
let data = JSON.parse(body.paras);
let id = body.id;
let task = fs.readFileSync(path.join(__dirname, `tasks/${id}.json`), 'utf8');
task = JSON.parse(task);
try{
task["links"] = data["urlList_0"];
}catch(error){
console.log(error);
}
for (const [key, value] of Object.entries(data)) {
for (let i = 0; i < task["inputParameters"].length; i++) {
if (key === task["inputParameters"][i]["name"]) { // 能调用
const nodeId = parseInt(task["inputParameters"][i]["nodeId"]);
const node = task["graph"][nodeId];
if (node["option"] === 1) {
node["parameters"]["links"] = value;
} else if (node["option"] === 4) {
node["parameters"]["value"] = value;
} else if (node["option"] === 8 && node["parameters"]["loopType"] === 0) {
node["parameters"]["exitCount"] = parseInt(value);
} else if (node["option"] === 8) {
node["parameters"]["textList"] = value;
}
break;
}
}
}
let file_names = [];
fs.readdirSync(path.join(__dirname, "execution_instances")).forEach((file)=>{
try{
file_names.push(parseInt(file.split(".")[0]));
} catch (error) {

}
})
let eid = 0;
if (file_names.length != 0) {
eid = Math.max(...file_names) + 1;
}
task["id"] = eid;
task = JSON.stringify(task);
fs.writeFile(path.join(__dirname, `execution_instances/${eid}.json`), task, (err) => {});
res.write(eid.toString(), 'utf8');
res.end();
}
});
}).listen(port);
console.log("Server has started.");
}
Loading

0 comments on commit 820c1a2

Please sign in to comment.