aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2020-07-18 22:27:48 +0200
committerMarvin Borner2020-07-18 22:27:48 +0200
commitf8cff89de2ef165748362cf0f104e2bf7bf88618 (patch)
tree7c64e49d890aa186f9810a512b03c2eef6d7c27d
parent317b466e1080166aa6bf40a3766014593cbc95f2 (diff)
Fileview..
-rw-r--r--src/handler/fileView.ts4
-rw-r--r--src/main.ts1
-rw-r--r--src/util/files.ts43
-rw-r--r--src/views/index.html2
4 files changed, 41 insertions, 9 deletions
diff --git a/src/handler/fileView.ts b/src/handler/fileView.ts
index 90c7176..eb9c3a1 100644
--- a/src/handler/fileView.ts
+++ b/src/handler/fileView.ts
@@ -1,6 +1,6 @@
import type { HandlerFunc, Context } from "https://deno.land/x/abc@master/mod.ts";
-import { cleanPath } from "../util/files.ts";
+import { getFiles } from "../util/files.ts";
export const handlePath: HandlerFunc = async (c: Context) => {
- return await c.render("./src/views/index.html", { path: cleanPath(c.path) });
+ return await c.render("./src/views/index.html", { files: await getFiles(c.path) });
};
diff --git a/src/main.ts b/src/main.ts
index 94f8b33..99f605c 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -22,6 +22,7 @@ app.static("/public/", "./src/public/"); // Manage static files
app.get("/", async (c: Context) => await c.render("./src/views/index.html")); // Render index on /
app.get("/files/*", handlePath);
+app.get("/files/", handlePath);
// Load groups dynamically
// deno-lint-ignore ban-ts-comment
diff --git a/src/util/files.ts b/src/util/files.ts
index ec1f584..e516258 100644
--- a/src/util/files.ts
+++ b/src/util/files.ts
@@ -1,7 +1,38 @@
-export const cleanPath = (path: string) => {
- return path
- .replace("/files/", "")
- .replace("../", "") // TODO: Fix relative ../
- .replace("./", "")
- .replace(/([^:]\/)\/+/g, "$1");
+import { ensureDirSync } from "https://deno.land/std/fs/mod.ts";
+import { walk } from "https://deno.land/std/fs/mod.ts";
+
+const TEMP_USER_ID = 42; // TODO: FIX
+
+export const cleanPath = (path: string): string => {
+ createUserDirectory(TEMP_USER_ID);
+
+ return (
+ "data/" +
+ TEMP_USER_ID +
+ "/" +
+ path
+ .replace("/files/", "")
+ .replace("../", "") // TODO: Fix relative ../
+ .replace("./", "")
+ .replace(/([^:]\/)\/+/g, "$1")
+ );
+};
+
+export const getFiles = async (path: string) => {
+ const newPath = path ? path : "";
+
+ createUserDirectory(TEMP_USER_ID);
+ const dataPath: string = cleanPath(newPath);
+ console.log(dataPath);
+
+ const files = [];
+ for await (const entry of walk(dataPath)) {
+ files.push(entry.path);
+ }
+ return files;
+};
+
+export const createUserDirectory = (uid: number) => {
+ ensureDirSync("data/" + uid);
+ // TODO: Give user access to dir
};
diff --git a/src/views/index.html b/src/views/index.html
index ffeb948..0e3ab11 100644
--- a/src/views/index.html
+++ b/src/views/index.html
@@ -6,6 +6,6 @@
<title>Index</title>
</head>
<body>
- <% if (path) { %> <%= path %>! <% } %>
+ <% if (files) { %> <%= files %>! <% } %>
</body>
</html>