generated from JetBrains/intellij-platform-plugin-template
-
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.
[ML4SE-169] Removed Web* states. Object for requests
- Loading branch information
mikrise2
committed
Oct 17, 2023
1 parent
e4f089e
commit 9a473f3
Showing
5 changed files
with
77 additions
and
168 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/requests/FileRequests.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,64 @@ | ||
package org.jetbrains.research.tasktracker.requests | ||
|
||
import com.intellij.openapi.diagnostic.Logger | ||
import io.ktor.client.* | ||
import io.ktor.client.engine.cio.* | ||
import io.ktor.client.request.forms.* | ||
import io.ktor.http.* | ||
import kotlinx.coroutines.runBlocking | ||
import org.jetbrains.research.tasktracker.tracking.activity.ActivityTracker | ||
import org.jetbrains.research.tasktracker.tracking.fileEditor.FileEditorTracker | ||
import org.jetbrains.research.tasktracker.tracking.toolWindow.ToolWindowTracker | ||
import org.jetbrains.research.tasktracker.tracking.webcam.WebCamTracker | ||
import org.jetbrains.research.tasktracker.ui.main.panel.storage.MainPanelStorage | ||
import java.io.File | ||
|
||
object FileRequests { | ||
|
||
private val client = HttpClient(CIO) | ||
private val logger: Logger = Logger.getInstance(FileRequests::class.java) | ||
|
||
fun sendToolWindowFiles(toolWindowTracker: ToolWindowTracker) = toolWindowTracker.getLogFiles().all { | ||
sendFile(it, "toolWindow") | ||
} | ||
|
||
fun sendActivityFiles(activityTracker: ActivityTracker) = activityTracker.getLogFiles().all { | ||
sendFile(it, "activity") | ||
} | ||
|
||
fun sendFileEditorFiles(fileEditorTracker: FileEditorTracker) = fileEditorTracker.getLogFiles().all { | ||
sendFile(it, "fileEditor") | ||
} | ||
|
||
fun sendWebcamFiles(webCamTracker: WebCamTracker) = webCamTracker.getLogFiles().all { | ||
sendFile(it, "webCam") | ||
} | ||
|
||
fun sendSurvey(surveyFiles: List<File>) = surveyFiles.all { sendFile(it, "survey") } | ||
|
||
@Suppress("TooGenericExceptionCaught") | ||
private fun sendFile(file: File, subdir: String) = runBlocking { | ||
try { | ||
client.submitFormWithBinaryData( | ||
url = "$DOMAIN/upload-document/${MainPanelStorage.currentResearchId}?subdir=$subdir", | ||
formData = formData { | ||
append( | ||
"file", | ||
file.readBytes(), | ||
Headers.build { | ||
append( | ||
HttpHeaders.ContentDisposition, "filename=\"${file.name}\"" | ||
) | ||
} | ||
) | ||
} | ||
) | ||
true | ||
} catch (e: Exception) { | ||
logger.warn("Server interaction error! File to send: ${file.path}", e) | ||
false | ||
} | ||
} | ||
|
||
const val DOMAIN = "http://3.249.245.244:8888" | ||
} |
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
Empty file.
This file was deleted.
Oops, something went wrong.