sync: sync upstream code

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2019-07-20 22:19:06 +08:00
parent b05a00f87d
commit a981ccbcae
7 changed files with 126 additions and 42 deletions

View File

@@ -28,9 +28,9 @@ ContenTypeMap["wav"] = "audio/wav";
ContenTypeMap["mp3"] = "audio/mpeg";
ContenTypeMap["mp4"] = "video/mp4";
ContenTypeMap["ico"] = "image/vnd.microsoft.icon";
ContenTypeMap["jpg"] = "image/jpeg";
ContenTypeMap["png"] = "image/png";
ContenTypeMap["gif"] = "image/gif";
ContenTypeMap["jpg"] = "image/jpeg";
ContenTypeMap["html"] = "text/html";
ContenTypeMap["txt"] = "text/plain";
ContenTypeMap["csv"] = "text/csv";
@@ -41,7 +41,6 @@ ContenTypeMap["pdf"] = "application/pdf";
ContenTypeMap["exe"] = "application/octet-stream";
ContenTypeMap["msi"] = "application/octet-stream";
ContenTypeMap["woff"] = "application/font-woff";
ContenTypeMap[".js"] = "application/javascript";
ContenTypeMap["html"] = "text/html";
ContenTypeMap["psd"] = "application/octet-stream";
global.HTTPCaller = {};
@@ -1358,7 +1357,11 @@ function SendWebFile(response, name?, StrCookie?, bParsing?) {
var type = name.substr(name.length - 4, 4);
if (type.substr(0, 1) === ".")
type = type.substr(1);
var Path = "./" + name;
var Path;
if (name.substr(0, 2) !== "./")
Path = "./" + name;
else
Path = name;
if (!fs.existsSync(Path)) {
if (type === "ico") {
response.writeHead(404, { 'Content-Type': 'text/html' });
@@ -1386,7 +1389,12 @@ function SendWebFile(response, name?, StrCookie?, bParsing?) {
data = GetFileHTMLWithParsing(Path);
response.end(data);
return;
}
} else
if ("image/jpeg,image/vnd.microsoft.icon,image/svg+xml,image/png,application/javascript,text/css,text/html".indexOf(StrContentType) > - 1) {
response.end(GetFileSimpleBin(Path));
return;
}
const stream = fs.createReadStream(Path);
setTimeout(function() {
stream.close();
@@ -1477,6 +1485,16 @@ function GetFileSimple(Path) {
return data;
};
function GetFileSimpleBin(Path) {
var Key = "GetFileSimpleBin-" + Path;
var data = global.SendHTMLMap[Key];
if (!data) {
data = (fs.readFileSync(Path));
global.SendHTMLMap[Key] = data;
}
return data;
};
function SaveFileSimple(Path, Str) {
global.SendHTMLMap = {};
var Key = "GetFileSimple-" + Path;
@@ -1490,6 +1508,13 @@ global.GetFileHTMLFromMarkdown = GetFileHTMLFromMarkdown;
global.GetFileSimple = GetFileSimple;
global.SaveFileSimple = SaveFileSimple;
function ReloaSenddBufer() {
global.SendHTMLMap = {};
};
setInterval(ReloaSenddBufer, 60 * 1000);
if (global.DEV_MODE)
setInterval(ReloaSenddBufer, 1 * 1000);
function GetStrTime(now) {
if (!now)
now = global.GetCurrentTime(0);
@@ -1752,6 +1777,7 @@ function GetEventArray(SmartNum, Context) {
return ArrRet;
};
global.HTTPCaller.GetHashRate = function(ArrParams) {
var AllReadCount = 0;
var CurBlockNum = global.GetCurrentBlockNumByTime();
var ResArr = [];
for (var i = 0; i < ArrParams.length; i++) {
@@ -1774,9 +1800,7 @@ global.HTTPCaller.GetHashRate = function(ArrParams) {
var StepDelta = Math.floor(Delta / Count);
if (StepDelta < 1)
StepDelta = 1;
var CountAvg = 10;
if (i === ArrParams.length - 1)
CountAvg = 3;
var CountAvg = 3;
var StepDeltaAvg = Math.floor(StepDelta / CountAvg);
if (StepDeltaAvg < 1)
StepDeltaAvg = 1;
@@ -1791,8 +1815,10 @@ global.HTTPCaller.GetHashRate = function(ArrParams) {
var Sum = 0;
var CountSum = 0;
for (var d = 0; d < CountAvg; d++) {
var Block = global.SERVER.ReadBlockHeaderDB(Num + d);
var Block = global.SERVER.ReadBlockHeaderFromMapDB(Num + d * StepDeltaAvg);
if (Block) {
if (!Block.FromMap)
AllReadCount++;
CountSum++;
Sum += global.GetPowPower(Block.PowHash);
}