diff --git a/public/stream.m3u b/public/stream.m3u new file mode 100644 index 0000000..96021c0 --- /dev/null +++ b/public/stream.m3u @@ -0,0 +1 @@ +http://116.122.163.142:8000/stream diff --git a/server.js b/server.js index d3e33b1..e6c48af 100644 --- a/server.js +++ b/server.js @@ -57,10 +57,13 @@ fastify.get("/", function (request, reply) { reply.view("/src/pages/parade.html", {}); }); -//get '/preview/:foldername' +//get '/live +fastify.get("/live", function (request, reply) { + reply.view("/src/pages/live.html", {}); +}); + +//get '/preview/:foldername' --> request.params.foldername fastify.get("/preview/:foldername", function (request, reply) { - // - //request.params.foldername reply.view("/src/pages/preview.html", {}); }); @@ -79,13 +82,19 @@ fastify.get("/preview/:foldername", function (request, reply) { let folders = []; for (const item of list) { - var fields = JSON.parse((await fs.readFile('/media/storage/public/sound-parade/' + item + '/fields.json')).toString('utf8')); - folders.push({ - foldername: item, - group: fields.group, - title: fields.title, - comment: fields.comment, + let json = await fs.readFile('/media/storage/public/sound-parade/' + item + '/fields.json') + .catch((err) => { + console.error(err); }); + if (json != undefined) { + var fields = JSON.parse(json.toString('utf8')); + folders.push({ + foldername: item, + group: fields.group, + title: fields.title, + comment: fields.comment, + }); + } } // console.log(folders); @@ -172,19 +181,73 @@ fastify.get("/delete/:foldername/:pass", async function (request, reply) { fastify.post("/entry", async function (request, reply) { // stores files to tmp dir and return paths - const files = await request.saveRequestFiles(); + const files = await request.saveRequestFiles().catch(err => { + console.error(err); + }); let audiofile = files.find(f => f.fieldname == 'audiofile'); let pixelfile = files.find(f => f.fieldname == 'pixels'); let tmpdir = path.dirname(audiofile.filepath); // console.log(audiofile.fields.message.value); - console.log("hi."); + console.log("-- hi."); // got all files. - //convert to mp3 ? - var converted = false; + //conversion needed? + var conversion = false; if (path.extname(audiofile.filename) !== ".mp3") { - console.log("convert to mp3..."); - converted = true; + conversion = true; + console.log("-- well.."); //conversion. is scheduled. + } else { + console.log("-- good"); //no conversion_ + } + + //upload + const client = new Client(server); + + console.log("-- ready"); //file server opened + + //create unique folder ==> timestamp + uuid + const folder = await client.createFolder("Storage/public/sound-parade/" + moment().tz('Asia/Seoul').format('YYYYMMDD-HHmmss-') + uuidv1()); + // + const json = await folder.createFile("fields.json", Buffer.from(JSON.stringify({ + group: audiofile.fields.group.value, + title: audiofile.fields.title.value, + comment: audiofile.fields.comment.value, + pass: audiofile.fields.pass.value + }))); + const image = await folder.createFile("pixels.png", await fs.readFile(pixelfile.filepath)); + // + if (conversion) { + console.log('---- hi conv'); + //save original file as is. + we have scheduled a conversion. + let afile = await fs.readFile(audiofile.filepath) + .catch(err => { + console.error(err); + }); + // + if (afile != undefined) { + const file = await folder.createFile(audiofile.filename, afile) + .catch(err => { + console.error(err); + console.log('---- createFile err.'); + console.log('afile', afile); + }); + } else { + console.log('afile == undef!'); + } + console.log('---- yes conv'); + // + } else { + console.log('---- no conv'); + //rename & save original file. + const file = await folder.createFile("audio.mp3", await fs.readFile(audiofile.filepath).catch(err => console.error(err))); + } + + console.log("-- saved"); //saved in file server. + + //conversion needed? + var converted = false; + if (conversion) { + console.log("-- mp3..."); //converting to mp3... function converter() { return new Promise((resolve, reject) => { // @@ -193,9 +256,12 @@ fastify.post("/entry", async function (request, reply) { ffmpeg() .addInput(audiofile.filepath) .on("error", function(err) { + console.log("-- err:", err); reject(err); }) .on("end", function() { + console.log("-- fine."); //conversion succeesful + converted = true; resolve(outputFile); }) .outputOptions('-b:a 192000') @@ -203,33 +269,16 @@ fastify.post("/entry", async function (request, reply) { .run(); }); } - await converter(); - // console.log(await fs.readdir(tmpdir)); + await converter().catch((err) => { console.error(err); }); + + if (converted) { + const file = await folder.createFile("audio.mp3", await fs.readFile(tmpdir + '/converted.mp3')); + console.log("-- done"); + } + } - console.log("ok."); - - //upload - const client = new Client(server); - - console.log("good."); - - //create unique folder ==> timestamp + uuid - const folder = await client.createFolder("Storage/public/sound-parade/" + moment().tz('Asia/Seoul').format('YYYYMMDD-HHmmss-') + uuidv1()); - if (converted) { - const file = await folder.createFile("audio.mp3", await fs.readFile(tmpdir + '/converted.mp3')); - } else { - const file = await folder.createFile("audio.mp3", await fs.readFile(audiofile.filepath)); - } - const image = await folder.createFile("pixels.png", await fs.readFile(pixelfile.filepath)); - const json = await folder.createFile("fields.json", Buffer.from(JSON.stringify({ - group: audiofile.fields.group.value, - title: audiofile.fields.title.value, - comment: audiofile.fields.comment.value, - pass: audiofile.fields.pass.value - }))); - - console.log("done."); + console.log("-- well done"); reply.send('done!'); //reply.redirect('/submit'); @@ -257,6 +306,11 @@ io.on("connection", function(socket) { fn(false); } }); + + socket.on("flow", function(req) { + io.emit("flow", req); + }); + }); // diff --git a/src/pages/entry.en.html b/src/pages/entry.en.html index 2b2c654..ba7ebb6 100644 --- a/src/pages/entry.en.html +++ b/src/pages/entry.en.html @@ -42,7 +42,7 @@
KR
-
Home
+
parade

