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
|
||||
require('dotenv').config();
|
||||
|
||||
//ffmpeg
|
||||
var ffmpeg = require('ffmpeg');
|
||||
|
||||
//nextcloud client
|
||||
const { Client, Server, GetFilesRecursivelyCommand, CommandStatus } = require("nextcloud-node-client");
|
||||
const server = new Server({
|
||||
|
|
@ -13,10 +16,10 @@ const server = new Server({
|
|||
|
||||
//built-in
|
||||
const path = require("path");
|
||||
const fs = require('fs')
|
||||
const util = require('util')
|
||||
const { pipeline } = require('stream')
|
||||
const pump = util.promisify(pipeline)
|
||||
const fs = require('fs').promises;
|
||||
const util = require('util');
|
||||
const { pipeline } = require('stream');
|
||||
const pump = util.promisify(pipeline);
|
||||
|
||||
//uuid
|
||||
const {
|
||||
|
|
@ -125,24 +128,47 @@ fastify.get("/", function (request, reply) {
|
|||
//'post'
|
||||
fastify.post("/", async function (request, reply) {
|
||||
|
||||
// -- "accumulate whole file in memory"
|
||||
const data = await request.file()
|
||||
const buffer = await data.toBuffer()
|
||||
// <<< https://github.com/fastify/fastify-multipart/#accumulate-whole-file-in-memory
|
||||
// ^--- this is needed.. dont understand fully, though. related to 'stream' receiving.
|
||||
// stores files to tmp dir and return paths
|
||||
const files = await request.saveRequestFiles();
|
||||
let audiofile = files.find(f => f.fieldname == 'audiofile');
|
||||
let pixelfile = files.find(f => f.fieldname == 'pixels');
|
||||
// console.log(audiofile.fields.message.value);
|
||||
|
||||
const client = new Client(server);
|
||||
|
||||
//create unique folder ==> timestamp + uuid
|
||||
const folder = await client.createFolder("Storage/public/sound-parade/" + moment().tz('Asia/Seoul').format('YYYYMMDD-HHmmss - ') + uuidv1());
|
||||
|
||||
//files
|
||||
console.log(data.fields.audiofile);
|
||||
const file = await folder.createFile(data.fields.audiofile.filename, await data.fields.audiofile.toBuffer());
|
||||
console.log(data.fields);
|
||||
const text = await folder.createFile("message.txt", Buffer.from(data.fields.message.value));
|
||||
console.log(data.fields.pixels);
|
||||
const image = await folder.createFile(data.fields.pixels.filename, await data.fields.pixels.toBuffer());
|
||||
//convert to mp3
|
||||
let dir = path.dirname(audiofile.filepath);
|
||||
try {
|
||||
var process = new ffmpeg(audiofile.filepath);
|
||||
process.then(function (video) {
|
||||
// Callback mode
|
||||
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", {});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue