Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ plugins {
id("com.itsaky.androidide.desugaring")
alias(libs.plugins.sentry)
alias(libs.plugins.google.services)
kotlin("plugin.serialization")
}

fun propOrEnv(name: String): String =
Expand Down Expand Up @@ -318,7 +317,6 @@ dependencies {
implementation(libs.common.markwon.linkify)
implementation(libs.commons.text.v1140)

implementation(libs.kotlinx.serialization.json)
// Koin for Dependency Injection
implementation(libs.koin.android)
implementation(libs.androidx.security.crypto)
Expand All @@ -340,9 +338,6 @@ dependencies {

// Pebble template engine
implementation("io.pebbletemplates:pebble:4.1.1")

// Jackson JSON parsing dependency
implementation("com.fasterxml.jackson.core:jackson-databind:2.15.2")
}

tasks.register("downloadDocDb") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import io.pebbletemplates.pebble.PebbleEngine
import io.pebbletemplates.pebble.loader.StringLoader
import java.util.concurrent.ConcurrentHashMap
import io.pebbletemplates.pebble.template.PebbleTemplate
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import android.os.Environment.getExternalStorageDirectory
import kotlinx.serialization.builtins.UByteArraySerializer
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.ToNumberPolicy
import com.google.gson.reflect.TypeToken
import okio.ByteString.Companion.toByteString


Expand Down Expand Up @@ -71,6 +72,10 @@ class WebServer(private val config: ServerConfig) {
private val brotliCompression : String = "br"
private val pebbleEngine = PebbleEngine.Builder().loader(StringLoader()).build()
private val templateCache = ConcurrentHashMap<Int, PebbleTemplate>()
private val gson: Gson = GsonBuilder()
.setObjectToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE)
.create()
private val dbContextType = object : TypeToken<Map<String, Any>>() {}.type
private var bookshelfTemplateId : Int = -1;
private val HTTP_INTERNAL_SERVER_ERROR = 500
private val HTTP_NOT_FOUND = 404
Expand Down Expand Up @@ -452,8 +457,10 @@ class WebServer(private val config: ServerConfig) {
}

// Load JSON data into a template context Map<> for instantiation
val mapper = ObjectMapper()
val context: Map<String, Any> = mapper.readValue(dbContent.toString(Charsets.UTF_8), object : TypeReference<Map<String, Any>>() {})
val dbContentStr = dbContent.toString(Charsets.UTF_8)
if (dbContentStr.isBlank() || dbContentStr.trim() == "null")
throw Exception("Template ID $templateId has empty or null JSON context")
val context: Map<String, Any> = gson.fromJson(dbContentStr, dbContextType)

// Evaluate template with loaded data and return the output
val sw = StringWriter()
Expand Down
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ buildscript {
dependencies {
classpath(libs.kotlin.gradle.plugin)
classpath(libs.nav.safe.args.gradle.plugin)
classpath(libs.kotlin.serialization.plugin)
}
}

Expand Down
3 changes: 0 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ koinAndroid = "4.1.1"
kotlin = "2.3.0"
kotlin-coroutines = "1.9.0"
kotlinxCoroutinesCore = "1.10.2"
kotlinxSerializationJson = "1.9.0"
lifecycleViewmodelKtx = "2.7.0"
paletteKtx = "1.0.0"
playServicesOssLicenses = "17.1.0"
Expand Down Expand Up @@ -128,7 +127,6 @@ google-genai = { module = "com.google.genai:google-genai", version.ref = "google
gson-v2101 = { module = "com.google.code.gson:gson", version.ref = "gson" }
koin-android = { module = "io.insert-koin:koin-android", version.ref = "koinAndroid" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinxCoroutinesCore" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }
room-compiler = { module = "androidx.room:room-compiler", version.ref = "room" }
room-ktx = { module = "androidx.room:room-ktx", version.ref = "room" }

Expand Down Expand Up @@ -307,7 +305,6 @@ tooling-slf4j = { module = "org.slf4j:slf4j-api", version = "2.0.12" }
# Classpaths
android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "agp" }
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-serialization-plugin = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" }
nav-safe-args-gradle-plugin = { module = "androidx.navigation:navigation-safe-args-gradle-plugin", version.ref = "androidx-navigation" }
maven-publish = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "maven-publish-plugin" }
androidx-monitor = { group = "androidx.test", name = "monitor", version.ref = "monitor" }
Expand Down
Loading