File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -3,11 +3,33 @@ const glob = util.promisify(require('glob'));
3
3
const fs = require ( "fs" ) . promises ;
4
4
const path = require ( 'path' ) ;
5
5
6
+ const MAX_FILE_SIZE = 1024 * 1024 ; // 1MB
7
+
8
+ async function checkFileSize ( filePath ) {
9
+ try {
10
+ const stats = await fs . stat ( filePath ) ;
11
+ return stats . size ;
12
+ } catch ( error ) {
13
+ console . error ( `Error checking file size for ${ filePath } : ${ error . message } ` ) ;
14
+ return 0 ;
15
+ }
16
+ }
6
17
7
18
async function main ( ) {
8
19
var errors = [ ] ;
9
20
var directories = await glob ( __dirname + '../../dishes/**/*.md' ) ;
10
21
22
+ // Check all files in dishes directory for size
23
+ var allFiles = await glob ( __dirname + '../../dishes/**/*' ) ;
24
+
25
+ // Check each file size
26
+ for ( var filePath of allFiles ) {
27
+ const fileSize = await checkFileSize ( filePath ) ;
28
+ if ( fileSize > MAX_FILE_SIZE ) {
29
+ errors . push ( `文件 ${ filePath } 超过了1MB大小限制 (${ ( fileSize / 1048576 ) . toFixed ( 2 ) } MB)! 请压缩图片或分割文件。` ) ;
30
+ }
31
+ }
32
+
11
33
for ( var filePath of directories ) {
12
34
var data = await fs . readFile ( filePath , 'utf8' ) ;
13
35
var filename = path . parse ( filePath ) . base . replace ( ".md" , "" ) ;
You can’t perform that action at this time.
0 commit comments