@@ -21,14 +21,14 @@ const MP4_AUDIO_BITRATE = process.env.MP4_AUDIO_BITRATE || '128k'
2121const MIN_SAVINGS_PCT = Number ( process . env . MEDIA_MIN_SAVINGS_PCT || '5' )
2222const SKIP_SMALL_KB = Number ( process . env . MEDIA_SKIP_SMALL_KB || '256' )
2323
24- function bytesToMiB ( bytes ) {
24+ function bytesToMiB ( bytes ) {
2525 return ( bytes / 1024 / 1024 ) . toFixed ( 2 )
2626}
2727
28- function runFfmpeg ( args ) {
28+ function runFfmpeg ( args ) {
2929 const result = spawnSync ( 'ffmpeg' , args , {
3030 stdio : 'inherit' ,
31- windowsHide : true ,
31+ windowsHide : true
3232 } )
3333 if ( result . error ) {
3434 throw result . error
@@ -38,7 +38,7 @@ function runFfmpeg(args) {
3838 }
3939}
4040
41- function isFileExists ( filePath ) {
41+ function isFileExists ( filePath ) {
4242 try {
4343 fsSync . accessSync ( filePath )
4444 return true
@@ -47,29 +47,29 @@ function isFileExists(filePath) {
4747 }
4848}
4949
50- async function ensureDir ( dirPath ) {
50+ async function ensureDir ( dirPath ) {
5151 await fs . mkdir ( dirPath , { recursive : true } )
5252}
5353
54- async function cleanDir ( dirPath ) {
54+ async function cleanDir ( dirPath ) {
5555 await fs . rm ( dirPath , { recursive : true , force : true } )
5656 await ensureDir ( dirPath )
5757}
5858
59- async function * walkFiles ( dirPath ) {
59+ async function * walkFiles ( dirPath ) {
6060 if ( ! isFileExists ( dirPath ) ) return
6161 const entries = await fs . readdir ( dirPath , { withFileTypes : true } )
6262 for ( const entry of entries ) {
6363 const fullPath = path . join ( dirPath , entry . name )
6464 if ( entry . isDirectory ( ) ) {
65- yield * walkFiles ( fullPath )
65+ yield * walkFiles ( fullPath )
6666 } else if ( entry . isFile ( ) ) {
6767 yield fullPath
6868 }
6969 }
7070}
7171
72- async function optimizeOne ( { inputPath, inputBaseDir, outputBaseDir } ) {
72+ async function optimizeOne ( { inputPath, inputBaseDir, outputBaseDir } ) {
7373 const relPath = path . relative ( inputBaseDir , inputPath )
7474 const outputPath = path . join ( outputBaseDir , relPath )
7575
@@ -111,7 +111,7 @@ async function optimizeOne({ inputPath, inputBaseDir, outputBaseDir }) {
111111 MP3_BITRATE ,
112112 '-id3v2_version' ,
113113 '3' ,
114- tmpPath ,
114+ tmpPath
115115 ] )
116116 } else {
117117 // Re-encode MP4 (H.264 + AAC) and enable faststart
@@ -133,7 +133,7 @@ async function optimizeOne({ inputPath, inputBaseDir, outputBaseDir }) {
133133 MP4_AUDIO_BITRATE ,
134134 '-movflags' ,
135135 '+faststart' ,
136- tmpPath ,
136+ tmpPath
137137 ] )
138138 }
139139
@@ -151,12 +151,12 @@ async function optimizeOne({ inputPath, inputBaseDir, outputBaseDir }) {
151151 return { changed : true , reason : 'optimized' , before : stat . size , after : outStat . size , outputPath }
152152}
153153
154- function checkFfmpegAvailable ( ) {
154+ function checkFfmpegAvailable ( ) {
155155 const result = spawnSync ( 'ffmpeg' , [ '-version' ] , { stdio : 'ignore' , windowsHide : true } )
156156 return result . status === 0
157157}
158158
159- async function main ( ) {
159+ async function main ( ) {
160160 if ( ! checkFfmpegAvailable ( ) ) {
161161 console . error ( '[optimize:media] ffmpeg not found in PATH.' )
162162 console . error ( 'Install ffmpeg and ensure `ffmpeg` is available in your terminal, then re-run.' )
@@ -167,7 +167,7 @@ async function main() {
167167 const targets = [
168168 { inputDir : SRC_AUDIO_DIR , outputDir : OUT_AUDIO_DIR } ,
169169 { inputDir : SRC_VIDEO_DIR , outputDir : OUT_VIDEO_DIR } ,
170- { inputDir : SRC_PUBLIC_AUDIO_DIR , outputDir : OUT_PUBLIC_AUDIO_DIR } ,
170+ { inputDir : SRC_PUBLIC_AUDIO_DIR , outputDir : OUT_PUBLIC_AUDIO_DIR }
171171 ]
172172
173173 let changedCount = 0
@@ -188,7 +188,7 @@ async function main() {
188188 const result = await optimizeOne ( {
189189 inputPath,
190190 inputBaseDir : target . inputDir ,
191- outputBaseDir : target . outputDir ,
191+ outputBaseDir : target . outputDir
192192 } )
193193 if ( result . changed ) {
194194 changedCount += 1
0 commit comments