Fix PDF recognition
But leave tests disabled, since they should maybe be mocked?
This commit is contained in:
parent
8a85114c13
commit
7c7ea6a66d
1 changed files with 24 additions and 16 deletions
|
@ -211,7 +211,8 @@ var Zotero_RecognizePDF = new function() {
|
||||||
}
|
}
|
||||||
});*/
|
});*/
|
||||||
var newItems = yield translate.translate({
|
var newItems = yield translate.translate({
|
||||||
libraryID
|
libraryID,
|
||||||
|
saveAttachments: false
|
||||||
});
|
});
|
||||||
if (newItems.length) {
|
if (newItems.length) {
|
||||||
return newItems[0];
|
return newItems[0];
|
||||||
|
@ -394,6 +395,7 @@ var Zotero_RecognizePDF = new function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// put new item in same collections as the old one
|
// put new item in same collections as the old one
|
||||||
|
yield item.loadCollections();
|
||||||
let itemCollections = item.getCollections();
|
let itemCollections = item.getCollections();
|
||||||
for (let i = 0; i < itemCollections.length; i++) {
|
for (let i = 0; i < itemCollections.length; i++) {
|
||||||
let collection = yield Zotero.Collections.getAsync(itemCollections[i]);
|
let collection = yield Zotero.Collections.getAsync(itemCollections[i]);
|
||||||
|
@ -598,8 +600,8 @@ var Zotero_RecognizePDF = new function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
item.deferred.resolve(
|
item.deferred.resolve(
|
||||||
Zotero.Promise.try(getGoodLines, item.lines)
|
Zotero.Promise.try(function () {
|
||||||
.then(function(lines) {
|
var lines = getGoodLines(item.lines);
|
||||||
return queryGoogle(lines, item.libraryID, 3); // Try querying 3 times
|
return queryGoogle(lines, item.libraryID, 3); // Try querying 3 times
|
||||||
})
|
})
|
||||||
.finally(function() { _processQueue(true); })
|
.finally(function() { _processQueue(true); })
|
||||||
|
@ -703,13 +705,15 @@ var Zotero_RecognizePDF = new function() {
|
||||||
}
|
}
|
||||||
Zotero.HTTP.lastGoogleScholarQueryTime = Date.now();
|
Zotero.HTTP.lastGoogleScholarQueryTime = Date.now();
|
||||||
try {
|
try {
|
||||||
try {
|
let xmlhttp = yield Zotero.HTTP.request("GET", url, { "responseType": "document" })
|
||||||
let xmlhttp = yield Zotero.HTTP.promise("GET", url, {"responseType":"document"});
|
.then(
|
||||||
}
|
function (xmlhttp) {
|
||||||
catch (e) {
|
return _checkCaptchaOK(xmlhttp, 3);
|
||||||
yield _checkCaptchaError(e, 3);
|
},
|
||||||
}
|
function (e) {
|
||||||
xmlhttp = yield _checkCaptchaOK(xmlhttp, 3);
|
return _checkCaptchaError(e, 3);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
let doc = xmlhttp.response,
|
let doc = xmlhttp.response,
|
||||||
deferred = Zotero.Promise.defer(),
|
deferred = Zotero.Promise.defer(),
|
||||||
|
@ -768,7 +772,7 @@ var Zotero_RecognizePDF = new function() {
|
||||||
* in order to get CAPTCHA to show up
|
* in order to get CAPTCHA to show up
|
||||||
* @return {Promise} A promise resolved when PDF metadata has been retrieved
|
* @return {Promise} A promise resolved when PDF metadata has been retrieved
|
||||||
*/
|
*/
|
||||||
function _checkCaptchaError(e, tries, dontClearCookies) {
|
var _checkCaptchaError = Zotero.Promise.coroutine(function* (e, tries, dontClearCookies) {
|
||||||
if(stopCheckCallback && stopCheckCallback()) {
|
if(stopCheckCallback && stopCheckCallback()) {
|
||||||
throw new Zotero.Exception.Alert('recognizePDF.stopped');
|
throw new Zotero.Exception.Alert('recognizePDF.stopped');
|
||||||
}
|
}
|
||||||
|
@ -791,13 +795,17 @@ var Zotero_RecognizePDF = new function() {
|
||||||
}
|
}
|
||||||
// Redo GET request
|
// Redo GET request
|
||||||
Zotero.debug("RecognizePDF: Reloading page after clearing cookies.");
|
Zotero.debug("RecognizePDF: Reloading page after clearing cookies.");
|
||||||
return Zotero.HTTP.promise("GET", e.xmlhttp.channel.originalURI.spec, {"responseType":"document"})
|
return Zotero.HTTP.request(
|
||||||
.then(function(xmlhttp) {
|
"GET", e.xmlhttp.channel.originalURI.spec, { "responseType": "document" }
|
||||||
|
)
|
||||||
|
.then(
|
||||||
|
function (xmlhttp) {
|
||||||
return _checkCaptchaOK(xmlhttp, tries);
|
return _checkCaptchaOK(xmlhttp, tries);
|
||||||
},
|
},
|
||||||
function(e) {
|
function (e) {
|
||||||
return _checkCaptchaError(e, tries, true); // Don't try this again
|
return _checkCaptchaError(e, tries, true); // Don't try this again
|
||||||
});
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.debug("RecognizePDF: Google Scholar returned an unexpected page"
|
Zotero.debug("RecognizePDF: Google Scholar returned an unexpected page"
|
||||||
|
@ -805,7 +813,7 @@ var Zotero_RecognizePDF = new function() {
|
||||||
throw new Zotero.Exception.Alert('recognizePDF.limit');
|
throw new Zotero.Exception.Alert('recognizePDF.limit');
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prompt user to enter CPATCHA
|
* Prompt user to enter CPATCHA
|
||||||
|
|
Loading…
Reference in a new issue