fix: clearing (#367)

+ added convenient clear-temp script, no flags yet
This commit is contained in:
Jayvin Hernandez 2023-04-11 18:37:38 -07:00 committed by GitHub
parent 61b2eff6a4
commit fd2746c2d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 2 deletions

View file

@ -24,7 +24,8 @@
"scripts:list-users": "node --enable-source-maps dist/scripts/list-users",
"scripts:set-user": "node --enable-source-maps dist/scripts/set-user",
"scripts:clear-zero-byte": "node --enable-source-maps dist/scripts/clear-zero-byte",
"scripts:query-size": "node --enable-source-maps dist/scripts/query-size"
"scripts:query-size": "node --enable-source-maps dist/scripts/query-size",
"scripts:clear-temp": "node --enable-source-maps dist/scripts/clear-temp"
},
"dependencies": {
"@emotion/react": "^11.10.6",

View file

@ -6,7 +6,7 @@ const logger = Logger.get('admin');
async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
try {
const { datasource, orphaned } = req.body;
const { orphaned } = req.body;
if (orphaned) {
const { count } = await prisma.file.deleteMany({
where: {

28
src/scripts/clear-temp.ts Normal file
View file

@ -0,0 +1,28 @@
import config from 'lib/config';
import { readdir, rm } from 'fs/promises';
import { join } from 'path';
import { existsSync } from 'fs';
async function main() {
const temp = config.core.temp_directory;
if (!existsSync(temp)) {
console.log('Temp directory does not exist, exiting..');
process.exit(0);
}
const files = (await readdir(temp)).filter((x) => x.startsWith('zipline_partial_'));
if (files.length === 0) {
console.log('No partial files found, exiting..');
process.exit(0);
} else {
for (const file of files) {
console.log(`Deleting ${file}`);
await rm(join(temp, file));
}
console.log('Done!');
process.exit(0);
}
}
main();

View file

@ -50,4 +50,9 @@ export default defineConfig([
outDir: 'dist/scripts',
...opts,
},
{
entryPoints: ['src/scripts/clear-temp.ts'],
outDir: 'dist/scripts',
...opts,
},
]);