api/create-filename: build & sanitize filenames in one place

This commit is contained in:
wukko
2024-11-24 18:12:21 +06:00
parent 407c27ed86
commit 6770738116
9 changed files with 25 additions and 34 deletions

View File

@@ -1,3 +1,13 @@
const illegalCharacters = ['}', '{', '%', '>', '<', '^', ';', ':', '`', '$', '"', "@", '=', '?', '|', '*'];
const sanitizeString = (string) => {
for (const i in illegalCharacters) {
string = string.replaceAll("/", "_").replaceAll("\\", "_")
.replaceAll(illegalCharacters[i], '')
}
return string;
}
export default (f, style, isAudioOnly, isAudioMuted) => {
let filename = '';
@@ -5,7 +15,7 @@ export default (f, style, isAudioOnly, isAudioMuted) => {
let classicTags = [...infoBase];
let basicTags = [];
const title = `${f.title} - ${f.author}`;
const title = `${sanitizeString(f.title)} - ${sanitizeString(f.author)}`;
if (f.resolution) {
classicTags.push(f.resolution);