Return up-to-date storage properties, too

This commit is contained in:
Abe Jellinek 2026-05-12 10:20:27 -04:00
parent 68519d5713
commit c05f8a0c48
2 changed files with 21 additions and 17 deletions

View file

@ -5773,24 +5773,21 @@ Zotero.Item.prototype.toJSON = function (options = {}) {
}
if (this.isStoredFileAttachment() && !options.skipStorageProperties) {
if (options.syncedStorageProperties) {
let mtime = this.attachmentSyncedModificationTime;
// There's never a reason to include these if they're null. This can happen if
// we're restoring to server from a copy of the database that was never
// file-synced. We don't want to clear the remote file associations when that
// happens.
if (mtime !== null) {
obj.mtime = mtime;
}
let md5 = this.attachmentSyncedHash;
if (md5 !== null) {
obj.md5 = md5;
}
// Add synced storage properties even if syncedStorageProperties is false,
// since we can't get the local properties synchronously
// We'll overwrite them in toResponseJSONAsync() if possible
let mtime = this.attachmentSyncedModificationTime;
// There's never a reason to include these if they're null. This can happen if
// we're restoring to server from a copy of the database that was never
// file-synced. We don't want to clear the remote file associations when that
// happens.
if (mtime !== null) {
obj.mtime = mtime;
}
else {
// TEMP
//obj.mtime = (yield this.attachmentModificationTime) || null;
//obj.md5 = (yield this.attachmentHash) || null;
let md5 = this.attachmentSyncedHash;
if (md5 !== null) {
obj.md5 = md5;
}
}
}
@ -5935,6 +5932,12 @@ Zotero.Item.prototype.toResponseJSONAsync = async function (options = {}) {
else if (this.isImportedAttachment()) {
json.links.enclosure.length = await getFileSize(this);
}
if (this.isStoredFileAttachment() && !options.skipStorageProperties) {
json.data.mtime = await this.attachmentModificationTime ?? null;
json.data.md5 = await this.attachmentHash ?? null;
}
return json;
};

View file

@ -901,6 +901,7 @@ async function toResponseJSON(dataObjectOrObjects, searchParams) {
? await dataObject.toResponseJSONAsync({
apiURL: `http://localhost:${Zotero.Server.port}/api/`,
includeGroupDetails: true,
syncedStorageProperties: false,
syncedVersionProperty: false,
})
: dataObject;