2024-10-18 07:04:57 -04:00
|
|
|
import readline from 'readline'
|
|
|
|
import { waitForDb } from '../app/src/infrastructure/mongodb.js'
|
|
|
|
import ProjectEntityHandler from '../app/src/Features/Project/ProjectEntityHandler.js'
|
|
|
|
import ProjectGetter from '../app/src/Features/Project/ProjectGetter.js'
|
|
|
|
import Errors from '../app/src/Features/Errors/Errors.js'
|
2020-05-01 07:42:17 -04:00
|
|
|
|
2020-04-28 09:11:39 -04:00
|
|
|
async function countFiles() {
|
|
|
|
const rl = readline.createInterface({
|
2021-04-27 03:52:58 -04:00
|
|
|
input: process.stdin,
|
2020-04-28 09:11:39 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
for await (const projectId of rl) {
|
|
|
|
try {
|
|
|
|
const project = await ProjectGetter.promises.getProject(projectId)
|
2020-04-29 06:50:34 -04:00
|
|
|
if (!project) {
|
|
|
|
throw new Errors.NotFoundError('project not found')
|
|
|
|
}
|
2022-01-10 05:23:05 -05:00
|
|
|
const { files, docs } =
|
|
|
|
ProjectEntityHandler.getAllEntitiesFromProject(project)
|
2020-04-28 09:11:39 -04:00
|
|
|
console.error(
|
|
|
|
projectId,
|
|
|
|
files.length,
|
2020-04-29 05:48:17 -04:00
|
|
|
(project.deletedFiles && project.deletedFiles.length) || 0,
|
2020-04-28 09:11:39 -04:00
|
|
|
docs.length,
|
2020-04-29 05:48:17 -04:00
|
|
|
(project.deletedDocs && project.deletedDocs.length) || 0
|
2020-04-28 09:11:39 -04:00
|
|
|
)
|
|
|
|
} catch (err) {
|
|
|
|
if (err instanceof Errors.NotFoundError) {
|
|
|
|
console.error(projectId, 'NOTFOUND')
|
|
|
|
} else {
|
2020-05-01 07:42:17 -04:00
|
|
|
console.log(projectId, 'ERROR', err.name, err.message)
|
2020-04-28 09:11:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-18 07:04:57 -04:00
|
|
|
try {
|
|
|
|
await waitForDb()
|
|
|
|
await countFiles()
|
|
|
|
process.exit(0)
|
|
|
|
} catch (error) {
|
|
|
|
console.log('Aiee, something went wrong!', error)
|
|
|
|
process.exit(1)
|
|
|
|
}
|