Skip to content

Commit

Permalink
perf: 提升未下载完全歌曲文件清理速度
Browse files Browse the repository at this point in the history
  • Loading branch information
zonemeen committed Feb 21, 2024
1 parent e1749be commit 8b1f14e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import prettyBytes from 'pretty-bytes'
import { red, green } from 'colorette'
import { pipeline } from 'node:stream/promises'
import { join, basename } from 'node:path'
import { existsSync, mkdirSync, createWriteStream, unlinkSync } from 'node:fs'
import { unlink } from 'node:fs/promises'
import { existsSync, mkdirSync, createWriteStream } from 'node:fs'
import lyricDownload from './services/lyric'
import type { SongInfo } from './types'

Expand Down Expand Up @@ -120,14 +121,12 @@ const download = (songs: SongInfo[]) => {
})

const exitEventTypes = ['exit', 'SIGINT', 'SIGHUP', 'SIGBREAK', 'SIGTERM']
exitEventTypes.forEach((type) => {
process.on(type, () => {
for (const path of unfinishedPathMap.keys()) {
if (existsSync(path)) unlinkSync(path)
}
for (let i = 0; i < exitEventTypes.length; i++) {
process.on(exitEventTypes[i], () => {
Promise.all([...unfinishedPathMap.keys()].map((path) => unlink(path)))
process.exit()
})
})
}
return Promise.all(songs.map((song, index) => downloadSong(song, index)))
}
export default download

0 comments on commit 8b1f14e

Please sign in to comment.