mirror of
https://github.com/anidl/multi-downloader-nx.git
synced 2026-05-16 14:41:52 +00:00
updated cleanupFilename
This commit is contained in:
parent
aa8b93276d
commit
e59ffd7f24
1 changed files with 16 additions and 8 deletions
|
|
@ -25,18 +25,26 @@ export default class Helper {
|
||||||
|
|
||||||
static cleanupFilename(n: string) {
|
static cleanupFilename(n: string) {
|
||||||
/* eslint-disable no-useless-escape, no-control-regex */
|
/* eslint-disable no-useless-escape, no-control-regex */
|
||||||
const fixingChar = '_';
|
// Smart Replacer
|
||||||
const illegalRe = /[\/\?<>\\:\*\|":]/g;
|
const rep: Record<string, string> = {
|
||||||
|
'/': '⧸',
|
||||||
|
'\\': '⧹',
|
||||||
|
':': ':',
|
||||||
|
'*': '∗',
|
||||||
|
'?': '?',
|
||||||
|
'"': "'",
|
||||||
|
'<': '‹',
|
||||||
|
'>': '›'
|
||||||
|
};
|
||||||
|
n = n.replace(/[\/\\:\*\?"<>\|]/g, (ch) => rep[ch] || '_');
|
||||||
|
|
||||||
|
// Old Replacer
|
||||||
const controlRe = /[\x00-\x1f\x80-\x9f]/g;
|
const controlRe = /[\x00-\x1f\x80-\x9f]/g;
|
||||||
const reservedRe = /^\.+$/;
|
const reservedRe = /^\.+$/;
|
||||||
const windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i;
|
const windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i;
|
||||||
const windowsTrailingRe = /[\. ]+$/;
|
const windowsTrailingRe = /[\. ]+$/;
|
||||||
return n
|
|
||||||
.replace(illegalRe, fixingChar)
|
return n.replace(controlRe, '_').replace(reservedRe, '_').replace(windowsReservedRe, '_').replace(windowsTrailingRe, '_');
|
||||||
.replace(controlRe, fixingChar)
|
|
||||||
.replace(reservedRe, fixingChar)
|
|
||||||
.replace(windowsReservedRe, fixingChar)
|
|
||||||
.replace(windowsTrailingRe, fixingChar);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static exec(
|
static exec(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue