oa助手类工具
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

61 lines
1.8 KiB

const { Notification } = require('electron')
var http = require("http");
var querystring = require("querystring");
var url = require("url");
const path = require('path')
const libdata = require(path.join(__dirname, 'data.js'));
exports.start = function () {
http.createServer(function (request, response) {
var pathname = url.parse(request.url).pathname;
if (HttpMap[pathname]) {
HttpMap[pathname](request, response)
} else {
response.end("请求未定义");
}
}).listen(37188);
}
HttpMap = {
"/commit": function (request, response) {
let query = querystring.parse(url.parse(request.url).query);
let branch = query["branch"];
let commit = query["commit"];
if (!branch || !commit) {
console.log([branch, commit]);
response.end("error");
return;
}
let branchSplit = branch.split("-");
let commitSplit = commit.split(" ");
if (branchSplit.length < 2 || commitSplit.length < 2) {
console.log([branch, commit, "error"]);
response.end("error");
return;
}
let id = branchSplit[0];
let hash = commitSplit.shift();
commit = commitSplit.join(" ");
if (commit[0] == '-' || commit[0] == '#') {
console.log([branch, commit, "skip commit"]);
(new Notification({
title: "有一条新的提交被忽略",
body: `分支:${branch} 提交内容:${commit}`
})).show()
response.end("skip commit");
return;
}
libdata.AddCommitToQueue({
id: id,
branch: branch,
hash: hash,
commit: commit,
});
console.log([branch, commit, "success"]);
response.end("success");
}
}