Skip to content

Commit

Permalink
Merge pull request #245 from CHWYH/wyh_dev
Browse files Browse the repository at this point in the history
feat(config): modify download.js
  • Loading branch information
RobinzZH committed Aug 29, 2018
2 parents 20d37df + f3d031b commit 1499e80
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions bin/tsw/util/auto-report/download.js
Expand Up @@ -253,7 +253,8 @@ const initRequestHar = function (request) {
const responseHeader = unpackRaw((Buffer.from(request.responseHeader || '')).toString('utf8'));


requestHaz.startedDateTime = request.timestamps.ClientConnected;
requestHaz.startedDateTime = (request.timestamps) ? ((request.timestamps && request.timestamps.ClientConnected) || Date.now()) : Date.now();

requestHaz.time = 3000;

requestHaz.request = {
Expand Down Expand Up @@ -354,19 +355,19 @@ const downloadHaz = function (request, response, opt) {
};

if (data.length <= 0) {
failRet(request, response, 'not find log');
failRet(request, response, JSON.stringify({ data: 'not find log' }));

return;
}

if (SNKey && data.SNKeys && data.SNKeys[0] != SNKey) {
failRet(request, response, '该log已经过期,请联系用户慢点刷log~');
failRet(request, response, JSON.stringify({ data: '该log已经过期,请联系用户慢点刷log~' }));

return;
}

if (typeof data === 'string') {
failRet(request, response, 'key类型不对');
failRet(request, response, JSON.stringify({ data: 'key类型不对' }));

return;
}
Expand Down Expand Up @@ -599,11 +600,16 @@ const failRet = function(request, response, msg) {
// chunked decode buffer , 格式 :size +\r\n + rawText +\r\n + 0|r\n , \r\n ====》 13,10, 中间的即为rawText

const decodeChunkedUint8Array = function (Uint8ArrayBuffer) {
const rawText = [];
let rawText = [];
let startOfTheRawText = Uint8ArrayBuffer.indexOf(13);
while (startOfTheRawText !== -1 && startOfTheRawText !== 0) {
const rawTextSizeUint8ArrayBuffer = Uint8ArrayBuffer.slice(0, startOfTheRawText);
const rawTextSizeUint8ArrayBuffer = Uint8ArrayBuffer.slice(0, startOfTheRawText); // 这里取到的应该是 当前chunked size
const rawTextSizeUint8ArrayInt = parseInt(Buffer.from(rawTextSizeUint8ArrayBuffer), 16);
if (Number.isNaN(rawTextSizeUint8ArrayInt)) {
rawText.length = 0;
rawText = [];
break;
}
if (rawTextSizeUint8ArrayInt === 0) {
break;
}
Expand Down

0 comments on commit 1499e80

Please sign in to comment.