mirror of
https://github.com/diced/zipline.git
synced 2025-05-10 18:05:54 +02:00
feat: script to add file sizes
This commit is contained in:
parent
38e30b2525
commit
c7df4a578b
4 changed files with 46 additions and 6 deletions
|
@ -23,7 +23,8 @@
|
|||
"scripts:import-dir": "node --enable-source-maps dist/scripts/import-dir",
|
||||
"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:clear-zero-byte": "node --enable-source-maps dist/scripts/clear-zero-byte",
|
||||
"scripts:query-size": "node --enable-source-maps dist/scripts/query-size"
|
||||
},
|
||||
"dependencies": {
|
||||
"@emotion/react": "^11.10.6",
|
||||
|
|
38
src/scripts/query-size.ts
Normal file
38
src/scripts/query-size.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
import { PrismaClient } from '@prisma/client';
|
||||
import config from 'lib/config';
|
||||
import datasource from 'lib/datasource';
|
||||
import { migrations } from 'server/util';
|
||||
|
||||
async function main() {
|
||||
process.env.DATABASE_URL = config.core.database_url;
|
||||
await migrations();
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
const files = await prisma.file.findMany();
|
||||
|
||||
console.log(`The script will attempt to query the size of ${files.length} files.`);
|
||||
|
||||
for (let i = 0; i !== files.length; ++i) {
|
||||
const file = files[i];
|
||||
const size = await datasource.size(file.name);
|
||||
if (size === 0) {
|
||||
console.log(`File ${file.name} has a size of 0 bytes. Ignoring...`);
|
||||
} else {
|
||||
console.log(`File ${file.name} has a size of ${size} bytes. Updating...`);
|
||||
await prisma.file.update({
|
||||
where: {
|
||||
id: file.id,
|
||||
},
|
||||
data: {
|
||||
size,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Done.');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
main();
|
|
@ -25,10 +25,6 @@
|
|||
},
|
||||
"incremental": true
|
||||
},
|
||||
"include": [
|
||||
"next-env.d.ts",
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
],
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
|
||||
"exclude": ["node_modules", "dist", ".yarn", ".next"]
|
||||
}
|
||||
|
|
|
@ -39,4 +39,9 @@ export default defineConfig([
|
|||
outDir: 'dist/scripts',
|
||||
...opts,
|
||||
},
|
||||
{
|
||||
entryPoints: ['src/scripts/query-size.ts'],
|
||||
outDir: 'dist/scripts',
|
||||
...opts,
|
||||
},
|
||||
]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue