Skip to content

Commit

Permalink
Rm Link header if ajax request to TG fails, for #308
Browse files Browse the repository at this point in the history
  • Loading branch information
machawk1 committed Oct 12, 2020
1 parent 3e0522f commit 2969ad7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
21 changes: 21 additions & 0 deletions mink-plugin/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ function displayUIBasedOnContext () {
case 3: link header, datetime
*/
for (let headerI = 0; headerI < headers.length; headerI++) {
// First line: previously deleting attribute (link header) leaves null
if (headers[headerI] == null) { continue }
if (headers[headerI].name.toLowerCase() === 'memento-datetime') {
mementoDateTimeHeader = headers[headerI].value
} else if (headers[headerI].name.toLowerCase() === 'link') {
Expand Down Expand Up @@ -344,6 +346,25 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.method === 'showViewingMementoInterface') {
log('We will show the "return to live web" interface but it is not implemented yet')
}

if (request.method === 'clearLinkHeaderAndDisplayUI') {
// This occurs when a previous attempt to fetch a TimeGate specified in a Link header fails but allows
// some funcitonality to proceed instead of failing hard. See #308
chrome.storage.local.get('headers', function (storedHeaders) {
let headers = storedHeaders.headers[document.URL]
console.log(storedHeaders)
for (let header in headers) {
if (headers[header].name.toUpperCase() == 'LINK') {
delete headers[header]
break
}
}
storedHeaders.headers[document.URL] = headers

chrome.storage.local.set(storedHeaders, displayUIBasedOnContext)

})
}
})

function getMementos (uri) {
Expand Down
7 changes: 6 additions & 1 deletion mink-plugin/mink.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ function createTimemapFromURI (uri, tabId, accumulatedArrayOfTimemaps) {
// Put them in the cache and tell content to display the ui
setTimemapInStorage(firstTm, firstTm.original)
// Send two messages first stop animation then display stored
// If use displayUIBasedOnContext the correctly gotten items wont be display
// If use displayUIBasedOnContext the correctly gotten items will not be display
// Rather we will ask memgator.cs for mementos
chrome.tabs.sendMessage(tabId, { 'method': 'stopAnimatingBrowserActionIcon' })
chrome.tabs.sendMessage(tabId, {
Expand Down Expand Up @@ -558,6 +558,11 @@ function findTMURI (uri, tabid) {
log(`Querying the tm ${uri} failed`, xhr, status, err)

// TODO: Reject this request for invalidity, progress with next option (e.g., query aggregator)
// Perhaps clear this value from localStorage and send a message with the method displayUI
chrome.tabs.sendMessage(tabid, {
'method': 'clearLinkHeaderAndDisplayUI'
})


// Promise.reject('Error querying URI specified in Link header')
})
Expand Down

0 comments on commit 2969ad7

Please sign in to comment.