feat: convert uploaded OGG to MP3 via ffmpeg
All checks were successful
Deploy / build-and-deploy (push) Successful in 2m4s

This commit is contained in:
2026-06-15 01:25:50 +03:00
parent e158467c76
commit 19d7a161c7
5 changed files with 70 additions and 20 deletions

23
lib/convert.ts Normal file
View File

@@ -0,0 +1,23 @@
import { execSync } from "child_process";
import fs from "fs";
export function convertOggToMp3(inputPath: string, outputPath: string): boolean {
try {
execSync(
`ffmpeg -i "${inputPath}" -codec:a libmp3lame -b:a 128k -y "${outputPath}" 2>/dev/null`,
{ timeout: 15000 }
);
return true;
} catch {
return false;
}
}
export function convertOggToMp3OrCopy(inputPath: string, mp3Path: string): string {
if (convertOggToMp3(inputPath, mp3Path)) {
return mp3Path;
}
// fallback: keep original OGG
fs.copyFileSync(inputPath, mp3Path.replace(/\.mp3$/, ".ogg"));
return mp3Path.replace(/\.mp3$/, ".ogg");
}