mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-20 02:44:31 +02:00
Fix:Check if Windows before cleaning file path for POSIX separators #1254
This commit is contained in:
parent
f76f9c7f84
commit
9a85ad1f6b
19 changed files with 66 additions and 54 deletions
|
@ -80,11 +80,11 @@ function bytesPretty(bytes, decimals = 0) {
|
|||
module.exports.bytesPretty = bytesPretty
|
||||
|
||||
async function recurseFiles(path, relPathToReplace = null) {
|
||||
path = path.replace(/\\/g, '/')
|
||||
path = this.filePathToPOSIX(path)
|
||||
if (!path.endsWith('/')) path = path + '/'
|
||||
|
||||
if (relPathToReplace) {
|
||||
relPathToReplace = relPathToReplace.replace(/\\/g, '/')
|
||||
relPathToReplace = this.filePathToPOSIX(relPathToReplace)
|
||||
if (!relPathToReplace.endsWith('/')) relPathToReplace += '/'
|
||||
} else {
|
||||
relPathToReplace = path
|
||||
|
@ -244,4 +244,19 @@ module.exports.removeFile = (path) => {
|
|||
Logger.error(`[fileUtils] Failed remove file "${path}"`, error)
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure folder separator is POSIX for Windows file paths. e.g. "C:\Users\Abs" becomes "C:/Users/Abs"
|
||||
*
|
||||
* @param {String} path - Ugly file path
|
||||
* @return {String} Pretty posix file path
|
||||
*/
|
||||
module.exports.filePathToPOSIX = (path) => {
|
||||
if (!global.isWin || !path) return path
|
||||
return path.replace(/\\/g, '/')
|
||||
}
|
||||
|
||||
module.exports.encodeUriPath = (path) => {
|
||||
return this.filePathToPOSIX(path).replace(/%/g, '%25').replace(/#/g, '%23')
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue