From f4970955cb6c61a99d6b9d35edc8d4148ef8728d Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 12 Dec 2020 21:33:40 +0300 Subject: [PATCH] Fix local exports for temporary files. --- .../hep/dataforge/vision/solid/fileExport.kt | 3 +- .../kotlin/hep/dataforge/vision/headers.kt | 28 +++++++++---------- .../vision/three/server/serverExtensions.kt | 4 ++- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/playground/src/jvmMain/kotlin/hep/dataforge/vision/solid/fileExport.kt b/playground/src/jvmMain/kotlin/hep/dataforge/vision/solid/fileExport.kt index 3dc29df2..5471bb2e 100644 --- a/playground/src/jvmMain/kotlin/hep/dataforge/vision/solid/fileExport.kt +++ b/playground/src/jvmMain/kotlin/hep/dataforge/vision/solid/fileExport.kt @@ -1,5 +1,6 @@ package ru.mipt.npm.sat +import hep.dataforge.vision.ResourceLocation import hep.dataforge.vision.VisionManager import hep.dataforge.vision.html.fragment import hep.dataforge.vision.solid.box @@ -15,5 +16,5 @@ fun main() { } } - fragment.makeFile() + fragment.makeFile(resourceLocation = ResourceLocation.LOCAL) } \ No newline at end of file diff --git a/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/headers.kt b/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/headers.kt index f8e138c5..80e5b250 100644 --- a/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/headers.kt +++ b/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/headers.kt @@ -102,23 +102,21 @@ internal fun fileCssHeader( @DFExperimental public fun Context.Companion.scriptHeader( scriptResource: String, - basePath: Path?, + basePath: Path, resourceLocation: ResourceLocation, ): HtmlFragment { - val targetPath = if (basePath == null) null else { - when (resourceLocation) { - ResourceLocation.LOCAL -> checkOrStoreFile( - basePath, - Path.of(DATAFORGE_ASSETS_PATH), - scriptResource - ) - ResourceLocation.SYSTEM -> checkOrStoreFile( - Path.of("."), - Path.of(System.getProperty("user.home")).resolve(DATAFORGE_ASSETS_PATH), - scriptResource - ) - ResourceLocation.EMBED -> null - } + val targetPath = when (resourceLocation) { + ResourceLocation.LOCAL -> checkOrStoreFile( + basePath, + Path.of(DATAFORGE_ASSETS_PATH), + scriptResource + ) + ResourceLocation.SYSTEM -> checkOrStoreFile( + Path.of("."), + Path.of(System.getProperty("user.home")).resolve(DATAFORGE_ASSETS_PATH), + scriptResource + ) + ResourceLocation.EMBED -> null } return if (targetPath == null) { embedScriptHeader(scriptResource) diff --git a/visionforge-threejs/visionforge-threejs-server/src/jvmMain/kotlin/hep/dataforge/vision/three/server/serverExtensions.kt b/visionforge-threejs/visionforge-threejs-server/src/jvmMain/kotlin/hep/dataforge/vision/three/server/serverExtensions.kt index fa7a0488..a4d84a23 100644 --- a/visionforge-threejs/visionforge-threejs-server/src/jvmMain/kotlin/hep/dataforge/vision/three/server/serverExtensions.kt +++ b/visionforge-threejs/visionforge-threejs-server/src/jvmMain/kotlin/hep/dataforge/vision/three/server/serverExtensions.kt @@ -10,6 +10,7 @@ import hep.dataforge.vision.makeFile import hep.dataforge.vision.scriptHeader import hep.dataforge.vision.solid.SolidGroup import hep.dataforge.vision.solid.SolidManager +import java.nio.file.Files import java.nio.file.Path public actual val visionContext: Context = Global.context("vision-server") { @@ -38,6 +39,7 @@ public fun HtmlVisionFragment.makeFile( resourceLocation: ResourceLocation = ResourceLocation.SYSTEM, show: Boolean = true, ) { - val scriptHeader = Context.scriptHeader("/js/visionforge-three.js", path, resourceLocation) + val actualPath = path ?: Files.createTempFile("tempPlot", ".html") + val scriptHeader = Context.scriptHeader("/js/visionforge-three.js", actualPath, resourceLocation) makeFile(visionManager, path = path, show = show, title = title, headers = arrayOf(scriptHeader)) } \ No newline at end of file