diff options
author | Marvin Borner | 2019-04-03 22:39:03 +0200 |
---|---|---|
committer | Marvin Borner | 2019-04-03 22:39:03 +0200 |
commit | 390db9229b2aaa0a6ca7a920e4901b581ba917e2 (patch) | |
tree | 745d925f39e685257f333cce0f5e83c08a3d5eef /src/main/kotlin | |
parent | 560bdf297f353959c3ec7a667d6d33ab6f0db05a (diff) |
Added fileview
Diffstat (limited to 'src/main/kotlin')
-rw-r--r-- | src/main/kotlin/App.kt | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/main/kotlin/App.kt b/src/main/kotlin/App.kt index 02f1999..87055a1 100644 --- a/src/main/kotlin/App.kt +++ b/src/main/kotlin/App.kt @@ -35,13 +35,24 @@ fun main() { app.get("/files/*") { ctx -> val files = ArrayList<String>() try { - Files.list(Paths.get("$fileHome/${ctx.splats()[0]}/")).forEach { - val fileName = it.toString() - .drop(fileHome.length + (if (ctx.splats()[0].isNotEmpty()) ctx.splats()[0].length + 2 else 1)) - val filePath = "$fileHome${it.toString().drop(fileHome.length)}" - files.add(if (File(filePath).isDirectory) "$fileName/" else fileName) - } - ctx.render("files.rocker.html", model("files", files)) + if (File("$fileHome/${ctx.splats()[0]}").isDirectory) { + Files.list(Paths.get("$fileHome/${ctx.splats()[0]}/")).forEach { + val fileName = it.toString() + .drop(fileHome.length + (if (ctx.splats()[0].isNotEmpty()) ctx.splats()[0].length + 2 else 1)) + val filePath = "$fileHome${it.toString().drop(fileHome.length)}" + files.add(if (File(filePath).isDirectory) "$fileName/" else fileName) + ctx.render("files.rocker.html", model("files", files)) + } + } else + // TODO: Fix square brackets at fileview content + ctx.render( + "fileview.rocker.html", model( + "content", Files.readAllLines( + Paths.get("$fileHome/${ctx.splats()[0]}"), + Charsets.UTF_8 + ).toString() + ) + ) } catch (_: java.nio.file.NoSuchFileException) { throw NotFoundResponse("Error: File or directory does not exist.") } |