mirror of
https://github.com/marktext/marktext.git
synced 2025-05-07 17:12:47 +08:00
Ensure Hunspell dictionary before downloading (#1675)
This commit is contained in:
parent
1a3020a5b1
commit
a3428b5151
@ -17,6 +17,8 @@ export const downloadHunspellDictionary = async lang => {
|
|||||||
responseType: 'stream'
|
responseType: 'stream'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
await fs.ensureDir(dictionaryPath)
|
||||||
|
|
||||||
const dstFile = path.join(dictionaryPath, `${lang}.bdic`)
|
const dstFile = path.join(dictionaryPath, `${lang}.bdic`)
|
||||||
const tmpFile = `${dstFile}.tmp`
|
const tmpFile = `${dstFile}.tmp`
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -31,11 +33,13 @@ export const downloadHunspellDictionary = async lang => {
|
|||||||
outStream.once('error', reject)
|
outStream.once('error', reject)
|
||||||
outStream.once('finish', async () => {
|
outStream.once('finish', async () => {
|
||||||
if (totalLength < 8 * 1024) {
|
if (totalLength < 8 * 1024) {
|
||||||
throw new Error('Dictionary is most likely bogus.')
|
reject(new Error('Dictionary is most likely bogus.'))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await fs.move(tmpFile, dstFile, { overwrite: true })
|
fs.move(tmpFile, dstFile, { overwrite: true })
|
||||||
resolve()
|
.then(resolve)
|
||||||
|
.catch(reject)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user