Local API: Attachment size fixes (#4270)
- Don't fail on missing attachment - Get size of main file only - Include best-attachment `attachmentSize` for parent items
This commit is contained in:
parent
5d197e4b12
commit
3363cb448a
1 changed files with 17 additions and 1 deletions
|
@ -5517,6 +5517,21 @@ Zotero.Item.prototype.toResponseJSON = function (options = {}) {
|
|||
|
||||
|
||||
Zotero.Item.prototype.toResponseJSONAsync = async function (options = {}) {
|
||||
async function getFileSize(attachment) {
|
||||
let path = attachment.getFilePath();
|
||||
if (path) {
|
||||
try {
|
||||
return (await IOUtils.stat(path)).size;
|
||||
}
|
||||
catch (e) {
|
||||
if (e.name != 'NotFoundError') {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
let json = this.toResponseJSON(options);
|
||||
if (this.isRegularItem()) {
|
||||
let bestAttachment = await this.getBestAttachment();
|
||||
|
@ -5526,10 +5541,11 @@ Zotero.Item.prototype.toResponseJSONAsync = async function (options = {}) {
|
|||
type: 'application/json',
|
||||
attachmentType: bestAttachment.attachmentContentType
|
||||
};
|
||||
json.links.attachment.attachmentSize = await getFileSize(bestAttachment);
|
||||
}
|
||||
}
|
||||
else if (this.isImportedAttachment()) {
|
||||
json.links.enclosure.length = await Zotero.Attachments.getTotalFileSize(this);
|
||||
json.links.enclosure.length = await getFileSize(this);
|
||||
}
|
||||
return json;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue