aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclimb2019-04-03 21:12:37 +0200
committerclimb2019-04-03 21:12:37 +0200
commitf8f09b016bdd6c93195e87a65afb2d154e399d0f (patch)
tree4b93a359336428223d0909bdfe24ea19662b4bf1
parent644fcfd8f97c90180485e686d0b593efb986541e (diff)
added sqlite database and tried to get rocker templating to work
-rw-r--r--build.gradle27
-rw-r--r--src/main/kotlin/App.kt54
-rw-r--r--src/main/resources/views/test.rocker.html (renamed from src/main/resources/test.rocker.html)0
-rw-r--r--src/main/resources/views/upload.html (renamed from src/main/resources/upload.html)0
4 files changed, 71 insertions, 10 deletions
diff --git a/build.gradle b/build.gradle
index 7269324..70d4365 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,6 +1,7 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.11'
- id "com.fizzed.rocker" version "1.2.1"
+ // id "com.fizzed.rocker" version "1.2.1"
+ id 'nu.studer.rocker' version '0.4'
id 'java'
}
@@ -9,17 +10,31 @@ version "1.0-SNAPSHOT"
repositories {
jcenter()
- mavenCentral()
+ // mavenCentral()
}
+/*
sourceSets {
main {
rocker {
- srcDir('src/main/kotlin')
+ srcDir("src/main/resources")
}
}
}
+*/
+rockerVersion = '0.20.0'
+
+rocker {
+ main {
+ optimize = true
+ templateDir = file('src/resources/views')
+ outputDir = file('src/resources/compiled-views')
+ }
+}
+
+
+/*
buildscript {
repositories {
mavenLocal()
@@ -33,13 +48,17 @@ buildscript {
classpath "gradle.plugin.com.fizzed:rocker-gradle-plugin:1.2.1"
}
}
+*/
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
compile "io.javalin:javalin:2.8.0"
compile "org.slf4j:slf4j-simple:1.7.26"
compile "com.fasterxml.jackson.core:jackson-databind:2.9.8"
- compile "com.fizzed:rocker-compiler:0.14.0"
+ // compile "com.fizzed:rocker-compiler:0.14.0"
+ compile 'org.jetbrains.exposed:exposed:0.13.2'
+ compile "org.xerial:sqlite-jdbc:3.21.0.1"
+ // compile group: 'com.fizzed', name: 'rocker-runtime', version: '1.2.1'
}
compileKotlin {
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
+}
+
+
+
diff --git a/src/main/resources/test.rocker.html b/src/main/resources/views/test.rocker.html
index 8deedcd..8deedcd 100644
--- a/src/main/resources/test.rocker.html
+++ b/src/main/resources/views/test.rocker.html
diff --git a/src/main/resources/upload.html b/src/main/resources/views/upload.html
index 16c8a94..16c8a94 100644
--- a/src/main/resources/upload.html
+++ b/src/main/resources/views/upload.html