mirror of
https://github.com/Myxelium/RandomMemerBot.git
synced 2026-04-17 04:15:52 +00:00
Updated naming
This commit is contained in:
@@ -14,7 +14,7 @@ const app = express();
|
|||||||
const storage = diskStorage({
|
const storage = diskStorage({
|
||||||
destination: 'sounds/',
|
destination: 'sounds/',
|
||||||
filename: function (_req, file, cb) {
|
filename: function (_req, file, cb) {
|
||||||
cb(null, Date.now() + '-' + file.originalname);
|
cb(null, generateFileName(file.originalname));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -189,14 +189,16 @@ export function startServer() {
|
|||||||
* @param name - The name to generate a file name for.
|
* @param name - The name to generate a file name for.
|
||||||
* @returns string - The generated file name.
|
* @returns string - The generated file name.
|
||||||
*/
|
*/
|
||||||
function generateFileName(name: string): string {
|
function generateFileName(name: string) {
|
||||||
const genRanHex = [...Array(3)].map(() => Math.floor(Math.random() * 16).toString(16)).join('');
|
const randomHex = [...Array(3)].map(() => Math.floor(Math.random() * 16).toString(16)).join('');
|
||||||
|
|
||||||
const newName = name
|
const formattedName = name
|
||||||
.replace(/[^a-zA-Z ]/g, "")
|
.replace(/\(.*?\)|\[.*?\]/g, '')
|
||||||
|
.split(' ')
|
||||||
|
.filter(word => /^[a-zA-Z0-9]/.test(word))
|
||||||
|
.join(' ')
|
||||||
.replace(/\s+/g, '-')
|
.replace(/\s+/g, '-')
|
||||||
.toLowerCase()
|
.toLowerCase();
|
||||||
.replace(/\(.*?\)/g, '').replace(/#.*?\s/g, '');
|
|
||||||
|
|
||||||
return `${newName}-${genRanHex}.mp3`;
|
return `${formattedName}-${randomHex}.mp3`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user