mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
bbe9f9a620
Add script to delete deleted-project data from filestore GitOrigin-RevId: 9a2c5861edddf5ed26fc684257369fac4cf95475
41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
const readline = require('readline')
|
|
const { Project } = require('../app/src/models/Project')
|
|
const FileStoreHandler = require('../app/src/Features/FileStore/FileStoreHandler')
|
|
const { DeletedProject } = require('../app/src/models/DeletedProject')
|
|
|
|
/* eslint-disable no-console */
|
|
|
|
async function deleteFiles() {
|
|
const rl = readline.createInterface({
|
|
input: process.stdin
|
|
})
|
|
|
|
for await (const projectId of rl) {
|
|
try {
|
|
const projectCount = await Project.count({ _id: projectId }).exec()
|
|
if (projectCount > 0) {
|
|
throw new Error('found an existing project - refusing')
|
|
}
|
|
const count = await DeletedProject.count({
|
|
'deleterData.deletedProjectId': projectId,
|
|
project: { $ne: null }
|
|
}).exec()
|
|
if (count > 0) {
|
|
throw new Error('found an existing deleted project - refusing')
|
|
}
|
|
await FileStoreHandler.promises.deleteProject(projectId)
|
|
console.error(projectId, 'OK')
|
|
} catch (err) {
|
|
console.error(projectId, 'ERROR', err.name, err.message)
|
|
}
|
|
}
|
|
}
|
|
|
|
deleteFiles()
|
|
.then(() => {
|
|
process.exit(0)
|
|
})
|
|
.catch(err => {
|
|
console.log('Aiee, something went wrong!', err)
|
|
process.exit(1)
|
|
})
|