aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/App.kt
diff options
context:
space:
mode:
authorclimb2019-04-03 21:12:37 +0200
committerclimb2019-04-03 21:12:37 +0200
commitf8f09b016bdd6c93195e87a65afb2d154e399d0f (patch)
tree4b93a359336428223d0909bdfe24ea19662b4bf1 /src/main/kotlin/App.kt
parent644fcfd8f97c90180485e686d0b593efb986541e (diff)
added sqlite database and tried to get rocker templating to work
Diffstat (limited to 'src/main/kotlin/App.kt')
-rw-r--r--src/main/kotlin/App.kt54
1 files changed, 48 insertions, 6 deletions
diff --git a/src/main/kotlin/App.kt b/src/main/kotlin/App.kt
index b5d6042..fe1abef 100644
--- a/src/main/kotlin/App.kt
+++ b/src/main/kotlin/App.kt
@@ -1,23 +1,44 @@
package space.anity
-import com.fizzed.rocker.*
+import com.fizzed.rocker.Rocker
import io.javalin.*
import io.javalin.core.util.*
import io.javalin.rendering.*
import io.javalin.rendering.template.TemplateUtil.model
+import org.jetbrains.exposed.sql.Database
+import org.jetbrains.exposed.sql.SchemaUtils
+import org.jetbrains.exposed.sql.Table
+import org.jetbrains.exposed.sql.transactions.TransactionManager
+import org.jetbrains.exposed.sql.transactions.transaction
import java.io.*
import java.nio.file.*
+import java.sql.Connection
+
fun main(args: Array<String>) {
+
+ // TODO outsource to class
+ val db : Database = Database.connect("jdbc:sqlite:main.db", "org.sqlite.JDBC")
+ TransactionManager.manager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE
+
+ transaction {
+ SchemaUtils.createMissingTablesAndColumns(FileLocation, UserData, General)
+ }
+
+
val fileHome = "files"
- JavalinRenderer.register(
+ /*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!"))
+ val templateTest = Rocker.template("test.rocker.html").bind("message", "Testy testy!").render().toString()
+ println(templateTest)
+ // ctx.render("views/test.rocker.html", model("message", "Testy testy!"))
}
// TODO: Fix possible security issue with "../"
@@ -36,16 +57,37 @@ fun main(args: Array<String>) {
}
}
- app.get("/upload") { ctx -> ctx.redirect("/upload.html") }
+ app.get("/upload") { ctx -> ctx.redirect("/views/upload.html") }
// TODO: Fix possible security issue with "../"
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")
- ctx.redirect("/upload.html")
+ ctx.redirect("/views/upload.html")
} else
throw BadRequestResponse("Error: Please enter a filename.")
}
}
}
+
+// DB tables
+object FileLocation : Table() {
+ val id = integer("id").autoIncrement().primaryKey()
+ val location = text("location")
+}
+
+object UserData : Table() {
+ // only for multiple users: val id = integer("id").autoIncrement().primaryKey()
+ val uname = varchar("uname", 24).primaryKey() // remove if ID
+ val pwd = varchar("pwd", 64)
+}
+
+object General : Table() {
+ // redundant: val id = integer("id").autoIncrement().primaryKey()
+ val isSetup = integer("isSetup").primaryKey() // remove pKey if ID // boolean -> 0:1
+ // TODO if not isSetup show other front page
+}
+
+
+