Skip to content

Commit e9375c0

Browse files
authored
Merge pull request #12 from Shigerello/main
Add support for directory structure
2 parents 6996981 + 88cf08f commit e9375c0

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/main/kotlin/com/github/serverfrog/bitburnerplugin/action/BitburnerPushAction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ class BitburnerPushAction() : AnAction(MyBundle.message("pushActionLabel")) {
1010

1111
override fun actionPerformed(e: AnActionEvent) {
1212
val file = e.dataContext.getData(CommonDataKeys.VIRTUAL_FILE)?.canonicalFile!!
13-
PushToBitburner.pushToBitburner(file, e.project)
13+
PushToBitburner.pushToBitburner(file, e.project!!)
1414
}
1515
}

src/main/kotlin/com/github/serverfrog/bitburnerplugin/bitburner/PushToBitburner.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import java.net.URI
1111
import java.net.http.HttpClient
1212
import java.net.http.HttpRequest
1313
import java.net.http.HttpResponse
14+
import java.nio.file.Paths
1415
import java.util.*
1516

1617

@@ -22,14 +23,14 @@ class PushToBitburner {
2223
private val notificationGroup: NotificationGroup = NotificationGroupManager.getInstance()
2324
.getNotificationGroup(MyBundle.message("groupId"))
2425

25-
fun pushToBitburner(file: VirtualFile, project: Project?) {
26+
fun pushToBitburner(file: VirtualFile, project: Project) {
2627

2728

2829
val client = HttpClient.newBuilder().build()
2930
val request = HttpRequest.newBuilder()
3031
.header("Authorization", "Bearer " + BitburnerSettings.getAuthToken())
3132
.uri(uri)
32-
.POST(HttpRequest.BodyPublishers.ofString(createJson(file)))
33+
.POST(HttpRequest.BodyPublishers.ofString(createJson(file, project)))
3334
.build()
3435
val response = client.send(request, HttpResponse.BodyHandlers.ofString())
3536
val status = response.statusCode()
@@ -42,8 +43,9 @@ class PushToBitburner {
4243

4344
}
4445

45-
private fun createJson(file: VirtualFile): String {
46-
val fileName = file.name.replace("/[\\\\|/]+/g", "/")
46+
private fun createJson(file: VirtualFile, project: Project): String {
47+
val relativePath = Paths.get(project.basePath!!).relativize(Paths.get(file.path))
48+
val fileName = relativePath.toString().replace("[\\\\|/]+".toRegex(), "/")
4749

4850
val fileContent = String(file.contentsToByteArray())
4951
val encode = String(Base64.getEncoder().encode(fileContent.toByteArray()))

0 commit comments

Comments
 (0)