Skip to content

Commit

Permalink
update log
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcheng1982 committed Oct 1, 2024
1 parent efd1e0a commit 3261162
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class WriteLocalFileTool(private val config: WriteLocalFileConfig) :
logger.info("File to write: ${request.filename}")
try {
val savePath = calculateSavePath(request)
logger.info("File save path: ${savePath.toAbsolutePath()}")
if (StringUtils.isNotEmpty(request.content)) {
Files.writeString(
savePath, request.content, StandardCharsets.UTF_8,
Expand All @@ -35,15 +36,13 @@ class WriteLocalFileTool(private val config: WriteLocalFileConfig) :
)
} else if (StringUtils.isNotEmpty(request.url)) {
FileUtils.copyURLToFile(
URI(request.url).toURL(),
URI(request.url!!).toURL(),
savePath.toFile()
)
}
return WriteLocalFileResponse(
savePath.toAbsolutePath().toString()
).also {
logger.info("Response: $it")
}
)
} catch (e: Exception) {
throw ToolExecutionException(this, e)
}
Expand All @@ -59,9 +58,7 @@ class WriteLocalFileTool(private val config: WriteLocalFileConfig) :

private fun calculateSavePath(request: WriteLocalFileRequest): Path {
val basePath = StringUtils.trimToNull(config.basePath)
val saveFileDir = basePath?.run {
Path.of(this)
} ?: Path.of(".")
val saveFileDir = Path.of(basePath ?: ".")
val filename = StringUtils.trimToNull(request.filename)
return saveFileDir.resolve(filename ?: UUID.randomUUID().toString())
.toAbsolutePath()
Expand Down

0 comments on commit 3261162

Please sign in to comment.