conditional mp3 conversion..
This commit is contained in:
parent
8a5cb7afa8
commit
8cfa769f5f
1 changed files with 23 additions and 20 deletions
43
server.js
43
server.js
|
|
@ -76,27 +76,30 @@ fastify.post("/entry", async function (request, reply) {
|
|||
let tmpdir = path.dirname(audiofile.filepath);
|
||||
// console.log(audiofile.fields.message.value);
|
||||
|
||||
//convert to mp3
|
||||
function converter() {
|
||||
return new Promise((resolve, reject) => {
|
||||
//
|
||||
let outputFile = tmpdir + "/converted.mp3";
|
||||
// --> https://stackoverflow.com/a/36109219 (a quick tip on fluent-ffmpeg)
|
||||
ffmpeg()
|
||||
.addInput(audiofile.filepath)
|
||||
.on("error", function(err) {
|
||||
reject(err);
|
||||
})
|
||||
.on("end", function() {
|
||||
resolve(outputFile);
|
||||
})
|
||||
.outputOptions('-b:a 192000')
|
||||
.output(outputFile)
|
||||
.run();
|
||||
});
|
||||
//convert to mp3 ?
|
||||
if (path.extname(audiofile.filename) !== ".mp3") {
|
||||
console.log("convert to mp3...");
|
||||
function converter() {
|
||||
return new Promise((resolve, reject) => {
|
||||
//
|
||||
let outputFile = tmpdir + "/converted.mp3";
|
||||
// --> https://stackoverflow.com/a/36109219 (a quick tip on fluent-ffmpeg)
|
||||
ffmpeg()
|
||||
.addInput(audiofile.filepath)
|
||||
.on("error", function(err) {
|
||||
reject(err);
|
||||
})
|
||||
.on("end", function() {
|
||||
resolve(outputFile);
|
||||
})
|
||||
.outputOptions('-b:a 192000')
|
||||
.output(outputFile)
|
||||
.run();
|
||||
});
|
||||
}
|
||||
await converter();
|
||||
// console.log(await fs.readdir(tmpdir));
|
||||
}
|
||||
await converter();
|
||||
// console.log(await fs.readdir(tmpdir));
|
||||
|
||||
//upload
|
||||
const client = new Client(server);
|
||||
|
|
|
|||
Loading…
Reference in a new issue