Download missing attachments as needed even in at-sync-time mode
This commit is contained in:
parent
3a2f0e6929
commit
9202ab8b3c
2 changed files with 52 additions and 50 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue