diff --git a/chrome/content/zotero/xpcom/reader.js b/chrome/content/zotero/xpcom/reader.js index 7013f01e62..4814912e47 100644 --- a/chrome/content/zotero/xpcom/reader.js +++ b/chrome/content/zotero/xpcom/reader.js @@ -146,6 +146,7 @@ class ReaderInstance { buf = new Uint8Array(buf).buffer; let annotationItems = this._item.getAnnotations(); let annotations = (await Promise.all(annotationItems.map(x => this._getAnnotation(x)))).filter(x => x); + let resourceBaseURI = `zotero://attachment/${Zotero.API.getLibraryPrefix(this._item.libraryID)}/items/${this._item.key}/`; // TODO: Remove after some time // Migrate Mendeley colors to Zotero PDF reader colors @@ -189,6 +190,7 @@ class ReaderInstance { type: this._type, buf: new Uint8Array(buf), annotations, + resourceBaseURI, primaryViewState: state, secondaryViewState: secondViewState, location, diff --git a/components/zotero-protocol-handler.js b/components/zotero-protocol-handler.js index 9366fb4551..8ad9fc1e0d 100644 --- a/components/zotero-protocol-handler.js +++ b/components/zotero-protocol-handler.js @@ -57,14 +57,18 @@ function ZoteroProtocolHandler() { /** - * zotero://attachment/library/[itemKey] - * zotero://attachment/groups/[groupID]/[itemKey] + * zotero://attachment/library/items/[itemKey] + * zotero://attachment/groups/[groupID]/items/[itemKey] + * + * And for snapshot attachments only: + * zotero://attachment/library/items/[itemKey]/[resourcePath] + * zotero://attachment/groups/[groupID]/items/[itemKey]/[resourcePath] */ var AttachmentExtension = { loadAsChrome: false, - newChannel: function (uri) { - return new AsyncChannel(uri, function* () { + newChannel: function (uri, loadInfo) { + return new AsyncChannel(uri, loadInfo, function* () { try { var uriPath = uri.pathQueryRef; if (!uriPath) { @@ -100,6 +104,26 @@ function ZoteroProtocolHandler() { return this._errorChannel(`${path} not found`); } + var resourcePathParts = uriPath.split('/') + .slice(params.groupID !== undefined ? 4 : 3) + .filter(Boolean); + if (resourcePathParts.length) { + if (!item.isSnapshotAttachment()) { + return this._errorChannel(`Item for ${uriPath} is not a snapshot attachment -- cannot access resources`); + } + + try { + path = PathUtils.join(PathUtils.parent(path), ...resourcePathParts); + } + catch (e) { + Zotero.logError(e); + return this._errorChannel(`Resource ${resourcePathParts.join('/')} not found`); + } + if (!(yield IOUtils.exists(path))) { + return this._errorChannel(`Resource ${resourcePathParts.join('/')} not found`); + } + } + // Set originalURI so that it seems like we're serving from zotero:// protocol. // This is necessary to allow url() links to work from within CSS files. // Otherwise they try to link to files on the file:// protocol, which isn't allowed.