mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-04 02:16:49 -05:00
38 lines
765 B
JavaScript
38 lines
765 B
JavaScript
|
export function countFiles(fileTreeData) {
|
||
|
if (!fileTreeData) {
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
const files = filesInFolder(fileTreeData)
|
||
|
|
||
|
// count all the non-deleted entities
|
||
|
const value = files.filter(item => !item.deleted).length
|
||
|
|
||
|
const limit = window.ExposedSettings.maxEntitiesPerProject
|
||
|
const status = fileCountStatus(value, limit, Math.ceil(limit / 20))
|
||
|
|
||
|
return { value, status, limit }
|
||
|
}
|
||
|
|
||
|
function filesInFolder({ docs, folders, fileRefs }) {
|
||
|
const files = [...docs, ...fileRefs]
|
||
|
|
||
|
for (const folder of folders) {
|
||
|
files.push(...filesInFolder(folder))
|
||
|
}
|
||
|
|
||
|
return files
|
||
|
}
|
||
|
|
||
|
function fileCountStatus(value, limit, range) {
|
||
|
if (value >= limit) {
|
||
|
return 'error'
|
||
|
}
|
||
|
|
||
|
if (value >= limit - range) {
|
||
|
return 'warning'
|
||
|
}
|
||
|
|
||
|
return 'success'
|
||
|
}
|