diff --git a/README.md b/README.md index d9bb807..381e1c8 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,10 @@ function uploadapk(){ export PLAYSTORE_SERVICE_ACCOUNT_JSON_FILE=$2 #If proxy needed - #PLAY_STORE_PROXY=192.168.0.1:3128 + #PLAYSTORE_PROXY=192.168.0.1:3128 + + #Increase connection timeout + #PLAYSTORE_CONNECTION_TIMEOUT=PT6M apk_package=$(apkinfoextractor $path_to_apk | jq '.package') export APP_PACKAGE_NAME=$apk_package diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreApi.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreApi.kt index cfbc78a..2a54e27 100644 --- a/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreApi.kt +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreApi.kt @@ -1,62 +1,62 @@ package com.github.vacxe.googleplaycli import com.github.vacxe.googleplaycli.actions.* -import com.google.api.client.googleapis.GoogleUtils import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport -import com.google.api.client.http.javanet.NetHttpTransport +import com.google.api.client.http.HttpRequestInitializer import com.google.api.client.json.jackson2.JacksonFactory import com.google.api.services.androidpublisher.AndroidPublisher import com.google.api.services.androidpublisher.AndroidPublisherScopes import com.google.auth.http.HttpCredentialsAdapter import com.google.auth.oauth2.ServiceAccountCredentials -import java.io.ByteArrayInputStream -import java.io.File -import java.io.FileInputStream import java.io.InputStream -import java.net.InetSocketAddress -import java.net.Proxy +import java.time.Duration class PlayStoreApi(serviceAccountInputStream: InputStream, appName: String) : - Edit, - Apks, - Bundles, - Deobfuscationfiles, - Details, - ExpansionFiles, - Images, - Listings, - Testers, - Tracks, - Internalappsharingartifacts, - Orders, - Reviews, - Inappproducts { + Edit, + Apks, + Bundles, + Deobfuscationfiles, + Details, + ExpansionFiles, + Images, + Listings, + Testers, + Tracks, + Internalappsharingartifacts, + Orders, + Reviews, + Inappproducts { override val androidPublisher: AndroidPublisher init { val accountCredentials = ServiceAccountCredentials - .fromStream(serviceAccountInputStream) - .createScoped(listOf(AndroidPublisherScopes.ANDROIDPUBLISHER)) - - val proxy : String? = System.getenv("PLAY_STORE_PROXY") - val httpTransport = when { - proxy != null -> { - val proxyParameters = proxy.split(":") - NetHttpTransport.Builder() - .trustCertificates(GoogleUtils.getCertificateTrustStore()) - .setProxy(Proxy(Proxy.Type.HTTP, InetSocketAddress(proxyParameters[0], proxyParameters[1].toInt()))) - .build() - } - else -> GoogleNetHttpTransport.newTrustedTransport() + .fromStream(serviceAccountInputStream) + .createScoped(listOf(AndroidPublisherScopes.ANDROIDPUBLISHER)) + + System.getenv("PLAYSTORE_PROXY")?.run { + val proxyParameters = split(":") + System.setProperty("proxyHost", proxyParameters[0]) + System.setProperty("proxyPort", proxyParameters[1]) } + val connectionTimeout = (System.getenv("PLAYSTORE_CONNECTION_TIMEOUT") ?: "PT2M") + .let { Duration.parse(it) } + androidPublisher = AndroidPublisher.Builder( - httpTransport, - JacksonFactory.getDefaultInstance(), - HttpCredentialsAdapter(accountCredentials) + GoogleNetHttpTransport.newTrustedTransport(), + JacksonFactory.getDefaultInstance(), + setHttpTimeout(HttpCredentialsAdapter(accountCredentials), connectionTimeout) ) - .setApplicationName(appName) - .build() + .setApplicationName(appName) + .build() + } + + private fun setHttpTimeout(requestInitializer: HttpRequestInitializer, timeout: Duration): HttpRequestInitializer { + return HttpRequestInitializer { httpRequest -> + requestInitializer.initialize(httpRequest) + httpRequest.connectTimeout = timeout.toMillis().toInt() + httpRequest.readTimeout = timeout.toMillis().toInt() + } } } diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreCli.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreCli.kt index 924aeed..44bf336 100644 --- a/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreCli.kt +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreCli.kt @@ -1,5 +1,6 @@ package com.github.vacxe.googleplaycli +import com.github.ajalt.clikt.core.CliktCommand import com.github.vacxe.googleplaycli.dsl.addCmd import com.github.vacxe.googleplaycli.dsl.cmd import com.github.vacxe.googleplaycli.dsl.subcmd @@ -78,5 +79,12 @@ fun main(args: Array) { addCmd { Commands.Inappproducts.Patch() } addCmd { Commands.Inappproducts.Update() } } + addCmd { + object : CliktCommand(name = "version", help = "Library version code") { + override fun run() { + println("0.3.7") + } + } + } }.main(args) } diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/actions/Deobfuscationfiles.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/actions/Deobfuscationfiles.kt index 5aa4271..00da9e6 100644 --- a/src/main/kotlin/com/github/vacxe/googleplaycli/actions/Deobfuscationfiles.kt +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/actions/Deobfuscationfiles.kt @@ -2,6 +2,7 @@ package com.github.vacxe.googleplaycli.actions import com.github.vacxe.googleplaycli.actions.model.DeobfuscationfilesUploadModel import com.github.vacxe.googleplaycli.core.constants.MediaType.MIME_TYPE_APK +import com.github.vacxe.googleplaycli.core.constants.MediaType.MIME_TYPE_STREAM import com.google.api.client.http.AbstractInputStreamContent import com.google.api.client.http.FileContent import com.google.api.services.androidpublisher.AndroidPublisher @@ -11,7 +12,7 @@ interface Deobfuscationfiles : BaseAction { fun deobfuscationFilesUpload(model: DeobfuscationfilesUploadModel): DeobfuscationFilesUploadResponse { val edits: AndroidPublisher.Edits = androidPublisher.edits() val editId = model.editId ?: edits.insert(model.packageName, null).execute().id - val deobfuscation: AbstractInputStreamContent = FileContent(MIME_TYPE_APK, model.deobfuscation) + val deobfuscation: AbstractInputStreamContent = FileContent(MIME_TYPE_STREAM, model.deobfuscation) return edits.deobfuscationfiles().upload(model.packageName, editId, model.apkVersionCode, model.deobfuscationFileType, deobfuscation).execute() } } diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/core/constants/MediaType.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/core/constants/MediaType.kt index 71ce57c..f351385 100644 --- a/src/main/kotlin/com/github/vacxe/googleplaycli/core/constants/MediaType.kt +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/core/constants/MediaType.kt @@ -2,5 +2,6 @@ package com.github.vacxe.googleplaycli.core.constants object MediaType { const val MIME_TYPE_APK = "application/vnd.android.package-archive" + const val MIME_TYPE_STREAM = "application/octet-stream" const val MIME_TYPE_PNG = "image/png" } \ No newline at end of file