Skip to content
Snippets Groups Projects
Commit 79644864 authored by Phil Höfer's avatar Phil Höfer
Browse files

update refillTokenStash function

parent bc1e09fd
No related branches found
No related tags found
No related merge requests found
......@@ -45,8 +45,13 @@ function updateStorageFromCookies() {sites.forEach((site) => {
// TODO: Collect token if unused
function refillTokenStash(count) { // get count (max 10) tokens and store them in the stash
//console.log("refilling tokens");
/**
* Get count (max 10) tokens and store them in the stash
* @param {number} count
* @returns {boolean} True if successfull, false otherwise.
*/
function refillTokenStash(count) { // TODO: handle count >10
console.log("refilling tokens");
let tokensToBlind = [];
for (let i = 0; i <= Math.min(count,9); i++) {
tokensToBlind.push(uuidv4());
......@@ -131,7 +136,7 @@ async function getTokensPerSearch() {
* Returns the refill threshold size based on the currently saved tokensPerSearch value
* @returns {number}
*/
async function getRefillThresholdSize() {
function getRefillThresholdSize() {
return getTokensPerSearch().then((x) => x*3);
}
......@@ -139,7 +144,7 @@ async function getRefillThresholdSize() {
* Returns the target stash size based on the currently saved tokensPerSearch value
* @returns {number}
*/
async function getTargetStashSize() {
function getTargetStashSize() {
return getTokensPerSearch().then((x) => x*7);
}
......@@ -162,11 +167,12 @@ async function checkTokenStash() {
console.log(activeKey);
let refillThresholdSize = getRefillThresholdSize();
let targetStashSize = getTargetStashSize();
console.log(refillThresholdSize);
if (currentStash > refillThresholdSize) {
return true;
} else if (activeKey) {
return await refillTokenStash(targetStashSize - currentStash.length);
} else {
return refillTokenStash(targetStashSize - currentStash.length);
return false;
}
}
setTimeout(checkTokenStash,10000);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment