API version checking
This commit is contained in:
parent
4067a1b820
commit
4dcaf2907f
|
@ -25,7 +25,7 @@
|
|||
|
||||
Zotero.Connector = new function() {
|
||||
const CONNECTOR_URI = "http://127.0.0.1:23119/";
|
||||
const CONNECTOR_SERVER_API_VERSION = 1;
|
||||
const CONNECTOR_API_VERSION = 2;
|
||||
|
||||
this.isOnline = null;
|
||||
|
||||
|
@ -69,8 +69,18 @@ Zotero.Connector = new function() {
|
|||
}
|
||||
|
||||
if(Zotero.Connector.EXCEPTION_CODES.indexOf(req.status) !== -1) {
|
||||
Zotero.debug("Connector: Method "+method+" failed");
|
||||
Zotero.debug("Connector: Method "+method+" failed with status "+req.status);
|
||||
if(callback) callback(false, req.status);
|
||||
|
||||
// Check for incompatible version
|
||||
if(req.status === 404 || req.status === 412) {
|
||||
if(Zotero.Connector_Browser && Zotero.Connector_Browser.onIncompatibleStandaloneVersion) {
|
||||
var standaloneVersion = req.getResponseHeader("X-Zotero-Version");
|
||||
Zotero.Connector_Browser.onIncompatibleStandaloneVersion(Zotero.version, standaloneVersion);
|
||||
throw "Connector: Version mismatch: Connector version "+Zotero.version
|
||||
+", Standalone version "+(standaloneVersion ? standaloneVersion : "<unknown>");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Zotero.debug("Connector: Method "+method+" succeeded");
|
||||
var val = null;
|
||||
|
@ -91,6 +101,10 @@ Zotero.Connector = new function() {
|
|||
var uri = CONNECTOR_URI+"connector/"+method;
|
||||
|
||||
Zotero.HTTP.doPost(uri, JSON.stringify(data),
|
||||
newCallback, {"Content-Type":"application/json"});
|
||||
newCallback, {
|
||||
"Content-Type":"application/json",
|
||||
"X-Zotero-Version":Zotero.version,
|
||||
"X-Zotero-Connector-API-Version":CONNECTOR_API_VERSION
|
||||
});
|
||||
}
|
||||
}
|
|
@ -67,6 +67,10 @@ Zotero.Server = new function() {
|
|||
*/
|
||||
this.generateResponse = function (status, contentType, body) {
|
||||
var response = "HTTP/1.0 "+status+" "+responseCodes[status]+"\r\n";
|
||||
if(!Zotero.isServer) {
|
||||
response += "X-Zotero-Version: "+Zotero.version+"\r\n";
|
||||
response += "X-Zotero-Connector-API-Version: "+CONNECTOR_API_VERSION+"\r\n";
|
||||
}
|
||||
|
||||
if(body) {
|
||||
if(contentType) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
***** BEGIN LICENSE BLOCK *****
|
||||
|
||||
Copyright © 2009 Center for History and New Media
|
||||
Copyright © 2011 Center for History and New Media
|
||||
George Mason University, Fairfax, Virginia, USA
|
||||
http://zotero.org
|
||||
|
||||
|
@ -22,8 +22,7 @@
|
|||
|
||||
***** END LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
const CONNECTOR_SERVER_API_VERSION = 2;
|
||||
const CONNECTOR_API_VERSION = 2;
|
||||
|
||||
Zotero.Server.Connector = function() {};
|
||||
Zotero.Server.Connector._waitingForSelection = {};
|
||||
|
@ -406,4 +405,9 @@ Zotero.Server.Connector.Ping.prototype = {
|
|||
"init":function(postData, sendResponseCallback) {
|
||||
sendResponseCallback(200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// XXX For compatibility with older connectors; to be removed
|
||||
Zotero.Server.Endpoints["/translate/list"] = Zotero.Server.Connector.GetTranslators;
|
||||
Zotero.Server.Endpoints["/translate/save"] = Zotero.Server.Connector.SavePage;
|
Loading…
Reference in New Issue
Block a user