2022-01-10 10:47:01 -05:00
|
|
|
export function countFiles(fileTreeData) {
|
|
|
|
if (!fileTreeData) {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2022-06-08 04:28:46 -04:00
|
|
|
const value = _countElements(fileTreeData)
|
2022-01-10 10:47:01 -05:00
|
|
|
|
|
|
|
const limit = window.ExposedSettings.maxEntitiesPerProject
|
|
|
|
const status = fileCountStatus(value, limit, Math.ceil(limit / 20))
|
|
|
|
|
|
|
|
return { value, status, limit }
|
|
|
|
}
|
|
|
|
|
|
|
|
function fileCountStatus(value, limit, range) {
|
|
|
|
if (value >= limit) {
|
|
|
|
return 'error'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value >= limit - range) {
|
|
|
|
return 'warning'
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'success'
|
|
|
|
}
|
2022-06-08 04:28:46 -04:00
|
|
|
|
|
|
|
// Copied and adapted from ProjectEntityMongoUpdateHandler
|
|
|
|
function _countElements(rootFolder) {
|
|
|
|
function countFolder(folder) {
|
|
|
|
if (folder == null) {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
let total = 0
|
|
|
|
if (folder.folders) {
|
|
|
|
total += folder.folders.length
|
|
|
|
for (const subfolder of folder.folders) {
|
|
|
|
total += countFolder(subfolder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (folder.docs) {
|
|
|
|
total += folder.docs.length
|
|
|
|
}
|
|
|
|
if (folder.fileRefs) {
|
|
|
|
total += folder.fileRefs.length
|
|
|
|
}
|
|
|
|
return total
|
|
|
|
}
|
|
|
|
|
|
|
|
return countFolder(rootFolder)
|
|
|
|
}
|