mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-13 04:41:36 +00:00
Consider alternative encodings for text files
This commit is contained in:
parent
2d0a5462d2
commit
9a76293f20
2 changed files with 12 additions and 1 deletions
|
|
@ -1,6 +1,8 @@
|
|||
const axios = require('axios')
|
||||
const Path = require('path')
|
||||
const ssrfFilter = require('ssrf-req-filter')
|
||||
const iconvlite = require('iconv-lite')
|
||||
const jschardet = require('jschardet')
|
||||
const exec = require('child_process').exec
|
||||
const fs = require('../libs/fsExtra')
|
||||
const rra = require('../libs/recursiveReaddirAsync')
|
||||
|
|
@ -122,7 +124,15 @@ module.exports.getIno = getIno
|
|||
*/
|
||||
async function readTextFile(path) {
|
||||
try {
|
||||
var data = await fs.readFile(path)
|
||||
let data = await fs.readFile(path)
|
||||
const det_enc = jschardet.detect(data)
|
||||
if (det_enc)
|
||||
try {
|
||||
return iconvlite.decode(data, det_enc.encoding)
|
||||
} catch (error) {
|
||||
Logger.info(`[FileUtils] ReadTextFile detected encoding ${det_enc.encoding} for file ${path} failed to decode, defaulting to UTF-8. Internal error in iconv-lite: ${error}`)
|
||||
}
|
||||
// defaults to utf-8
|
||||
return String(data)
|
||||
} catch (error) {
|
||||
Logger.error(`[FileUtils] ReadTextFile error ${error}`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue