aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2019-04-07 14:14:30 +0200
committerMarvin Borner2019-04-07 14:14:30 +0200
commit92807cfb7249eff1d96b70aa33a46c9eb6c0e733 (patch)
tree033386b8c1e08a2b4720eb2cf2198fc20adece4f
parent0b1fc338c6e17930665112ca72416d836a0339fe (diff)
Added upload page as a rocker template
-rw-r--r--src/main/kotlin/App.kt6
-rw-r--r--src/main/resources/views/upload.html16
-rw-r--r--src/main/resources/views/upload.rocker.html8
3 files changed, 11 insertions, 19 deletions
diff --git a/src/main/kotlin/App.kt b/src/main/kotlin/App.kt
index 2869525..44f60bb 100644
--- a/src/main/kotlin/App.kt
+++ b/src/main/kotlin/App.kt
@@ -41,9 +41,9 @@ fun main() {
get("/files/*", { ctx -> crawlFiles(ctx) }, roles(Roles.ADMIN))
/**
- * Redirects upload to corresponding html file
+ * Renders the upload rocker template
*/
- get("/upload", { ctx -> ctx.redirect("/views/upload.html") }, roles(Roles.USER))
+ get("/upload", { ctx -> ctx.render("upload.rocker.html") }, roles(Roles.USER))
/**
* Receives and saves multipart media data
@@ -102,7 +102,7 @@ fun upload(ctx: Context) {
ctx.uploadedFiles("files").forEach { (contentType, content, name, extension) ->
if (ctx.queryParam("dir") !== null) {
FileUtil.streamToFile(content, "files/${ctx.queryParam("dir")}/$name")
- ctx.redirect("/views/upload.html")
+ ctx.redirect("/views/upload.rocker.html")
} else
throw BadRequestResponse("Error: Please enter a filename.")
}
diff --git a/src/main/resources/views/upload.html b/src/main/resources/views/upload.html
deleted file mode 100644
index 16c8a94..0000000
--- a/src/main/resources/views/upload.html
+++ /dev/null
@@ -1,16 +0,0 @@
-<!doctype html>
-<html lang="en">
-<head>
- <meta charset="UTF-8">
- <meta content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
- name="viewport">
- <meta content="ie=edge" http-equiv="X-UA-Compatible">
- <title>Upload Testing</title>
-</head>
-<body>
-<form action="/api/upload?dir=test" enctype="multipart/form-data" method="post">
- <input multiple name="files" type="file">
- <button>Submit</button>
-</form>
-</body>
-</html>
diff --git a/src/main/resources/views/upload.rocker.html b/src/main/resources/views/upload.rocker.html
new file mode 100644
index 0000000..441a570
--- /dev/null
+++ b/src/main/resources/views/upload.rocker.html
@@ -0,0 +1,8 @@
+@args (String content)
+
+@layout.template("Upload") -> {
+<form action="/api/upload?dir=test" enctype="multipart/form-data" method="post">
+ <input multiple name="files" type="file">
+ <button>Submit</button>
+</form>
+}