diff options
Diffstat (limited to 'src/main/kotlin/App.kt')
-rw-r--r-- | src/main/kotlin/App.kt | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/main/kotlin/App.kt b/src/main/kotlin/App.kt index d7467a4..b5d6042 100644 --- a/src/main/kotlin/App.kt +++ b/src/main/kotlin/App.kt @@ -1,16 +1,27 @@ package space.anity +import com.fizzed.rocker.* import io.javalin.* import io.javalin.core.util.* +import io.javalin.rendering.* +import io.javalin.rendering.template.TemplateUtil.model import java.io.* import java.nio.file.* fun main(args: Array<String>) { val fileHome = "files" + JavalinRenderer.register( + FileRenderer { filepath, model -> Rocker.template(filepath).bind(model).render().toString() }, ".rocker.html" + ) val app = Javalin.create().enableStaticFiles("../resources/").start(7000) + // TODO: Fix rocker templating + app.get("/test") { ctx -> + ctx.render("test.rocker.html", model("message", "Testy testy!")) + } + // TODO: Fix possible security issue with "../" - app.get("/files/*") { ctx -> + app.get("/api/files/*") { ctx -> val files = ArrayList<String>() try { Files.list(Paths.get("$fileHome/${ctx.splats()[0]}/")).forEach { @@ -28,7 +39,7 @@ fun main(args: Array<String>) { app.get("/upload") { ctx -> ctx.redirect("/upload.html") } // TODO: Fix possible security issue with "../" - app.post("/upload") { ctx -> + app.post("/api/upload") { ctx -> ctx.uploadedFiles("files").forEach { (contentType, content, name, extension) -> if (ctx.queryParam("dir") !== null) { FileUtil.streamToFile(content, "files/${ctx.queryParam("dir")}/$name") |