fix: clearing (#367)
+ added convenient clear-temp script, no flags yet
This commit is contained in:
parent
61b2eff6a4
commit
fd2746c2d0
4 changed files with 36 additions and 2 deletions
|
@ -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",
|
||||
|
|
|
@ -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
28
src/scripts/clear-temp.ts
Normal 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();
|
|
@ -50,4 +50,9 @@ export default defineConfig([
|
|||
outDir: 'dist/scripts',
|
||||
...opts,
|
||||
},
|
||||
{
|
||||
entryPoints: ['src/scripts/clear-temp.ts'],
|
||||
outDir: 'dist/scripts',
|
||||
...opts,
|
||||
},
|
||||
]);
|
||||
|
|
Loading…
Reference in a new issue