diff --git a/chrome/content/zotero/xpcom/data/dataObject.js b/chrome/content/zotero/xpcom/data/dataObject.js index 4bc9423c48..a3f12309ab 100644 --- a/chrome/content/zotero/xpcom/data/dataObject.js +++ b/chrome/content/zotero/xpcom/data/dataObject.js @@ -1335,10 +1335,10 @@ Zotero.DataObject.prototype.toResponseJSON = function (options = {}) { href: Zotero.URI.toAPIURL(uri, options.apiURL), type: 'application/json' }, - alternate: { + alternate: Zotero.Users.getCurrentUserID() ? { href: Zotero.URI.toWebURL(uri), type: 'text/html' - } + } : undefined }, meta: {}, data: this.toJSON(options) diff --git a/chrome/content/zotero/xpcom/data/library.js b/chrome/content/zotero/xpcom/data/library.js index a1dcd74f2a..24884a9013 100644 --- a/chrome/content/zotero/xpcom/data/library.js +++ b/chrome/content/zotero/xpcom/data/library.js @@ -136,7 +136,7 @@ Zotero.defineProperty(Zotero.Library.prototype, 'libraryTypeID', { get: function () { switch (this._libraryType) { case 'user': - return Zotero.Users.getCurrentUserID(); + return Zotero.Users.getCurrentUserID() || 0; case 'group': return Zotero.Groups.getGroupIDFromLibraryID(this._libraryID); @@ -689,10 +689,10 @@ Zotero.Library.prototype.toResponseJSON = function (options = {}) { href: Zotero.URI.toAPIURL(uri, options.apiURL), type: 'application/json' }, - alternate: { + alternate: Zotero.Users.getCurrentUserID() ? { href: Zotero.URI.toWebURL(uri), type: 'text/html' - } + } : undefined } }; }; diff --git a/chrome/content/zotero/xpcom/data/tags.js b/chrome/content/zotero/xpcom/data/tags.js index 8da35248bd..c1d1702924 100644 --- a/chrome/content/zotero/xpcom/data/tags.js +++ b/chrome/content/zotero/xpcom/data/tags.js @@ -253,10 +253,10 @@ Zotero.Tags = new function() { href: Zotero.URI.toAPIURL(uri), type: 'application/json' }, - alternate: { + alternate: Zotero.Users.getCurrentUserID() ? { href: uri, // No toWebURL - match dataserver behavior type: 'text/html' - } + } : undefined }, meta: { type: tag.type || 0, diff --git a/chrome/content/zotero/xpcom/localAPI/server_localAPI.js b/chrome/content/zotero/xpcom/localAPI/server_localAPI.js index 674e613616..f9f5a09e13 100644 --- a/chrome/content/zotero/xpcom/localAPI/server_localAPI.js +++ b/chrome/content/zotero/xpcom/localAPI/server_localAPI.js @@ -101,7 +101,12 @@ class LocalAPIEndpoint { if (userID !== undefined && userID != 0 && userID != Zotero.Users.getCurrentUserID()) { - return this.makeResponse(400, 'text/plain', 'Only data for the logged-in user is available locally - use userID 0'); + let suffix = ""; + let currentUserID = Zotero.Users.getCurrentUserID(); + if (currentUserID) { + suffix += " or " + currentUserID; + } + return this.makeResponse(400, 'text/plain', 'Only data for the logged-in user is available locally -- use userID 0' + suffix); } requestData.libraryID = requestData.pathParams.groupID @@ -273,10 +278,11 @@ class LocalAPIEndpoint { } } - // alternate: cut off '/api/', replace userID 0 with current user's ID - links.alternate = ZOTERO_CONFIG.WWW_BASE_URL - + requestData.pathname.substring(5) + // alternate: only include if logged in, cut off '/api/', replace userID 0 with current userID + if (Zotero.Users.getCurrentUserID()) { + links.alternate = ZOTERO_CONFIG.WWW_BASE_URL + requestData.pathname.substring(5) .replace('users/0/', `users/${Zotero.Users.getCurrentUserID()}/`); + } return links; } diff --git a/chrome/content/zotero/xpcom/uri.js b/chrome/content/zotero/xpcom/uri.js index 1fcf85c791..766c743808 100644 --- a/chrome/content/zotero/xpcom/uri.js +++ b/chrome/content/zotero/xpcom/uri.js @@ -359,7 +359,10 @@ Zotero.URI = new function () { if (!apiURL) { apiURL = ZOTERO_CONFIG.API_URL; } - return uri.replace(ZOTERO_CONFIG.BASE_URI, apiURL); + return uri + .replace(ZOTERO_CONFIG.BASE_URI, apiURL) + // Replace local user key with users/0 + .replace(/(http:\/\/localhost:\d+\/api\/users)\/local\/\w+/, '$1/0'); }; /**