Don't clear md5/mtime in item JSON if skipped in patch mode
The client skips synced storage properties (md5, mtime) when uploading items to ZFS-enabled libraries, but since the API returns JSON with those values included after writes, they do get saved to the sync cache. If the local attachment is then modified and the client generates a diff from the cached version with those properties skipped, they'll be included in the patch JSON as empty strings in order to clear them. This changes Zotero.Item::toJSON() to skip those properties in patch mode as well. This fixes a sync error ("Cannot change 'md5' directly in group library") when a group attachment is updated locally.
This commit is contained in:
parent
c29b7eb06c
commit
9ba3745b94
2 changed files with 28 additions and 1 deletions
|
@ -4237,7 +4237,12 @@ Zotero.Item.prototype.toJSON = function (options = {}) {
|
|||
obj.dateModified = Zotero.Date.sqlToISO8601(this.dateModified);
|
||||
}
|
||||
|
||||
return this._postToJSON(env);
|
||||
var json = this._postToJSON(env);
|
||||
if (options.skipStorageProperties) {
|
||||
delete json.md5;
|
||||
delete json.mtime;
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1192,6 +1192,28 @@ describe("Zotero.Item", function () {
|
|||
var json = note.toJSON({ patchBase });
|
||||
assert.isFalse(json.parentItem);
|
||||
});
|
||||
|
||||
it("shouldn't clear storage properties from original in .skipStorageProperties mode", function* () {
|
||||
var item = new Zotero.Item('attachment');
|
||||
item.attachmentLinkMode = 'imported_file';
|
||||
item.attachmentFilename = 'test.txt';
|
||||
item.attachmentContentType = 'text/plain';
|
||||
item.attachmentCharset = 'utf-8';
|
||||
item.attachmentSyncedModificationTime = 1234567890000;
|
||||
item.attachmentSyncedHash = '18d21750c8abd5e3afa8ea89e3dfa570';
|
||||
var patchBase = item.toJSON({
|
||||
syncedStorageProperties: true
|
||||
});
|
||||
item.setNote("Test");
|
||||
var json = item.toJSON({
|
||||
patchBase,
|
||||
skipStorageProperties: true
|
||||
});
|
||||
Zotero.debug(json);
|
||||
assert.equal(json.note, "Test");
|
||||
assert.notProperty(json, "md5");
|
||||
assert.notProperty(json, "mtime");
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue