commit 9202ab8b3c08228cadadb492de5bfe1a1f0dc94c
parent 3a2f0e69295d4d4a742ed4c973f54b1fa8c0fefd
Author: Dan Stillman <dstillman@zotero.org>
Date: Fri, 11 Aug 2017 16:05:02 +0200
Download missing attachments as needed even in at-sync-time mode
Diffstat:
2 files changed, 52 insertions(+), 50 deletions(-)
diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js
@@ -4123,8 +4123,7 @@ var ZoteroPane = new function()
}
else {
if (!item.isImportedAttachment()
- || (!Zotero.Sync.Storage.Local.getEnabledForLibrary(item.libraryID)
- || !Zotero.Sync.Storage.Local.downloadAsNeeded(item.libraryID))) {
+ || !Zotero.Sync.Storage.Local.getEnabledForLibrary(item.libraryID)) {
this.showAttachmentNotFoundDialog(itemID, noLocateOnMissing);
return;
}
diff --git a/test/tests/zoteroPaneTest.js b/test/tests/zoteroPaneTest.js
@@ -177,56 +177,59 @@ describe("ZoteroPane", function() {
})
it("should download an attachment on-demand", function* () {
- yield setup();
- Zotero.Sync.Storage.Local.downloadAsNeeded(Zotero.Libraries.userLibraryID, true);
-
- var item = new Zotero.Item("attachment");
- item.attachmentLinkMode = 'imported_file';
- item.attachmentPath = 'storage:test.txt';
- // TODO: Test binary data
- var text = Zotero.Utilities.randomString();
- item.attachmentSyncState = "to_download";
- yield item.saveTx();
-
- var mtime = "1441252524000";
- var md5 = Zotero.Utilities.Internal.md5(text)
-
- var s3Path = `pretend-s3/${item.key}`;
- this.httpd.registerPathHandler(
- `/users/1/items/${item.key}/file`,
- {
- handle: function (request, response) {
- response.setStatusLine(null, 302, "Found");
- response.setHeader("Zotero-File-Modification-Time", mtime, false);
- response.setHeader("Zotero-File-MD5", md5, false);
- response.setHeader("Zotero-File-Compressed", "No", false);
- response.setHeader("Location", baseURL + s3Path, false);
+ for (let fn of ['downloadAsNeeded', 'downloadOnSync']) {
+ yield setup();
+
+ Zotero.Sync.Storage.Local[fn](Zotero.Libraries.userLibraryID, true);
+
+ var item = new Zotero.Item("attachment");
+ item.attachmentLinkMode = 'imported_file';
+ item.attachmentPath = 'storage:test.txt';
+ // TODO: Test binary data
+ var text = Zotero.Utilities.randomString();
+ item.attachmentSyncState = "to_download";
+ yield item.saveTx();
+
+ var mtime = "1441252524000";
+ var md5 = Zotero.Utilities.Internal.md5(text)
+
+ var s3Path = `pretend-s3/${item.key}`;
+ this.httpd.registerPathHandler(
+ `/users/1/items/${item.key}/file`,
+ {
+ handle: function (request, response) {
+ response.setStatusLine(null, 302, "Found");
+ response.setHeader("Zotero-File-Modification-Time", mtime, false);
+ response.setHeader("Zotero-File-MD5", md5, false);
+ response.setHeader("Zotero-File-Compressed", "No", false);
+ response.setHeader("Location", baseURL + s3Path, false);
+ }
}
- }
- );
- this.httpd.registerPathHandler(
- "/" + s3Path,
- {
- handle: function (request, response) {
- response.setStatusLine(null, 200, "OK");
- response.write(text);
+ );
+ this.httpd.registerPathHandler(
+ "/" + s3Path,
+ {
+ handle: function (request, response) {
+ response.setStatusLine(null, 200, "OK");
+ response.write(text);
+ }
}
- }
- );
-
- // Disable loadURI() so viewAttachment() doesn't trigger translator loading
- var stub = sinon.stub(zp, "loadURI");
-
- yield zp.viewAttachment(item.id);
-
- assert.ok(stub.calledOnce);
- assert.ok(stub.calledWith(OS.Path.toFileURI(item.getFilePath())));
- stub.restore();
-
- assert.equal((yield item.attachmentHash), md5);
- assert.equal((yield item.attachmentModificationTime), mtime);
- var path = yield item.getFilePathAsync();
- assert.equal((yield Zotero.File.getContentsAsync(path)), text);
+ );
+
+ // Disable loadURI() so viewAttachment() doesn't trigger translator loading
+ var stub = sinon.stub(zp, "loadURI");
+
+ yield zp.viewAttachment(item.id);
+
+ assert.ok(stub.calledOnce);
+ assert.ok(stub.calledWith(OS.Path.toFileURI(item.getFilePath())));
+ stub.restore();
+
+ assert.equal((yield item.attachmentHash), md5);
+ assert.equal((yield item.attachmentModificationTime), mtime);
+ var path = yield item.getFilePathAsync();
+ assert.equal((yield Zotero.File.getContentsAsync(path)), text);
+ }
})
})