From 5d5bcee6a665e80432165a5790c754ecae8b32e3 Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Tue, 7 Nov 2023 16:41:04 +0100 Subject: [PATCH] Do not flatten deep objects Signed-off-by: Louis Chemineau --- src/store/files.js | 8 +------- src/utils/fileUtils.js | 10 +++++----- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/store/files.js b/src/store/files.js index e9ac283f9..634aefc60 100644 --- a/src/store/files.js +++ b/src/store/files.js @@ -50,13 +50,7 @@ const mutations = { } if (file.fileid >= 0) { - file.metadataPhotosSize = {} - if (file.width && file.height) { - file.metadataPhotosSize.width = file.width - file.metadataPhotosSize.height = file.height - } else { - file.metadataPhotosSize = { width: 256, height: 256 } - } + file.metadataPhotosSize ??= { width: 256, height: 256 } } // Make the fileId a string once and for all. diff --git a/src/utils/fileUtils.js b/src/utils/fileUtils.js index e76670934..8454323fa 100644 --- a/src/utils/fileUtils.js +++ b/src/utils/fileUtils.js @@ -103,7 +103,7 @@ const sortCompare = function(fileInfo1, fileInfo2, key, asc = true) { * @param {object} obj - object to flatten and format. */ function genFileInfo(obj) { - const fileInfo = flattenAndFormatObject(obj, genFileInfo) + const fileInfo = flattenAndFormatObject(obj, flattenAndFormatObject) if (fileInfo.filename) { // Adding context @@ -117,19 +117,19 @@ function genFileInfo(obj) { * @param {object} obj - object to flatten and format. */ function extractTagInfo(obj) { - return flattenAndFormatObject(obj, extractTagInfo) + return flattenAndFormatObject(obj, flattenAndFormatObject) } /** * - * @param obj - * @param callback + * @param {object} obj + * @param {Function|null} callback */ function flattenAndFormatObject(obj, callback) { return Object.entries(obj).reduce((resultObj, [key, data]) => { // flatten object if any if (!!data && typeof data === 'object' && !Array.isArray(data)) { - return { ...resultObj, ...callback(data) } + return { ...resultObj, ...(callback ? callback(data) : { [camelcase(key)]: data }) } } // format key and add it to the tagInfo