Walking  Towards  the Flow

@@ -157,6 +157,9 @@ +

+ ↓  +

diff --git a/src/pages/entry.html b/src/pages/entry.html index f0035fd..f0257b5 100644 --- a/src/pages/entry.html +++ b/src/pages/entry.html @@ -42,7 +42,7 @@
- +

흐름을  향하여  걷는

@@ -159,6 +159,9 @@ +

+ ↓  +

diff --git a/src/pages/live.html b/src/pages/live.html new file mode 100644 index 0000000..3655f85 --- /dev/null +++ b/src/pages/live.html @@ -0,0 +1,285 @@ + + + + + + + 흐름을 향하여 걷는 + + + + + + + + + + + +
+
+
+ + + + diff --git a/src/pages/preview.html b/src/pages/preview.html index 102422a..669ec1f 100644 --- a/src/pages/preview.html +++ b/src/pages/preview.html @@ -312,7 +312,6 @@ if (type == "icon") { img.style("z-index", "-1"); } - 3; img.position(x, y); var pan = (x / windowWidth) * 2 - 1; @@ -350,7 +349,9 @@ arr.splice(i, 1); if (arr.length == 0 && playing == false) { setTimeout(() => { - createDiv("미리보기가 끝났습니다.
Preview is over.").class("notice").style('text-align', 'center'); + createDiv("미리보기가 끝났습니다.
Preview is over.

").class("notice").style('text-align', 'center') + .child(createButton("퍼레이드 가기").attribute('onclick', 'location.href="/"').style('margin', '1em 1em')) + .child(createButton("닫기").attribute('onclick', 'window.close()').style('margin', '1em 1em')) }, 3000); } }