Move data out of resources. Deliver as separate directory.

This commit is contained in:
Alexander Nozik 2024-03-02 19:10:56 +03:00
parent 7053c866f9
commit 5e207a1a64

View File

@ -10,10 +10,16 @@ import io.ktor.server.routing.get
import io.ktor.server.routing.routing import io.ktor.server.routing.routing
import space.kscience.dataforge.context.Context import space.kscience.dataforge.context.Context
import space.kscience.dataforge.context.request import space.kscience.dataforge.context.request
import space.kscience.dataforge.workspace.resources import space.kscience.dataforge.data.forEach
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.workspace.FileData
import space.kscience.dataforge.workspace.directory
import space.kscience.snark.html.SnarkHtml import space.kscience.snark.html.SnarkHtml
import space.kscience.snark.html.readSiteData import space.kscience.snark.html.readSiteData
import space.kscience.snark.ktor.site import space.kscience.snark.ktor.site
import kotlin.io.path.Path
import kotlin.io.path.exists
@Suppress("unused") @Suppress("unused")
fun Application.spcModule() { fun Application.spcModule() {
@ -27,12 +33,20 @@ fun Application.spcModule() {
val snark = context.request(SnarkHtml) val snark = context.request(SnarkHtml)
// val dataDirectory = Path.of( val dataDirectoryString = environment.config.propertyOrNull("snark.dataDirectory")?.getString() ?: "data"
// environment.config.tryGetString("ktor.environment.dataDirectory") ?: "data"
// ) val dataDirectory = Path(dataDirectoryString)
if(!dataDirectory.exists()){
error("Data directory at $dataDirectory is not resolved")
}
val siteData = snark.readSiteData(context) { val siteData = snark.readSiteData(context) {
resources(snark.io, "common", "home", "magprog") directory(snark.io, Name.EMPTY, dataDirectory)
}
siteData.forEach { namedData ->
println("${namedData.name}: ${namedData.meta[FileData.FILE_PATH_KEY]}")
} }
routing { routing {