diff --git a/server.js b/server.js index 118cb61..754a363 100644 --- a/server.js +++ b/server.js @@ -2,7 +2,7 @@ require('dotenv').config(); //nextcloud client -const { Client, Server } = require("nextcloud-node-client"); +const { Client, Server, GetFilesRecursivelyCommand, CommandStatus } = require("nextcloud-node-client"); const server = new Server({ basicAuth: { password: process.env.nextcloud_PASSWD, @@ -62,6 +62,66 @@ fastify.get("/", function (request, reply) { // --> https://stackoverflow.com/a/40899275 // all the regex doesn't work... last resort. +["/list", "/list/"].forEach(function(path) { + fastify.get(path, async function (request, reply) { + + let params = {}; + + // + const client = new Client(server); + + //files + const sourceFolder = await client.getFolder("/Storage/public/sound-parade/"); + // const folderFiles = await sourceFolder.getFiles(); + // for (const file of folderFiles) { + // console.log(file.name); + // } + + const subFolders = await sourceFolder.getSubFolders(); + for (const subFolder of subFolders) { + console.log("folder", subFolder.name); + } + + // // only pdfs and jpg should be listed + // // const fileFilterFunction = (file) => { + // // // if (file.mime === "application/pdf" || file.mime === "image/jpeg") { + // // // return file; + // // // } + // // return file; + // // } + // + // const options = { + // sourceFolder, + // // filterFile: fileFilterFunction, + // }; + // + // const command = new GetFilesRecursivelyCommand(client, options); + // // get files asynchronously (will not throw exceptions!) + // command.execute(); + // + // // check the processing status as long as the command is running + // while (command.isFinished() !== true) { + // // wait one second + // await (async () => { return new Promise(resolve => setTimeout(resolve, 1000)) })(); + // console.log(command.getPercentCompleted() + "%"); + // } + // + // // use the result to do the needful + // const uploadResult = command.getResultMetaData(); + // + // if (command.getStatus() === CommandStatus.success) { + // console.log(uploadResult.messages); + // for (const file of command.getFiles()) { + // console.log(file.name); + // } + // } else { + // console.log(uploadResult.errors); + // } + + reply.view("/src/pages/list.hbs", params); + }); +}); + //'post' fastify.post("/", async function (request, reply) { @@ -74,7 +134,7 @@ fastify.post("/", async function (request, reply) { const client = new Client(server); //create unique folder ==> timestamp + uuid - const folder = await client.createFolder("Storage/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 console.log(data.fields.audiofile); diff --git a/src/pages/list.hbs b/src/pages/list.hbs new file mode 100644 index 0000000..1fd7b6d --- /dev/null +++ b/src/pages/list.hbs @@ -0,0 +1,22 @@ + + + + + + 흐름을 향하여 걷는 + + + + +
+ {{#each listing}} + {{#if this}} + + {{/if}} + {{/each}} +
+ +