Skip to content

Commit

Permalink
Add template to switch aggregator for #367
Browse files Browse the repository at this point in the history
  • Loading branch information
machawk1 committed Oct 14, 2024
1 parent 6019e2f commit 31ec85c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions mink-plugin/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function setActiveBasedOnIgnorelistedProperty (cb) {
})
}

// TODO: refine the acronym in this function's signature. Beware the axe murderer.
function normalDisplayUIBC (items) {
const hasATimeMapInCache = items.timemaps && items.timemaps[document.URL]

Expand Down
23 changes: 15 additions & 8 deletions mink-plugin/mink.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function log (...messages) {
}

function logWithTrace (...messages) {
log(messages)
log(...messages)
console.log('Stack Trace:')
console.log(new Error().stack)
console.trace()
Expand Down Expand Up @@ -255,14 +255,16 @@ chrome.runtime.onMessage.addListener(
// TODO: get value of submitid from AIS interface
submissionURI = 'archive.is/submit/'
method = 'POST'
data = { coo: '', url: request.urir }
data = {coo: '', url: request.urir}
}

// TODO: XHR to fetch for MV3 implementation incomplete below
(async function () {
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 @@ -303,14 +305,16 @@ async function fetchTimeMap (uri, tabid) {

fetch(uri)
.then(response => {
log('Fetching complete, proceeding')
log('Fetch responses received, proceeding')
const status_code = response.status
if (status_code == 404) {
throw new ZeroMementos(`No mementos for {uri}`)
} else if (status_code == 504) {
throw new InaccessibleAggregator(`Aggregator at {uri} reported a {status_code} status code`)
} else {
log(`Status code: ${status_code}`)
}
return console.log(status_code) || response
return response
})
.then(response => {
return response.json()
Expand All @@ -331,15 +335,18 @@ async function fetchTimeMap (uri, tabid) {
setTimemapInStorage(data, data.original)
})
.catch(function(err) {
logWithTrace(`Error fetching ${uri}`)
// console.log(err.message)
logWithTrace(`Something with the response from ${uri} is not as expected...`)

if (err.name === 'ZeroMementos') {
showInterfaceForZeroMementos(tabid)
} else if (err.name === 'InaccessibleAggregator') {
log('TODO: switch up the aggregator')
logWithTrace('TODO: switch up the aggregator')
} else if (err instanceof SyntaxError) {
log("JSON parsing failed, switch up the aggregator")
logWithTrace("JSON parsing failed, switch up the aggregator")
log(`Previous aggregator: {aggregator}`)
chrome.tabs.sendMessage(tabid, {
method: 'tryNextAggregator'
})
}
})
/*
Expand Down

0 comments on commit 31ec85c

Please sign in to comment.