Skip to content

Commit

Permalink
BugFix
Browse files Browse the repository at this point in the history
  • Loading branch information
davtur19 committed Oct 9, 2019
1 parent bcf441e commit ac6901b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 36 deletions.
70 changes: 38 additions & 32 deletions dotgit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const SLEEP = 150;
const WAIT = 2000;
const MAX_CONNECTIONS = 20;

const WS_SEARCH = /(ws)(s)?:\/\//;
const WS_REPLACE = "http$2://";
Expand Down Expand Up @@ -102,8 +103,9 @@ function startDownload(baseUrl, downloadFinished) {

// make zip
function downloadZip() {
if (running_tasks === 0) {
if (running_tasks === 0 && waiting === 0) {
let zip = new JSZip();
notification("Download status", "Creating zip...");

downloadedFiles.forEach(function (file) {
zip.file(file[0], file[1], {arrayBuffer: true});
Expand All @@ -119,27 +121,32 @@ function startDownload(baseUrl, downloadFinished) {
}
}

let waiting = 0;

function downloadFile(path, decompress, callback) {
if (walkedPaths.includes(path)) {
return;
}

walkedPaths.push(path);
running_tasks++;

fetch(baseUrl + GIT_PATH + path, {
redirect: "manual"
}).then(function (response) {
if (response.ok && response.status === 200) {
fileExist = true;
return response.arrayBuffer();
}
}).catch(function () {
downloadZip();
}).then(function (buffer) {
if (running_tasks > MAX_CONNECTIONS) {
waiting++;
setTimeout(function () {
waiting--;
downloadFile(path, decompress, callback);
}, WAIT);
} else {
walkedPaths.push(path);
running_tasks++;

fetch(baseUrl + GIT_PATH + path, {
redirect: "manual"
}).then(function (response) {
if (response.ok && response.status === 200) {
fileExist = true;
return response.arrayBuffer();
}
running_tasks--;
}).then(function (buffer) {
if (typeof buffer !== "undefined") {
downloadedFiles.push([path, buffer]);
const words = new Uint8Array(buffer);
Expand All @@ -152,12 +159,11 @@ function startDownload(baseUrl, downloadFinished) {
// plaintext file
callback(arrayBufferToString(words));
}
running_tasks--;
}
downloadZip();
}, running_tasks * SLEEP);
}).catch(function () {
downloadZip();
});
});
}
}


Expand Down Expand Up @@ -192,11 +198,12 @@ function startDownload(baseUrl, downloadFinished) {
search.lastIndex++;
}

matches.forEach((match) => {

for (let i = 0; i < matches.length; i++) {
// make object path and download
let path = GIT_OBJECTS_PATH + match.slice(0, 2) + "/" + match.slice(2);
let path = GIT_OBJECTS_PATH + matches[i].slice(0, 2) + "/" + matches[i].slice(2);
downloadFile(path, true, checkResult);
});
}
}
}

Expand All @@ -211,14 +218,14 @@ function startDownload(baseUrl, downloadFinished) {
search.lastIndex++;
}

matches.forEach((match) => {
let pathExt = GIT_PACK_PATH + match + GIT_PACK_EXT;
let pathIdx = GIT_PACK_PATH + match + GIT_IDX_EXT;
downloadFile(pathExt, false, function (a) {
for (let i = 0; i < matches.length; i++) {
let pathExt = GIT_PACK_PATH + matches[i] + GIT_PACK_EXT;
let pathIdx = GIT_PACK_PATH + matches[i] + GIT_IDX_EXT;
downloadFile(pathExt, false, function () {
});
downloadFile(pathIdx, false, function (a) {
downloadFile(pathIdx, false, function () {
});
});
}
}
}

Expand All @@ -230,9 +237,9 @@ function startDownload(baseUrl, downloadFinished) {
}

// start download from well know paths
GIT_WELL_KNOW_PATHS.forEach(function (path) {
downloadFile(path, false, checkResult);
});
for (let i = 0; i < GIT_WELL_KNOW_PATHS.length; i++) {
downloadFile(GIT_WELL_KNOW_PATHS[i], false, checkResult);
}
}


Expand Down Expand Up @@ -260,7 +267,6 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
notification("Download status", "Failed to download " + request.url + "\nNo files found");
sendResponse({status: false});
}
chrome.notifications.create(notification);
});
}

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "DotGit",
"version": "3.1",
"version": "3.2",
"description": "An extension to check if .git is exposed in visited websites",
"icons": {
"48": "icons/dotgit-48.png",
Expand Down
4 changes: 1 addition & 3 deletions popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ if (chrome.browserAction.setBadgeText) {
});
// set width for desktop devices
document.addEventListener('DOMContentLoaded', function () {
let test = document.getElementById("hostsFound").style.width = "380px";
console.log(test);
document.getElementById("hostsFound").style.width = "380px";
});
}

Expand Down Expand Up @@ -58,7 +57,6 @@ function addElements(element, array, callback, downloading) {
}
}


document.addEventListener("click", (e) => {
if (e.target.id === "reset") {
chrome.storage.local.set({
Expand Down

0 comments on commit ac6901b

Please sign in to comment.