mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-04-11 22:29:38 +00:00
Fix downloads
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { randomBytes } from 'crypto'
|
||||
import { basename, parse } from 'path'
|
||||
import sanitize from 'sanitize-filename'
|
||||
import { inspect } from 'util'
|
||||
|
||||
import { lower } from '../src-shared/UtilFunctions'
|
||||
@@ -26,3 +28,26 @@ export function hasVideoExtension(name: string) {
|
||||
export function devLog(message: unknown) {
|
||||
emitIpcEvent('errorLog', typeof message === 'string' ? message : inspect(message))
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns `filename` with all invalid filename characters replaced.
|
||||
*/
|
||||
export function sanitizeFilename(filename: string): string {
|
||||
const newFilename = sanitize(filename, {
|
||||
replacement: ((invalidChar: string) => {
|
||||
switch (invalidChar) {
|
||||
case '<': return '❮'
|
||||
case '>': return '❯'
|
||||
case ':': return '꞉'
|
||||
case '"': return "'"
|
||||
case '/': return '/'
|
||||
case '\\': return '⧵'
|
||||
case '|': return '⏐'
|
||||
case '?': return '?'
|
||||
case '*': return '⁎'
|
||||
default: return '_'
|
||||
}
|
||||
}),
|
||||
})
|
||||
return (newFilename === '' ? randomBytes(5).toString('hex') : newFilename)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user