Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/photos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorLouis Chemineau <louis@chmn.me>2022-08-24 14:25:23 +0300
committerLouis Chemineau <louis@chmn.me>2022-09-15 18:28:21 +0300
commit5fcd3f992eb28e326792e0a0ebeadf9fba6c0ad9 (patch)
treea1e8a0e8f419e6038afbf51338e81d9d7bf5ee1e /src/utils
parentac8c298b2e01adc736ae29ab14cbc3cb52525fa7 (diff)
Add collaborators management viewsfeat/album_collaborators
Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/fileUtils.js39
1 files changed, 18 insertions, 21 deletions
diff --git a/src/utils/fileUtils.js b/src/utils/fileUtils.js
index daaf7621..9d3c522b 100644
--- a/src/utils/fileUtils.js
+++ b/src/utils/fileUtils.js
@@ -97,29 +97,26 @@ const sortCompare = function(fileInfo1, fileInfo2, key, asc = true) {
: -fileInfo1[key]?.toString()?.localeCompare(fileInfo2[key].toString(), OC.getLanguage()) || -1
}
-const genFileInfo = function(obj) {
- const fileInfo = {}
-
- Object.keys(obj).forEach(key => {
- const data = obj[key]
-
+/**
+ * @param {object} obj - object to flatten and format.
+ */
+function genFileInfo(obj) {
+ return Object.entries(obj).reduce((fileInfo, [key, data]) => {
// flatten object if any
- if (!!data && typeof data === 'object') {
- Object.assign(fileInfo, genFileInfo(data))
- } else {
- // format key and add it to the fileInfo
- if (data === 'false') {
- fileInfo[camelcase(key)] = false
- } else if (data === 'true') {
- fileInfo[camelcase(key)] = true
- } else {
- fileInfo[camelcase(key)] = isNumber(data)
- ? Number(data)
- : data
- }
+ if (!!data && typeof data === 'object' && !Array.isArray(data)) {
+ return { ...fileInfo, ...genFileInfo(data) }
}
- })
- return fileInfo
+
+ // format key and add it to the fileInfo
+ switch (data) {
+ case 'false':
+ return { ...fileInfo, [camelcase(key)]: false }
+ case 'true':
+ return { ...fileInfo, [camelcase(key)]: true }
+ default:
+ return { ...fileInfo, [camelcase(key)]: isNumber(data) ? Number(data) : data }
+ }
+ }, {})
}
export { encodeFilePath, extractFilePaths, sortCompare, genFileInfo }