-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
101 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Gradle Releases -> https://github.com/gradle/gradle/releases | ||
libraryGroup = com.simiacryptus.skyenet | ||
libraryVersion = 1.0.83 | ||
libraryVersion = 1.0.84 | ||
gradleVersion = 7.6.1 | ||
kotlin.daemon.jvmargs=-Xmx2g |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
webui/src/main/kotlin/com/simiacryptus/diff/AddShellExecutionLinks.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.simiacryptus.diff | ||
|
||
import com.simiacryptus.skyenet.webui.application.ApplicationInterface | ||
import com.simiacryptus.skyenet.webui.session.SocketManagerBase | ||
import com.simiacryptus.skyenet.webui.util.MarkdownUtil | ||
import java.util.* | ||
import java.io.BufferedReader | ||
import java.io.InputStreamReader | ||
|
||
fun SocketManagerBase.addShellExecutionLinks( | ||
response: String, | ||
ui: ApplicationInterface | ||
): String { | ||
val shellCodePattern = """(?s)(?<![^\n])```shell\n(.*?)\n```""".toRegex() | ||
return shellCodePattern.replace(response) { matchResult -> | ||
val shellCode = matchResult.groupValues[1] | ||
val executionId = UUID.randomUUID().toString() | ||
val executionTask = ui.newTask(false) | ||
val executeButton = hrefLink("Execute", classname = "href-link cmd-button") { | ||
try { | ||
val process = Runtime.getRuntime().exec(arrayOf("sh", "-c", shellCode)) | ||
val reader = BufferedReader(InputStreamReader(process.inputStream)) | ||
val errorReader = BufferedReader(InputStreamReader(process.errorStream)) | ||
val output = StringBuilder() | ||
var line: String? | ||
while (reader.readLine().also { line = it } != null) { | ||
output.append(line).append("\n") | ||
} | ||
while (errorReader.readLine().also { line = it } != null) { | ||
output.append("Error: ").append(line).append("\n") | ||
} | ||
val exitCode = process.waitFor() | ||
output.append("Exit code: $exitCode") | ||
executionTask.complete(MarkdownUtil.renderMarkdown("```\n${output.toString()}\n```", ui = ui)) | ||
} catch (e: Throwable) { | ||
executionTask.error(null, e) | ||
} | ||
} | ||
""" | ||
```shell | ||
$shellCode | ||
``` | ||
<div id="execution-$executionId"> | ||
$executeButton | ||
${executionTask.placeholder} | ||
</div> | ||
""".trimIndent() | ||
} | ||
} |