Skip to content

Commit

Permalink
Add max_failed_in_a_row and bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
davtur19 committed Oct 3, 2020
1 parent 300a589 commit 1b2574a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
25 changes: 22 additions & 3 deletions dotgit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const DEFAULT_OPTIONS = {
"download": {
"wait": 100,
"max_wait": 10000,
"max_connections": 20
"max_connections": 20,
"failed_in_a_row": 250
}
};

Expand Down Expand Up @@ -78,6 +79,7 @@ let notification_download;
let check_git;
let check_svn;
let check_hg;
let failed_in_a_row;


function notification(title, message) {
Expand Down Expand Up @@ -208,7 +210,7 @@ function startDownload(baseUrl, downloadFinished) {
let waiting = 0;
let fileExist = false;
let downloadStats = {};

let failedInARow = 0;
let downloadStatus = {
successful: 0,
failed: 0,
Expand Down Expand Up @@ -255,6 +257,11 @@ function startDownload(baseUrl, downloadFinished) {

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

Expand Down Expand Up @@ -282,10 +289,13 @@ function startDownload(baseUrl, downloadFinished) {
if (response.ok && response.status === 200) {
fileExist = true;
downloadStatus.successful++;
failedInARow = 0;
sendDownloadStatus(baseUrl, downloadStatus);
return response.arrayBuffer();
}
running_tasks--;
downloadStatus.failed++;
failedInARow++;
sendDownloadStatus(baseUrl, downloadStatus);
}).then(function (buffer) {
if (typeof buffer !== "undefined") {
Expand Down Expand Up @@ -389,6 +399,7 @@ function set_options(options) {
wait = options.download.wait;
max_wait = options.download.max_wait;
max_connections = options.download.max_connections;
failed_in_a_row = options.download.failed_in_a_row;
notification_new_git = options.notification.new_git;
notification_download = options.notification.download;
check_git = options.functions.git;
Expand Down Expand Up @@ -463,6 +474,9 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
} else if (request.type === "max_wait") {
max_wait = request.value;
sendResponse({status: true});
} else if (request.type === "failed_in_a_row") {
failed_in_a_row = request.value;
sendResponse({status: true});
} else if (request.type === "reset_options") {
chrome.storage.local.set({options: DEFAULT_OPTIONS});
set_options(DEFAULT_OPTIONS);
Expand All @@ -488,7 +502,7 @@ chrome.storage.local.get(["checked", "withExposedGit", "options"], function (res
chrome.storage.local.set({options: DEFAULT_OPTIONS});
}
// upgrade 3.7.4 => 4.0
if (typeof result.options.functions === "undefined" || typeof result.withExposedGit[0].type === "undefined") {
if (typeof result.options.functions === "undefined" || (typeof result.withExposedGit[0] !== "undefined" && typeof result.withExposedGit[0].type === "undefined")) {
let urls = [];
result.options.functions = DEFAULT_OPTIONS.functions;
result.withExposedGit.forEach(function (url) {
Expand All @@ -497,6 +511,11 @@ chrome.storage.local.get(["checked", "withExposedGit", "options"], function (res
result.withExposedGit = urls;
chrome.storage.local.set({withExposedGit: result.withExposedGit});
}
// upgrade 4.0 => 4.1
if (typeof result.options.download.failed_in_a_row === "undefined") {
result.options.download.failed_in_a_row = DEFAULT_OPTIONS.download.failed_in_a_row;
chrome.storage.local.set({withExposedGit: result.withExposedGit});
}

chrome.storage.local.set({options: checkOptions(DEFAULT_OPTIONS, result.options)});

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": "4.0.2",
"version": "4.1",
"description": "An extension for checking if .git is exposed in visited websites",
"icons": {
"16": "icons/dotgit-16.png",
Expand Down
6 changes: 5 additions & 1 deletion options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@
<section class="option">
<div class="browser-style title-option">
Download<br>
By changing these values the browser may become unstable!<br>
</div>
<div class="browser-style title-option">
<label for="failed_in_a_row">Max failed in a row</label>
<input class="browser-style input-text" type="number" id="failed_in_a_row" min="1" max="1000000"/>
</div>
<div>
By changing the values below, the browser may become unstable!<br>
<a href="https://github.com/davtur19/DotGit/blob/master/README.md#how-the-download-works">
Change them only if you know what you are doing
</a><br><br>
Expand Down
3 changes: 2 additions & 1 deletion options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function set_gui(options) {
document.getElementById("hgOff").checked = !options.functions.hg;
document.getElementById("max_sites").value = options.max_sites;
document.getElementById("max_connections").value = options.download.max_connections;
document.getElementById("failed_in_a_row").value = options.download.failed_in_a_row;
document.getElementById("wait").value = options.download.wait;
document.getElementById("max_wait").value = options.download.max_wait;
document.getElementById("on1").checked = options.notification.new_git;
Expand Down Expand Up @@ -72,7 +73,7 @@ document.addEventListener("DOMContentLoaded", function () {
value: result.options.notification.download
}, function (response) {
});
} else if (e.target.validity.valid === true && (e.target.id === "max_connections" || e.target.id === "wait" || e.target.id === "max_wait")) {
} else if (e.target.validity.valid === true && (e.target.id === "max_connections" || e.target.id === "wait" || e.target.id === "max_wait" || e.target.id === "failed_in_a_row")) {
result.options.download[e.target.id] = e.target.value;
chrome.storage.local.set(result);
chrome.runtime.sendMessage({
Expand Down

0 comments on commit 1b2574a

Please sign in to comment.