mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-04 22:55:51 -05:00
aa480a2663
[web] migrate from window attributes to getMeta GitOrigin-RevId: 3dcf1ab6b01155e5e4abeb3e78d0fa9053e055bc
52 lines
1 KiB
JavaScript
52 lines
1 KiB
JavaScript
import getMeta from '@/utils/meta'
|
|
|
|
export function countFiles(fileTreeData) {
|
|
if (!fileTreeData) {
|
|
return 0
|
|
}
|
|
|
|
const value = _countElements(fileTreeData)
|
|
|
|
const limit = getMeta('ol-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'
|
|
}
|
|
|
|
// 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)
|
|
}
|