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);
|
let tmpdir = path.dirname(audiofile.filepath);
|
||||||
// console.log(audiofile.fields.message.value);
|
// console.log(audiofile.fields.message.value);
|
||||||
|
|
||||||
//convert to mp3
|
//convert to mp3 ?
|
||||||
function converter() {
|
if (path.extname(audiofile.filename) !== ".mp3") {
|
||||||
return new Promise((resolve, reject) => {
|
console.log("convert to mp3...");
|
||||||
//
|
function converter() {
|
||||||
let outputFile = tmpdir + "/converted.mp3";
|
return new Promise((resolve, reject) => {
|
||||||
// --> https://stackoverflow.com/a/36109219 (a quick tip on fluent-ffmpeg)
|
//
|
||||||
ffmpeg()
|
let outputFile = tmpdir + "/converted.mp3";
|
||||||
.addInput(audiofile.filepath)
|
// --> https://stackoverflow.com/a/36109219 (a quick tip on fluent-ffmpeg)
|
||||||
.on("error", function(err) {
|
ffmpeg()
|
||||||
reject(err);
|
.addInput(audiofile.filepath)
|
||||||
})
|
.on("error", function(err) {
|
||||||
.on("end", function() {
|
reject(err);
|
||||||
resolve(outputFile);
|
})
|
||||||
})
|
.on("end", function() {
|
||||||
.outputOptions('-b:a 192000')
|
resolve(outputFile);
|
||||||
.output(outputFile)
|
})
|
||||||
.run();
|
.outputOptions('-b:a 192000')
|
||||||
});
|
.output(outputFile)
|
||||||
|
.run();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await converter();
|
||||||
|
// console.log(await fs.readdir(tmpdir));
|
||||||
}
|
}
|
||||||
await converter();
|
|
||||||
// console.log(await fs.readdir(tmpdir));
|
|
||||||
|
|
||||||
//upload
|
//upload
|
||||||
const client = new Client(server);
|
const client = new Client(server);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue