list testing...

This commit is contained in:
Dooho Yi 2022-01-13 21:52:28 +09:00
parent f1e12f0042
commit 8b26f0a68f
2 changed files with 84 additions and 2 deletions

View file

@ -2,7 +2,7 @@
require('dotenv').config(); require('dotenv').config();
//nextcloud client //nextcloud client
const { Client, Server } = require("nextcloud-node-client"); const { Client, Server, GetFilesRecursivelyCommand, CommandStatus } = require("nextcloud-node-client");
const server = new Server({ const server = new Server({
basicAuth: { basicAuth: {
password: process.env.nextcloud_PASSWD, password: process.env.nextcloud_PASSWD,
@ -62,6 +62,66 @@ fastify.get("/", function (request, reply) {
// --> https://stackoverflow.com/a/40899275 // --> https://stackoverflow.com/a/40899275
// all the regex doesn't work... last resort. // 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' //'post'
fastify.post("/", async function (request, reply) { fastify.post("/", async function (request, reply) {
@ -74,7 +134,7 @@ fastify.post("/", async function (request, reply) {
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/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 //files
console.log(data.fields.audiofile); console.log(data.fields.audiofile);

22
src/pages/list.hbs Normal file
View file

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>흐름을 향하여 걷는</title>
<link
rel="stylesheet"
href="https://unpkg.com/tachyons@4.12.0/css/tachyons.min.css"
/>
<link rel="stylesheet" href="/list/style.css" />
</head>
<body class="bg-blue">
<div class="ph5 center">
{{#each listing}}
{{#if this}}
<img src="{{this}}" />
{{/if}}
{{/each}}
</div>
</body>
</html>