Update to version 2.2.0-alpha-2 and add database query provider

Bumped project version to `2.2.0-alpha-2` in `build.gradle.kts`. Introduced `SampleEntity`, `SamplePartEntity`, and `SampleEntityQueryProvider` for database handling. Added `SampleDao` with a sample query function. Updated SVG utilities with a `viewbox` extension and enhanced `RequestHandler` to set content type for HTML responses.
This commit is contained in:
2025-06-09 14:06:17 +02:00
parent c1f756eb79
commit 2871697329
6 changed files with 116 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ plugins {
}
group = "nl.astraeus"
version = "2.1.2"
version = "2.2.0-alpha-2"
repositories {
mavenCentral()

View File

@@ -14,6 +14,10 @@ fun SVG.height(height: Int) {
this.attributes["height"] = "$height"
}
fun SVG.viewbox(viewbox: String) {
this.attributes["viewbox"] = viewbox
}
fun SVG.svgStyle(
name: String,
vararg props: Pair<String, String>

View File

@@ -0,0 +1,11 @@
package nl.astraeus.vst.chip.db
object SampleDao {
val queryProvider = SampleEntityQueryProvider
fun getSample(waveHash: String): ByteArray {
return byteArrayOf()
}
}

View File

@@ -0,0 +1,50 @@
package nl.astraeus.vst.chip.db
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import nl.astraeus.vst.base.db.Entity
data class SampleEntity(
var sha1Hash: String,
var filename: String,
var length: Int,
var created: Instant = Clock.System.now(),
var updated: Instant = Clock.System.now(),
) : Entity {
override fun getPK(): Array<Any> = arrayOf(sha1Hash)
override fun setPK(pks: Array<Any>) {
sha1Hash = pks[0] as String
}
}
data class SamplePartEntity(
var sha1Hash: String,
var part: Int,
var from: Int,
var to: Int,
var data: ByteArray,
) : Entity {
override fun getPK(): Array<Any> = arrayOf(sha1Hash, part)
override fun setPK(pks: Array<Any>) {
sha1Hash = pks[0] as String
part = pks[1] as Int
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is SamplePartEntity) return false
if (sha1Hash != other.sha1Hash) return false
if (part != other.part) return false
return true
}
override fun hashCode(): Int {
var result = sha1Hash.hashCode()
result = 31 * result + part
return result
}
}

View File

@@ -0,0 +1,49 @@
package nl.astraeus.vst.chip.db
import nl.astraeus.vst.base.db.QueryProvider
import nl.astraeus.vst.base.db.SqlStatement
import nl.astraeus.vst.base.db.toDateTimeInstant
import nl.astraeus.vst.base.db.toSqlTimestamp
import java.sql.ResultSet
val SAMPLE_CREATE_QUERY = """
CREATE TABLE SAMPLES (
SHA1HASH TEXT,
FILENAME TEXT,
LENGTH NUMBER,
CREATED TIMESTAMP
)
""".trimIndent()
object SampleEntityQueryProvider : QueryProvider<SampleEntity>() {
override val tableName: String
get() = "SAMPLES"
override val resultSetMapper: (ResultSet) -> SampleEntity
get() = { rs ->
SampleEntity(
rs.getString(1),
rs.getString(2),
rs.getInt(3),
rs.getTimestamp(4).toDateTimeInstant()
)
}
override val insert: SqlStatement<SampleEntity>
get() = SqlStatement(
"""
INSERT INTO $tableName (
SHA1HASH,
LENGTH,
CREATED
) VALUES (
?,?,?,?
)
""".trimIndent()
) { ps ->
ps.setString(1, sha1Hash)
ps.setString(2, filename)
ps.setInt(3, length)
ps.setTimestamp(4, updated.toSqlTimestamp())
}
override val update: SqlStatement<SampleEntity>
get() = TODO("Not yet implemented")
}

View File

@@ -112,6 +112,7 @@ class PatchHandler(
}
httpSession?.setAttribute("html-session", VstSession(patchId))
exchange.responseHeaders.put(Headers.CONTENT_TYPE, "text/html; charset=utf-8")
exchange.responseSender.send(generateIndex(title, scriptName, null))
} else {
val patchId = generateId()