mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-05-28 14:21:34 +00:00
Merge 9a76293f20 into c009db9f28
This commit is contained in:
commit
86188d64cb
2 changed files with 12 additions and 1 deletions
|
|
@ -45,6 +45,7 @@
|
||||||
"express-session": "^1.17.3",
|
"express-session": "^1.17.3",
|
||||||
"graceful-fs": "^4.2.10",
|
"graceful-fs": "^4.2.10",
|
||||||
"htmlparser2": "^8.0.1",
|
"htmlparser2": "^8.0.1",
|
||||||
|
"jschardet": "^3.1.4",
|
||||||
"lru-cache": "^10.0.3",
|
"lru-cache": "^10.0.3",
|
||||||
"node-unrar-js": "^2.0.2",
|
"node-unrar-js": "^2.0.2",
|
||||||
"nodemailer": "^6.9.13",
|
"nodemailer": "^6.9.13",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const Path = require('path')
|
const Path = require('path')
|
||||||
const ssrfFilter = require('ssrf-req-filter')
|
const ssrfFilter = require('ssrf-req-filter')
|
||||||
|
const iconvlite = require('iconv-lite')
|
||||||
|
const jschardet = require('jschardet')
|
||||||
const exec = require('child_process').exec
|
const exec = require('child_process').exec
|
||||||
const fs = require('../libs/fsExtra')
|
const fs = require('../libs/fsExtra')
|
||||||
const rra = require('../libs/recursiveReaddirAsync')
|
const rra = require('../libs/recursiveReaddirAsync')
|
||||||
|
|
@ -122,7 +124,15 @@ module.exports.getIno = getIno
|
||||||
*/
|
*/
|
||||||
async function readTextFile(path) {
|
async function readTextFile(path) {
|
||||||
try {
|
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)
|
return String(data)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(`[FileUtils] ReadTextFile error ${error}`)
|
Logger.error(`[FileUtils] ReadTextFile error ${error}`)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue