Use API version 2
This commit is contained in:
parent
e86cda2440
commit
fe3ad1883d
3 changed files with 11 additions and 6 deletions
|
@ -40,6 +40,7 @@ Zotero.HTTP = new function() {
|
||||||
* <li>cookieSandbox - The sandbox from which cookies should be taken</li>
|
* <li>cookieSandbox - The sandbox from which cookies should be taken</li>
|
||||||
* <li>debug - Log response text and status code</li>
|
* <li>debug - Log response text and status code</li>
|
||||||
* <li>dontCache - If set, specifies that the request should not be fulfilled from the cache</li>
|
* <li>dontCache - If set, specifies that the request should not be fulfilled from the cache</li>
|
||||||
|
* <li>headers - HTTP headers to include in the request</li>
|
||||||
* <li>responseType - The type of the response. See XHR 2 documentation for legal values</li>
|
* <li>responseType - The type of the response. See XHR 2 documentation for legal values</li>
|
||||||
* <li>responseCharset - The charset the response should be interpreted as</li>
|
* <li>responseCharset - The charset the response should be interpreted as</li>
|
||||||
* <li>successCodes - HTTP status codes that are considered successful</li>
|
* <li>successCodes - HTTP status codes that are considered successful</li>
|
||||||
|
|
|
@ -27,6 +27,9 @@
|
||||||
Zotero.Sync.Storage.ZFS = (function () {
|
Zotero.Sync.Storage.ZFS = (function () {
|
||||||
var _rootURI;
|
var _rootURI;
|
||||||
var _userURI;
|
var _userURI;
|
||||||
|
var _headers = {
|
||||||
|
"Zotero-API-Version" : ZOTERO_CONFIG.API_VERSION
|
||||||
|
};
|
||||||
var _cachedCredentials = false;
|
var _cachedCredentials = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,7 +41,7 @@ Zotero.Sync.Storage.ZFS = (function () {
|
||||||
function getStorageFileInfo(item) {
|
function getStorageFileInfo(item) {
|
||||||
var funcName = "Zotero.Sync.Storage.ZFS.getStorageFileInfo()";
|
var funcName = "Zotero.Sync.Storage.ZFS.getStorageFileInfo()";
|
||||||
|
|
||||||
return Zotero.HTTP.promise("GET", getItemInfoURI(item), { successCodes: [200, 404] })
|
return Zotero.HTTP.promise("GET", getItemInfoURI(item), { successCodes: [200, 404], headers: _headers })
|
||||||
.then(function (req) {
|
.then(function (req) {
|
||||||
if (req.status == 404) {
|
if (req.status == 404) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -232,7 +235,7 @@ Zotero.Sync.Storage.ZFS = (function () {
|
||||||
body += "&zip=1";
|
body += "&zip=1";
|
||||||
}
|
}
|
||||||
|
|
||||||
return Zotero.HTTP.promise("POST", uri, { body: body, debug: true })
|
return Zotero.HTTP.promise("POST", uri, { body: body, headers: _headers, debug: true })
|
||||||
.then(function (req) {
|
.then(function (req) {
|
||||||
if (!req.responseXML) {
|
if (!req.responseXML) {
|
||||||
throw new Error("Invalid response retrieving file upload parameters");
|
throw new Error("Invalid response retrieving file upload parameters");
|
||||||
|
@ -508,7 +511,7 @@ Zotero.Sync.Storage.ZFS = (function () {
|
||||||
var body = "update=" + uploadKey + "&mtime=" + item.attachmentModificationTime;
|
var body = "update=" + uploadKey + "&mtime=" + item.attachmentModificationTime;
|
||||||
|
|
||||||
// Register upload on server
|
// Register upload on server
|
||||||
return Zotero.HTTP.promise("POST", uri, { body: body, successCodes: [204] })
|
return Zotero.HTTP.promise("POST", uri, { body: body, headers: _headers, successCodes: [204] })
|
||||||
.then(function (req) {
|
.then(function (req) {
|
||||||
updateItemFileInfo(item);
|
updateItemFileInfo(item);
|
||||||
return {
|
return {
|
||||||
|
@ -886,7 +889,7 @@ Zotero.Sync.Storage.ZFS = (function () {
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return Zotero.HTTP.promise("GET", lastSyncURI,
|
return Zotero.HTTP.promise("GET", lastSyncURI,
|
||||||
{ debug: true, successCodes: [200, 404] });
|
{ headers: _headers, successCodes: [200, 404], debug: true });
|
||||||
})
|
})
|
||||||
.then(function (req) {
|
.then(function (req) {
|
||||||
// Not yet synced
|
// Not yet synced
|
||||||
|
@ -929,7 +932,7 @@ Zotero.Sync.Storage.ZFS = (function () {
|
||||||
|
|
||||||
var lastSyncURI = this._getLastSyncURI(libraryID);
|
var lastSyncURI = this._getLastSyncURI(libraryID);
|
||||||
|
|
||||||
return Zotero.HTTP.promise("POST", lastSyncURI, { debug: true, successCodes: [200, 404] })
|
return Zotero.HTTP.promise("POST", lastSyncURI, { headers: _headers, successCodes: [200, 404], debug: true })
|
||||||
.then(function (req) {
|
.then(function (req) {
|
||||||
// Not yet synced
|
// Not yet synced
|
||||||
//
|
//
|
||||||
|
@ -987,7 +990,7 @@ Zotero.Sync.Storage.ZFS = (function () {
|
||||||
// TODO: move to root uri
|
// TODO: move to root uri
|
||||||
uri.spec += "?auth=1";
|
uri.spec += "?auth=1";
|
||||||
|
|
||||||
return Zotero.HTTP.promise("GET", uri).
|
return Zotero.HTTP.promise("GET", uri, { headers: _headers }).
|
||||||
then(function (req) {
|
then(function (req) {
|
||||||
Zotero.debug("Credentials are cached");
|
Zotero.debug("Credentials are cached");
|
||||||
_cachedCredentials = true;
|
_cachedCredentials = true;
|
||||||
|
|
|
@ -33,6 +33,7 @@ const ZOTERO_CONFIG = {
|
||||||
WWW_BASE_URL: 'http://www.zotero.org/',
|
WWW_BASE_URL: 'http://www.zotero.org/',
|
||||||
SYNC_URL: 'https://sync.zotero.org/',
|
SYNC_URL: 'https://sync.zotero.org/',
|
||||||
API_URL: 'https://api.zotero.org/',
|
API_URL: 'https://api.zotero.org/',
|
||||||
|
API_VERSION: 2,
|
||||||
PREF_BRANCH: 'extensions.zotero.',
|
PREF_BRANCH: 'extensions.zotero.',
|
||||||
BOOKMARKLET_URL: 'https://www.zotero.org/bookmarklet/',
|
BOOKMARKLET_URL: 'https://www.zotero.org/bookmarklet/',
|
||||||
VERSION: "3.1a1.SOURCE"
|
VERSION: "3.1a1.SOURCE"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue