Returns the translators hash on Connector ping.
Part of zotero/zotero-connectors#452
This commit is contained in:
parent
969031a374
commit
f4284a3579
2 changed files with 22 additions and 2 deletions
|
@ -1686,7 +1686,7 @@ Zotero.Server.Connector.Ping.prototype = {
|
||||||
* Sends 200 and HTML status on GET requests
|
* Sends 200 and HTML status on GET requests
|
||||||
* @param data {Object} request information defined in connector.js
|
* @param data {Object} request information defined in connector.js
|
||||||
*/
|
*/
|
||||||
init: function (req) {
|
init: async function (req) {
|
||||||
if (req.method == 'GET') {
|
if (req.method == 'GET') {
|
||||||
return [200, "text/html", '<!DOCTYPE html><html>'
|
return [200, "text/html", '<!DOCTYPE html><html>'
|
||||||
+ '<body>Zotero is running</body></html>'];
|
+ '<body>Zotero is running</body></html>'];
|
||||||
|
@ -1696,11 +1696,13 @@ Zotero.Server.Connector.Ping.prototype = {
|
||||||
//Zotero.debug("Setting active URL to " + req.data.activeURL);
|
//Zotero.debug("Setting active URL to " + req.data.activeURL);
|
||||||
Zotero.QuickCopy.lastActiveURL = req.data.activeURL;
|
Zotero.QuickCopy.lastActiveURL = req.data.activeURL;
|
||||||
}
|
}
|
||||||
|
let translatorsHash = await Zotero.Translators.getTranslatorsHash();
|
||||||
|
|
||||||
let response = {
|
let response = {
|
||||||
prefs: {
|
prefs: {
|
||||||
automaticSnapshots: Zotero.Prefs.get('automaticSnapshots'),
|
automaticSnapshots: Zotero.Prefs.get('automaticSnapshots'),
|
||||||
googleDocsAddNoteEnabled: true
|
googleDocsAddNoteEnabled: true,
|
||||||
|
translatorsHash
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (Zotero.QuickCopy.hasSiteSettings()) {
|
if (Zotero.QuickCopy.hasSiteSettings()) {
|
||||||
|
|
|
@ -39,6 +39,8 @@ Zotero.Translators = new function() {
|
||||||
this.TRANSLATOR_ID_NOTE_HTML = '897a81c2-9f60-4bec-ae6b-85a5030b8be5';
|
this.TRANSLATOR_ID_NOTE_HTML = '897a81c2-9f60-4bec-ae6b-85a5030b8be5';
|
||||||
this.TRANSLATOR_ID_RDF = '5e3ad958-ac79-463d-812b-a86a9235c28f';
|
this.TRANSLATOR_ID_RDF = '5e3ad958-ac79-463d-812b-a86a9235c28f';
|
||||||
|
|
||||||
|
this._translatorsHash = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes translator cache, loading all translator metadata into memory
|
* Initializes translator cache, loading all translator metadata into memory
|
||||||
*
|
*
|
||||||
|
@ -266,6 +268,7 @@ Zotero.Translators = new function() {
|
||||||
|
|
||||||
this.reinit = async function (options = {}) {
|
this.reinit = async function (options = {}) {
|
||||||
await this.init(Object.assign({}, options, { reinit: true }));
|
await this.init(Object.assign({}, options, { reinit: true }));
|
||||||
|
this._translatorsHash = null;
|
||||||
await Zotero.QuickCopy.init();
|
await Zotero.QuickCopy.init();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -326,6 +329,21 @@ Zotero.Translators = new function() {
|
||||||
throw new Error("Invalid or missing translator metadata JSON object in " + OS.Path.basename(path));
|
throw new Error("Invalid or missing translator metadata JSON object in " + OS.Path.basename(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a hash of all translators (to check whether Connector needs an update)
|
||||||
|
*/
|
||||||
|
this.getTranslatorsHash = async function () {
|
||||||
|
if (this._translatorsHash) return this._translatorsHash;
|
||||||
|
await this.init();
|
||||||
|
const translators = await this.getAll();
|
||||||
|
let hashString = "";
|
||||||
|
for (let translator of translators) {
|
||||||
|
hashString += `${translator.translatorID}:${translator.lastUpdated},`;
|
||||||
|
}
|
||||||
|
this._translatorsHash = Zotero.Utilities.Internal.md5(hashString);
|
||||||
|
return this._translatorsHash;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the translator that corresponds to a given ID
|
* Gets the translator that corresponds to a given ID
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue