From 5e207a1a648d1ac685aa951871c241b85b35ed0e Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 2 Mar 2024 19:10:56 +0300 Subject: [PATCH] Move data out of resources. Deliver as separate directory. --- src/main/kotlin/center/sciprog/Application.kt | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/center/sciprog/Application.kt b/src/main/kotlin/center/sciprog/Application.kt index d268bba..e156f69 100644 --- a/src/main/kotlin/center/sciprog/Application.kt +++ b/src/main/kotlin/center/sciprog/Application.kt @@ -10,10 +10,16 @@ import io.ktor.server.routing.get import io.ktor.server.routing.routing import space.kscience.dataforge.context.Context 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.readSiteData import space.kscience.snark.ktor.site +import kotlin.io.path.Path +import kotlin.io.path.exists + @Suppress("unused") fun Application.spcModule() { @@ -27,12 +33,20 @@ fun Application.spcModule() { val snark = context.request(SnarkHtml) -// val dataDirectory = Path.of( -// environment.config.tryGetString("ktor.environment.dataDirectory") ?: "data" -// ) + val dataDirectoryString = environment.config.propertyOrNull("snark.dataDirectory")?.getString() ?: "data" + + val dataDirectory = Path(dataDirectoryString) + + if(!dataDirectory.exists()){ + error("Data directory at $dataDirectory is not resolved") + } 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 {