Улучшено скачивание файлов - добавлено читабельное имя файла

This commit is contained in:
Book Pauk
2022-09-26 16:04:26 +07:00
parent 92303cadc3
commit afef0ed04c
6 changed files with 87 additions and 21 deletions

View File

@@ -54,3 +54,16 @@ export async function copyTextToClipboard(text) {
return result;
}
export function makeValidFilename(filename, repl = '_') {
let f = filename.replace(/[\x00\\/:*"<>|]/g, repl); // eslint-disable-line no-control-regex
f = f.trim();
while (f.length && (f[f.length - 1] == '.' || f[f.length - 1] == '_')) {
f = f.substring(0, f.length - 1);
}
if (f)
return f;
else
throw new Error('Invalid filename');
}