Make Zotero.Item::attachmentHash getter asynchronous

This commit is contained in:
Dan Stillman 2015-10-29 02:27:33 -04:00
parent 3fca0644ee
commit 90286d2a50

View file

@ -2751,10 +2751,10 @@ Zotero.defineProperty(Zotero.Item.prototype, 'attachmentModificationTime', {
* Note: This is the hash of the file itself, not the last-known hash * Note: This is the hash of the file itself, not the last-known hash
* of the file on the storage server as stored in the database * of the file on the storage server as stored in the database
* *
* @return {String} MD5 hash of file as hex string * @return {Promise<String>} - MD5 hash of file as hex string
*/ */
Zotero.defineProperty(Zotero.Item.prototype, 'attachmentHash', { Zotero.defineProperty(Zotero.Item.prototype, 'attachmentHash', {
get: function () { get: Zotero.Promise.coroutine(function* () {
if (!this.isAttachment()) { if (!this.isAttachment()) {
return undefined; return undefined;
} }
@ -2763,13 +2763,13 @@ Zotero.defineProperty(Zotero.Item.prototype, 'attachmentHash', {
return undefined; return undefined;
} }
var file = this.getFile(); var path = yield this.getFilePathAsync();
if (!file) { if (!path) {
return undefined; return undefined;
} }
return Zotero.Utilities.Internal.md5(file) || undefined; return Zotero.Utilities.Internal.md5Async(path);
} })
}); });
@ -3894,7 +3894,7 @@ Zotero.Item.prototype.toJSON = Zotero.Promise.coroutine(function* (options = {})
} }
if (this.isFileAttachment()) { if (this.isFileAttachment()) {
obj.md5 = this.attachmentHash; obj.md5 = yield this.attachmentHash;
obj.mtime = yield this.attachmentModificationTime; obj.mtime = yield this.attachmentModificationTime;
} }
} }