@@ -14,6 +14,13 @@ import kotlin.io.path.fileSize
1414import kotlin.io.path.writeText
1515import kotlin.jvm.optionals.getOrNull
1616
17+ /* *
18+ * Simple builder to collect debug files and upload them to a custom bytebin server
19+ * Ex:
20+ * <pre class="prettyprint">
21+ * DebugBuilder.builder("https://bytebin.lucko.me/")...
22+ * </pre>
23+ */
1724class DebugBuilder private constructor(private val uploadServer : String ) {
1825 private val fileToUpload: MutableList <DebugFile > = mutableListOf ()
1926 private var maxPartFileSize: Long = 2_097_152
@@ -27,12 +34,19 @@ class DebugBuilder private constructor(private val uploadServer: String) {
2734 .setLenient()
2835 .create()
2936
30-
37+ /* *
38+ * Add a debug file RAW into the debug zip
39+ */
3140 fun addFile (file : DebugFile ): DebugBuilder {
3241 fileToUpload.add(file)
3342 return this
3443 }
35-
44+ /* *
45+ * Add a debug file RAW into the debug zip
46+ * @param filePath to collect into the zip
47+ * @param fileType to display in the frontend
48+ * @param uiTabName to display tn the frontend
49+ */
3650 fun addFile (
3751 filePath : Path ,
3852 fileType : FileType ,
@@ -42,28 +56,45 @@ class DebugBuilder private constructor(private val uploadServer: String) {
4256 return this
4357 }
4458
45-
59+ /* *
60+ * Add a text as a file into the debug zip
61+ * @param text to collect into the zip
62+ * @param uiTabName to display tn the frontend
63+ */
4664 fun addText (text : String , uiTabName : String ): DebugBuilder {
4765 val textFile = Files .createTempFile(tempPrefix, " .txt" )
4866 textFile.writeText(text)
4967 fileToUpload.add(DebugFile (textFile, FileType .TEXT , uiTabName))
5068 return this
5169 }
52-
70+ /* *
71+ * Add a json string as a file into the debug zip
72+ * @param json to collect into the zip
73+ * @param uiTabName to display tn the frontend
74+ */
5375 fun addJson (json : String , uiTabName : String ): DebugBuilder {
5476 val textFile = Files .createTempFile(tempPrefix, " .json" )
5577 textFile.writeText(json)
5678 fileToUpload.add(DebugFile (textFile, FileType .JSON , uiTabName))
5779 return this
5880 }
59-
60- fun addYAML (json : String , uiTabName : String ): DebugBuilder {
81+ /* *
82+ * Add a yaml string as a file into the debug zip
83+ * @param yaml to collect into the zip
84+ * @param uiTabName to display tn the frontend
85+ */
86+ fun addYAML (yaml : String , uiTabName : String ): DebugBuilder {
6187 val textFile = Files .createTempFile(tempPrefix, " .yml" )
62- textFile.writeText(json )
88+ textFile.writeText(yaml )
6389 fileToUpload.add(DebugFile (textFile, FileType .YAML , uiTabName))
6490 return this
6591 }
66-
92+ /* *
93+ * Upload all collected files in a zip with a debug.json to a custom bytebin server.
94+ * @throws IllegalStateException when the zip file is bigger than 2mb(binary)
95+ * @throws IllegalStateException when no code was returned
96+ * @return an object with the given server and the uploaded code
97+ */
6798 @Throws(IllegalStateException ::class )
6899 fun upload (): DebugUploadResult {
69100 val tempFolder = Files .createTempDirectory(tempPrefix)
@@ -95,6 +126,10 @@ class DebugBuilder private constructor(private val uploadServer: String) {
95126 }
96127
97128 companion object {
129+ /* *
130+ * Creates a builder instance with the given bytebin server
131+ * @param uploadServer bytebin server base url
132+ */
98133 @JvmStatic
99134 fun builder (uploadServer : String ): DebugBuilder = DebugBuilder (uploadServer)
100135 }
0 commit comments