From 15a0f3bbe3f93074b2d5a046cec06b201c5a8543 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 18 Jun 2017 08:42:39 -0400 Subject: [PATCH] Add getKeys() method to API Client --- .../zotero/xpcom/sync/syncAPIClient.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/chrome/content/zotero/xpcom/sync/syncAPIClient.js b/chrome/content/zotero/xpcom/sync/syncAPIClient.js index 03b5c95ad2..4e302dcbf0 100644 --- a/chrome/content/zotero/xpcom/sync/syncAPIClient.js +++ b/chrome/content/zotero/xpcom/sync/syncAPIClient.js @@ -164,6 +164,35 @@ Zotero.Sync.APIClient.prototype = { }), + getKeys: async function (libraryType, libraryTypeID, queryParams) { + var params = { + libraryType: libraryType, + libraryTypeID: libraryTypeID, + format: 'keys' + }; + if (queryParams) { + for (let i in queryParams) { + params[i] = queryParams[i]; + } + } + + // TODO: Use pagination + var uri = this.buildRequestURI(params); + + var options = { + successCodes: [200, 304] + }; + var xmlhttp = await this.makeRequest("GET", uri, options); + if (xmlhttp.status == 304) { + return false; + } + return { + libraryVersion: this._getLastModifiedVersion(xmlhttp), + keys: xmlhttp.responseText.trim().split(/\n/).filter(key => key) + }; + }, + + /** * Return a promise for a JS object with object keys as keys and version * numbers as values. By default, returns all objects in the library.