2024-10-18 07:04:57 -04:00
|
|
|
import {
|
2023-04-18 07:15:34 -04:00
|
|
|
db,
|
|
|
|
READ_PREFERENCE_SECONDARY,
|
2024-10-18 07:04:57 -04:00
|
|
|
} from '../app/src/infrastructure/mongodb.js'
|
|
|
|
import { extname } from 'node:path'
|
2023-02-10 10:13:00 -05:00
|
|
|
|
|
|
|
const FILE_TYPES = [
|
|
|
|
'.jpg',
|
|
|
|
'.jpeg',
|
|
|
|
'.png',
|
|
|
|
'.bmp',
|
|
|
|
'.webp',
|
|
|
|
'.svg',
|
|
|
|
'.pdf',
|
|
|
|
'.eps',
|
|
|
|
'.gif',
|
|
|
|
'.ico',
|
|
|
|
'.tiff',
|
|
|
|
]
|
|
|
|
|
|
|
|
const longestFileType = Math.max(...FILE_TYPES.map(fileType => fileType.length))
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const projects = db.projects.find(
|
|
|
|
{},
|
2023-04-18 07:15:34 -04:00
|
|
|
{
|
|
|
|
projection: { rootFolder: 1 },
|
|
|
|
readPreference: READ_PREFERENCE_SECONDARY,
|
|
|
|
}
|
2023-02-10 10:13:00 -05:00
|
|
|
)
|
|
|
|
let projectsProcessed = 0
|
|
|
|
const result = new Map(FILE_TYPES.map(fileType => [fileType, 0]))
|
|
|
|
for await (const project of projects) {
|
|
|
|
projectsProcessed += 1
|
|
|
|
if (projectsProcessed % 100000 === 0) {
|
|
|
|
console.log(projectsProcessed, 'projects processed')
|
|
|
|
}
|
|
|
|
countFiles(project.rootFolder[0], result)
|
|
|
|
}
|
|
|
|
|
|
|
|
const sortedResults = [...result.entries()].sort(
|
|
|
|
([, countA], [, countB]) => countB - countA
|
|
|
|
)
|
|
|
|
|
|
|
|
sortedResults.forEach(([fileType, count]) => {
|
|
|
|
console.log(
|
|
|
|
`${fileType.padStart(longestFileType, ' ')}: ${count
|
|
|
|
.toString()
|
|
|
|
.padStart(7, ' ')}`
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function countFiles(folder, result) {
|
|
|
|
if (folder.folders) {
|
|
|
|
for (const subfolder of folder.folders) {
|
|
|
|
countFiles(subfolder, result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (folder.fileRefs) {
|
|
|
|
for (const file of folder.fileRefs) {
|
|
|
|
const fileType = extname(file.name).toLowerCase()
|
|
|
|
const current = result.get(fileType)
|
|
|
|
if (current !== undefined) {
|
|
|
|
result.set(fileType, current + 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2024-10-18 07:04:57 -04:00
|
|
|
try {
|
|
|
|
await main()
|
|
|
|
process.exit(0)
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error)
|
|
|
|
process.exit(1)
|
|
|
|
}
|