Download missing attachments as needed even in at-sync-time mode
This commit is contained in:
parent
3a2f0e6929
commit
9202ab8b3c
|
@ -4123,8 +4123,7 @@ var ZoteroPane = new function()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!item.isImportedAttachment()
|
if (!item.isImportedAttachment()
|
||||||
|| (!Zotero.Sync.Storage.Local.getEnabledForLibrary(item.libraryID)
|
|| !Zotero.Sync.Storage.Local.getEnabledForLibrary(item.libraryID)) {
|
||||||
|| !Zotero.Sync.Storage.Local.downloadAsNeeded(item.libraryID))) {
|
|
||||||
this.showAttachmentNotFoundDialog(itemID, noLocateOnMissing);
|
this.showAttachmentNotFoundDialog(itemID, noLocateOnMissing);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,56 +177,59 @@ describe("ZoteroPane", function() {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should download an attachment on-demand", function* () {
|
it("should download an attachment on-demand", function* () {
|
||||||
yield setup();
|
for (let fn of ['downloadAsNeeded', 'downloadOnSync']) {
|
||||||
Zotero.Sync.Storage.Local.downloadAsNeeded(Zotero.Libraries.userLibraryID, true);
|
yield setup();
|
||||||
|
|
||||||
var item = new Zotero.Item("attachment");
|
Zotero.Sync.Storage.Local[fn](Zotero.Libraries.userLibraryID, true);
|
||||||
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 item = new Zotero.Item("attachment");
|
||||||
var md5 = Zotero.Utilities.Internal.md5(text)
|
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 s3Path = `pretend-s3/${item.key}`;
|
var mtime = "1441252524000";
|
||||||
this.httpd.registerPathHandler(
|
var md5 = Zotero.Utilities.Internal.md5(text)
|
||||||
`/users/1/items/${item.key}/file`,
|
|
||||||
{
|
var s3Path = `pretend-s3/${item.key}`;
|
||||||
handle: function (request, response) {
|
this.httpd.registerPathHandler(
|
||||||
response.setStatusLine(null, 302, "Found");
|
`/users/1/items/${item.key}/file`,
|
||||||
response.setHeader("Zotero-File-Modification-Time", mtime, false);
|
{
|
||||||
response.setHeader("Zotero-File-MD5", md5, false);
|
handle: function (request, response) {
|
||||||
response.setHeader("Zotero-File-Compressed", "No", false);
|
response.setStatusLine(null, 302, "Found");
|
||||||
response.setHeader("Location", baseURL + s3Path, false);
|
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(
|
||||||
this.httpd.registerPathHandler(
|
"/" + s3Path,
|
||||||
"/" + s3Path,
|
{
|
||||||
{
|
handle: function (request, response) {
|
||||||
handle: function (request, response) {
|
response.setStatusLine(null, 200, "OK");
|
||||||
response.setStatusLine(null, 200, "OK");
|
response.write(text);
|
||||||
response.write(text);
|
}
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
);
|
|
||||||
|
|
||||||
// Disable loadURI() so viewAttachment() doesn't trigger translator loading
|
// Disable loadURI() so viewAttachment() doesn't trigger translator loading
|
||||||
var stub = sinon.stub(zp, "loadURI");
|
var stub = sinon.stub(zp, "loadURI");
|
||||||
|
|
||||||
yield zp.viewAttachment(item.id);
|
yield zp.viewAttachment(item.id);
|
||||||
|
|
||||||
assert.ok(stub.calledOnce);
|
assert.ok(stub.calledOnce);
|
||||||
assert.ok(stub.calledWith(OS.Path.toFileURI(item.getFilePath())));
|
assert.ok(stub.calledWith(OS.Path.toFileURI(item.getFilePath())));
|
||||||
stub.restore();
|
stub.restore();
|
||||||
|
|
||||||
assert.equal((yield item.attachmentHash), md5);
|
assert.equal((yield item.attachmentHash), md5);
|
||||||
assert.equal((yield item.attachmentModificationTime), mtime);
|
assert.equal((yield item.attachmentModificationTime), mtime);
|
||||||
var path = yield item.getFilePathAsync();
|
var path = yield item.getFilePathAsync();
|
||||||
assert.equal((yield Zotero.File.getContentsAsync(path)), text);
|
assert.equal((yield Zotero.File.getContentsAsync(path)), text);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user