mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-23 17:29:19 +02:00
Add logs when sanitizing filename and update podcast episode download to set targetFilename on init #4121
This commit is contained in:
parent
7d0f61663e
commit
92bb3527de
3 changed files with 32 additions and 6 deletions
|
@ -362,6 +362,9 @@ module.exports.sanitizeFilename = (filename, colonReplacement = ' - ') => {
|
|||
return false
|
||||
}
|
||||
|
||||
// Normalize the string first to ensure consistent byte calculations
|
||||
filename = filename.normalize('NFC')
|
||||
|
||||
// Most file systems use number of bytes for max filename
|
||||
// to support most filesystems we will use max of 255 bytes in utf-16
|
||||
// Ref: https://doc.owncloud.com/server/next/admin_manual/troubleshooting/path_filename_length.html
|
||||
|
@ -390,8 +393,11 @@ module.exports.sanitizeFilename = (filename, colonReplacement = ' - ') => {
|
|||
const ext = Path.extname(sanitized) // separate out file extension
|
||||
const basename = Path.basename(sanitized, ext)
|
||||
const extByteLength = Buffer.byteLength(ext, 'utf16le')
|
||||
|
||||
const basenameByteLength = Buffer.byteLength(basename, 'utf16le')
|
||||
if (basenameByteLength + extByteLength > MAX_FILENAME_BYTES) {
|
||||
Logger.debug(`[fileUtils] Filename "${filename}" is too long (${basenameByteLength + extByteLength} bytes), trimming basename to ${MAX_FILENAME_BYTES - extByteLength} bytes.`)
|
||||
|
||||
const MaxBytesForBasename = MAX_FILENAME_BYTES - extByteLength
|
||||
let totalBytes = 0
|
||||
let trimmedBasename = ''
|
||||
|
@ -407,6 +413,10 @@ module.exports.sanitizeFilename = (filename, colonReplacement = ' - ') => {
|
|||
sanitized = trimmedBasename + ext
|
||||
}
|
||||
|
||||
if (filename !== sanitized) {
|
||||
Logger.debug(`[fileUtils] Sanitized filename "${filename}" to "${sanitized}" (${Buffer.byteLength(sanitized, 'utf16le')} bytes)`)
|
||||
}
|
||||
|
||||
return sanitized
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue