testing ...
This commit is contained in:
parent
45e7c5040d
commit
3df1e2de4d
1 changed files with 42 additions and 16 deletions
58
server.js
58
server.js
|
|
@ -1,6 +1,9 @@
|
||||||
//dotenv
|
//dotenv
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
|
|
||||||
|
//ffmpeg
|
||||||
|
var ffmpeg = require('ffmpeg');
|
||||||
|
|
||||||
//nextcloud client
|
//nextcloud client
|
||||||
const { Client, Server, GetFilesRecursivelyCommand, CommandStatus } = require("nextcloud-node-client");
|
const { Client, Server, GetFilesRecursivelyCommand, CommandStatus } = require("nextcloud-node-client");
|
||||||
const server = new Server({
|
const server = new Server({
|
||||||
|
|
@ -13,10 +16,10 @@ const server = new Server({
|
||||||
|
|
||||||
//built-in
|
//built-in
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require('fs')
|
const fs = require('fs').promises;
|
||||||
const util = require('util')
|
const util = require('util');
|
||||||
const { pipeline } = require('stream')
|
const { pipeline } = require('stream');
|
||||||
const pump = util.promisify(pipeline)
|
const pump = util.promisify(pipeline);
|
||||||
|
|
||||||
//uuid
|
//uuid
|
||||||
const {
|
const {
|
||||||
|
|
@ -125,24 +128,47 @@ fastify.get("/", function (request, reply) {
|
||||||
//'post'
|
//'post'
|
||||||
fastify.post("/", async function (request, reply) {
|
fastify.post("/", async function (request, reply) {
|
||||||
|
|
||||||
// -- "accumulate whole file in memory"
|
// stores files to tmp dir and return paths
|
||||||
const data = await request.file()
|
const files = await request.saveRequestFiles();
|
||||||
const buffer = await data.toBuffer()
|
let audiofile = files.find(f => f.fieldname == 'audiofile');
|
||||||
// <<< https://github.com/fastify/fastify-multipart/#accumulate-whole-file-in-memory
|
let pixelfile = files.find(f => f.fieldname == 'pixels');
|
||||||
// ^--- this is needed.. dont understand fully, though. related to 'stream' receiving.
|
// console.log(audiofile.fields.message.value);
|
||||||
|
|
||||||
const client = new Client(server);
|
const client = new Client(server);
|
||||||
|
|
||||||
//create unique folder ==> timestamp + uuid
|
//create unique folder ==> timestamp + uuid
|
||||||
const folder = await client.createFolder("Storage/public/sound-parade/" + moment().tz('Asia/Seoul').format('YYYYMMDD-HHmmss - ') + uuidv1());
|
const folder = await client.createFolder("Storage/public/sound-parade/" + moment().tz('Asia/Seoul').format('YYYYMMDD-HHmmss - ') + uuidv1());
|
||||||
|
|
||||||
//files
|
//convert to mp3
|
||||||
console.log(data.fields.audiofile);
|
let dir = path.dirname(audiofile.filepath);
|
||||||
const file = await folder.createFile(data.fields.audiofile.filename, await data.fields.audiofile.toBuffer());
|
try {
|
||||||
console.log(data.fields);
|
var process = new ffmpeg(audiofile.filepath);
|
||||||
const text = await folder.createFile("message.txt", Buffer.from(data.fields.message.value));
|
process.then(function (video) {
|
||||||
console.log(data.fields.pixels);
|
// Callback mode
|
||||||
const image = await folder.createFile(data.fields.pixels.filename, await data.fields.pixels.toBuffer());
|
video.fnExtractSoundToMP3(dir + '/converted.mp3', function (error, file) {
|
||||||
|
if (!error)
|
||||||
|
console.log('Audio file: ' + file);
|
||||||
|
});
|
||||||
|
}, function (err) {
|
||||||
|
console.log('Error: ' + err);
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.code);
|
||||||
|
console.log(e.msg);
|
||||||
|
}
|
||||||
|
// await new ffmpeg(audiofile.filepath)
|
||||||
|
//
|
||||||
|
// await util.promisify((await new ffmpeg(name)).fnExtractSoundToMP3("converted.mp3"));
|
||||||
|
|
||||||
|
const file = await folder.createFile(audiofile.filename, await fs.readFile(audiofile.filepath));
|
||||||
|
// const text = await folder.createFile("message.txt", Buffer.from(audiofile.fields.message.value));
|
||||||
|
// const image = await folder.createFile(pixelfile.filename, await fs.readFile(pixelfile.filepath));
|
||||||
|
|
||||||
|
// //mp3 conversion
|
||||||
|
// console.log(await fs.readdir(dir));
|
||||||
|
//
|
||||||
|
//
|
||||||
|
console.log(await fs.readdir(dir));
|
||||||
|
|
||||||
reply.view("/src/pages/entry.hbs", {});
|
reply.view("/src/pages/entry.hbs", {});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue