Factorio Mod Portal Publish task - reduce logging
This commit is contained in:
parent
a8784db5b2
commit
394361001f
3 changed files with 18 additions and 18 deletions
|
|
@ -5,9 +5,6 @@ import io.ktor.client.engine.cio.CIO
|
||||||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
||||||
import io.ktor.client.plugins.defaultRequest
|
import io.ktor.client.plugins.defaultRequest
|
||||||
import io.ktor.client.plugins.logging.LogLevel
|
import io.ktor.client.plugins.logging.LogLevel
|
||||||
import io.ktor.client.plugins.logging.Logger
|
|
||||||
import io.ktor.client.plugins.logging.Logging
|
|
||||||
import io.ktor.client.plugins.logging.SIMPLE
|
|
||||||
import io.ktor.client.request.forms.MultiPartFormDataContent
|
import io.ktor.client.request.forms.MultiPartFormDataContent
|
||||||
import io.ktor.client.request.forms.formData
|
import io.ktor.client.request.forms.formData
|
||||||
import io.ktor.client.request.forms.submitForm
|
import io.ktor.client.request.forms.submitForm
|
||||||
|
|
@ -27,6 +24,10 @@ import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import org.gradle.api.internal.tasks.userinput.UserInputHandler
|
import org.gradle.api.internal.tasks.userinput.UserInputHandler
|
||||||
import org.gradle.kotlin.dsl.support.useToRun
|
import org.gradle.kotlin.dsl.support.useToRun
|
||||||
|
import io.ktor.client.plugins.logging.Logger as KtorLogger
|
||||||
|
import io.ktor.client.plugins.logging.Logging as KtorLogging
|
||||||
|
import org.gradle.api.logging.Logger as GradleLogger
|
||||||
|
import org.gradle.api.logging.Logging as GradleLogging
|
||||||
|
|
||||||
|
|
||||||
class FactorioModPortalPublishClient(
|
class FactorioModPortalPublishClient(
|
||||||
|
|
@ -39,9 +40,15 @@ class FactorioModPortalPublishClient(
|
||||||
private val modPortalBaseURl: String,
|
private val modPortalBaseURl: String,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
private val logger: GradleLogger = GradleLogging.getLogger(this::class.java)
|
||||||
|
|
||||||
private fun client() = HttpClient(CIO) {
|
private fun client() = HttpClient(CIO) {
|
||||||
install(Logging) {
|
install(KtorLogging) {
|
||||||
logger = Logger.SIMPLE
|
logger = object : KtorLogger {
|
||||||
|
override fun log(message: String) {
|
||||||
|
this@FactorioModPortalPublishClient.logger.debug(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
level = LogLevel.ALL
|
level = LogLevel.ALL
|
||||||
}
|
}
|
||||||
install(ContentNegotiation) {
|
install(ContentNegotiation) {
|
||||||
|
|
@ -76,7 +83,7 @@ class FactorioModPortalPublishClient(
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
upload(initUploadResponse)
|
upload(initUploadResponse)
|
||||||
} else {
|
} else {
|
||||||
println("aborting upload")
|
logger.lifecycle("aborting mod '$modName' upload")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -90,10 +97,10 @@ class FactorioModPortalPublishClient(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
println(response)
|
// println(response)
|
||||||
val initUploadResponse: InitUploadResponse =
|
val initUploadResponse: InitUploadResponse =
|
||||||
Json.decodeFromString(InitUploadResponse.serializer(), response.bodyAsText())
|
Json.decodeFromString(InitUploadResponse.serializer(), response.bodyAsText())
|
||||||
println(initUploadResponse)
|
// println(initUploadResponse)
|
||||||
|
|
||||||
require(response.status.isSuccess()) { "init upload request failed" }
|
require(response.status.isSuccess()) { "init upload request failed" }
|
||||||
|
|
||||||
|
|
@ -123,11 +130,11 @@ class FactorioModPortalPublishClient(
|
||||||
val submitUploadResponse =
|
val submitUploadResponse =
|
||||||
Json.decodeFromString(SubmitUploadResponse.serializer(), response.bodyAsText())
|
Json.decodeFromString(SubmitUploadResponse.serializer(), response.bodyAsText())
|
||||||
|
|
||||||
println(response)
|
// logger(response)
|
||||||
println(submitUploadResponse)
|
// println(submitUploadResponse)
|
||||||
require(response.status.isSuccess() && submitUploadResponse is SubmitUploadResponse.Success) {
|
require(response.status.isSuccess() && submitUploadResponse is SubmitUploadResponse.Success) {
|
||||||
"upload request failed"
|
"upload request failed"
|
||||||
}
|
}
|
||||||
println("Mod uploaded successfully! ${modPortalBaseURl.removeSuffix("/")}/$modName")
|
logger.lifecycle("Mod '$modName' uploaded successfully! ${modPortalBaseURl.removeSuffix("/")}/$modName")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,6 @@ abstract class FactorioModPublishTask @Inject constructor(
|
||||||
@TaskAction
|
@TaskAction
|
||||||
fun deploy() = runBlocking {
|
fun deploy() = runBlocking {
|
||||||
|
|
||||||
|
|
||||||
val userInputHandler = services.get<UserInputHandler>()
|
val userInputHandler = services.get<UserInputHandler>()
|
||||||
|
|
||||||
val portalUploadEndpoint = URLBuilder(portalApiUrl.get())
|
val portalUploadEndpoint = URLBuilder(portalApiUrl.get())
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,6 @@ import kotlinx.serialization.json.JsonElement
|
||||||
import kotlinx.serialization.json.jsonObject
|
import kotlinx.serialization.json.jsonObject
|
||||||
|
|
||||||
|
|
||||||
//@Serializable
|
|
||||||
//data class InitUploadRequest(
|
|
||||||
// @SerialName("mod") val modName: String,
|
|
||||||
//)
|
|
||||||
|
|
||||||
|
|
||||||
@Serializable(with = InitUploadResponse.Serializer::class)
|
@Serializable(with = InitUploadResponse.Serializer::class)
|
||||||
sealed interface InitUploadResponse {
|
sealed interface InitUploadResponse {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue