Skip to content

Commit

Permalink
Add fallthrough aggregator logic for #316 and #367
Browse files Browse the repository at this point in the history
  • Loading branch information
machawk1 committed Oct 14, 2024
1 parent 31ec85c commit aeacb6a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
10 changes: 10 additions & 0 deletions mink-plugin/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ function checkAggregatorHealthAndSet (aggregatorIndex) {

const options = { mode: 'no-cors', signal }

console.log(`Checking the health of aggregator #${aggregatorIndex} at ${memgatorHosts[aggregatorIndex]}`)

return window.fetch(url, options)
.then(setTimeout(() => { aborter.abort(`The request to ${url} timed out and has been aborted`) }, timeout))
.catch(error => {
Expand Down Expand Up @@ -326,6 +328,14 @@ function addToIgnorelist (currentIgnorelist, uriIn) {
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
log(`in listener with ${request.method}`)

if (request.method === 'tryNextAggregator') {
++hostI
checkAggregatorHealthAndSet(hostI)
console.log(`trying again with aggregator ${hostI}`)
getMementos(request.uri)
return
}

if (request.method === 'addToIgnorelist') {
getIgnorelist(addToIgnorelist, request.uri) // And add uri
return
Expand Down
2 changes: 1 addition & 1 deletion mink-plugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"content_security_policy": {
"extension_pages": "script-src 'self'; object-src 'self'"
},
"minimum_chrome_version": "88",
"minimum_chrome_version": "99",
"options_ui": {
"page": "options.html",
"open_in_tab": true
Expand Down
13 changes: 8 additions & 5 deletions mink-plugin/mink.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,6 @@ chrome.runtime.onMessage.addListener(
const resp = await fetch(submissionURI)
changeArchiveIcon(request, response)
})
} else if (request.method === 'tryNextAggregator') {
log('TODO: TRYING NEXT AGGREGATOR')
} else {
log(`Message sent using chrome.runtime not caught: ${request.method}`)
}
Expand Down Expand Up @@ -343,10 +341,11 @@ async function fetchTimeMap (uri, tabid) {
logWithTrace('TODO: switch up the aggregator')
} else if (err instanceof SyntaxError) {
logWithTrace("JSON parsing failed, switch up the aggregator")
log(`Previous aggregator: {aggregator}`)
log(`Previous aggregator endpoint: ${uri}`)
chrome.tabs.sendMessage(tabid, {
method: 'tryNextAggregator'
})
method: 'tryNextAggregator',
uri: uri
}, startAgainWithNewAggregatorTempFunctionName)
}
})
/*
Expand All @@ -361,6 +360,10 @@ async function fetchTimeMap (uri, tabid) {
*/
}

function startAgainWithNewAggregatorTempFunctionName () {
console.log('repeating query logic with a new aggregator')
}

function setBadgeText (value, tabid) {
let badgeValue = value

Expand Down

0 comments on commit aeacb6a

Please sign in to comment.