Skip to content

Commit bf939ea

Browse files
committed
Revert to using HTTP GET but also fetch for archive.is for #300
1 parent 4635ae0 commit bf939ea

File tree

1 file changed

+22
-42
lines changed

1 file changed

+22
-42
lines changed

mink-plugin/mink.js

+22-42
Original file line numberDiff line numberDiff line change
@@ -244,62 +244,42 @@ chrome.runtime.onMessage.addListener(
244244
let submissionURI
245245
let data = {}
246246
let method = 'GET'
247+
console.log(`sending request to ${request.archive}`)
247248
if (request.archive === 'ia') {
248249
submissionURI = `http://web.archive.org/save/${request.urir}`
249250
method = 'GET'
250251
} else if (request.archive === 'ais') {
251252
// TODO: get value of submitted from AIS interface
252253
submissionURI = 'https://archive.is/submit/'
253-
method = 'post'
254+
method = 'get'
254255
fetchArchiveIsSubmitID().then(submitidExtracted => {
255256
console.log(`Submitted to archive.is with url ${request.urir} and submitid ${submitidExtracted}`)
256-
const data = new FormData()
257-
data.append('submitid', submitidExtracted)
258-
data.append('url', request.urir)
259-
260-
for(let pair of data.entries()) {
261-
console.log(`${pair[0]}: ${pair[1]}`)
262-
}
263-
fetch(submissionURI, {
264-
method: 'POST',
265-
body: data
266-
}).then(
267-
response => response.text()
268-
).then(
269-
html => console.log(html)
257+
submissionURI = `${submissionURI}?url=${request.urir}&submitid=${submitidExtracted}`
258+
259+
window.fetch(submissionURI).then(
260+
response => {
261+
// e.g., https://archive.ph/C2NCh/again?url=https://weiglemc.github.io/
262+
// TODO: trim off everything before /again?
263+
// ?again might only occur when a URL is newly minted, to research
264+
console.log(response.url.split('/again').pop())
265+
// TODO: the call below does not have a properly formed response object
266+
changeArchiveIcon(request, response)
267+
268+
}
270269
)
271-
return
272-
273-
// xhr used instead of fetch bc we need the Content-Location response header
274-
let xhr = new XMLHttpRequest()
275-
xhr.addEventListener('load', readArchiveIsResponse)
276-
xhr.open(method, submissionURI)
277-
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
278-
279-
xhr.send(data)
280-
console.log(xhr)
281-
return
282-
283-
chrome.tabs.query({
284-
active: true,
285-
currentWindow: true
286-
}, function (tabs) {
287-
chrome.tabs.sendMessage(tabs[0].id, {
288-
method: 'archiveDone',
289-
data: xhr.getResponseHeader('Content-Location'),
290-
imgId: request.imgId,
291-
imgURI: request.imgURI,
292-
callback: request.cb,
293-
newTab: request.newTab
294-
})
295-
})
296-
297-
return
298270
})
271+
return
299272
}
273+
// NOTE THAT ARCHIVE.IS changed back from POST to GET but the below still returns a 404 for invalid URI
274+
// maybe escape it?
275+
276+
300277

301278
window.fetch(submissionURI).then(
302279
response => {
280+
console.log('xxx')
281+
console.log(request)
282+
console.log(response)
303283
changeArchiveIcon(request, response)
304284
}
305285
)

0 commit comments

Comments
 (0)