From d2edd43a09b9ac341a75a38324dfe9d9f618add8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 11 Dec 2022 09:03:34 +0600 Subject: [PATCH 1/8] Update gradle.properties --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index c9e05a1..564db0a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ kotlin.code.style=official -library_version=0.12.2 +library_version=0.13.0 From 29aa1271a6d878f22a463c5364b89800954da8be Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 11 Dec 2022 09:04:51 +0600 Subject: [PATCH 2/8] Update libs.versions.toml --- gradle/libs.versions.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d8340be..a52fa49 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,11 +1,11 @@ [versions] -kt = "1.7.20" -kt-serialization = "1.4.0" +kt = "1.7.22" +kt-serialization = "1.4.1" kt-coroutines = "1.6.4" -klock = "3.2.0" -ktor = "2.1.2" +klock = "3.4.0" +ktor = "2.2.1" gh-release = "2.4.1" From 14006652eeae1409c0caa0fb1bf0bb9f51b9eaca Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 11 Dec 2022 09:08:39 +0600 Subject: [PATCH 3/8] Add files via upload --- publish.gradle | 20 ++++++++++++++++++++ publish.kpsb | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/publish.gradle b/publish.gradle index ea83c7a..b0d96bd 100644 --- a/publish.gradle +++ b/publish.gradle @@ -42,20 +42,40 @@ publishing { maven { name = "GithubPackages" url = uri("https://maven.pkg.github.com/InsanusMokrassar/SauceNaoAPI") + credentials { username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER') password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD') } + + } + } + if (project.hasProperty('GITEA_TOKEN') || System.getenv('GITEA_TOKEN') != null) { + maven { + name = "Gitea" + url = uri("https://git.inmo.dev/api/packages/InsanusMokrassar/maven") + + credentials(HttpHeaderCredentials) { + name = "Authorization" + value = project.hasProperty('GITEA_TOKEN') ? project.property('GITEA_TOKEN') : System.getenv('GITEA_TOKEN') + } + + authentication { + header(HttpHeaderAuthentication) + } + } } if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) { maven { name = "sonatype" url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") + credentials { username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER') password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD') } + } } } diff --git a/publish.kpsb b/publish.kpsb index dc85fd2..dd1ee2f 100644 --- a/publish.kpsb +++ b/publish.kpsb @@ -1 +1 @@ -{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/SauceNaoAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"SauceNao API","description":"SauceNao API library","url":"https://insanusmokrassar.github.io/${project.name}","vcsUrl":"https://github.com/insanusmokrassar/${project.name}.git","developers":[{"id":"InsanusMokrassar","name":"Ovsyannikov Alexey","eMail":"ovsyannikov.alexey95@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/SauceNaoAPI"},{"name":"sonatype","url":"https://oss.sonatype.org/service/local/staging/deploy/maven2/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"}}} \ No newline at end of file +{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/SauceNaoAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"SauceNao API","description":"SauceNao API library","url":"https://insanusmokrassar.github.io/${project.name}","vcsUrl":"https://github.com/insanusmokrassar/${project.name}.git","developers":[{"id":"InsanusMokrassar","name":"Ovsyannikov Alexey","eMail":"ovsyannikov.alexey95@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/SauceNaoAPI"},{"name":"Gitea","url":"https://git.inmo.dev/api/packages/InsanusMokrassar/maven","credsType":{"type":"dev.inmo.kmppscriptbuilder.core.models.MavenPublishingRepository.CredentialsType.HttpHeaderCredentials","headerName":"Authorization","headerValueProperty":"GITEA_TOKEN"}},{"name":"sonatype","url":"https://oss.sonatype.org/service/local/staging/deploy/maven2/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"}}} \ No newline at end of file From a84f31f88806b94888ef643fcc8fb3073fdc4f88 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 11 Dec 2022 09:10:12 +0600 Subject: [PATCH 4/8] Update build_and_publish.yml --- .github/workflows/build_and_publish.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build_and_publish.yml b/.github/workflows/build_and_publish.yml index ad8472e..4f6e8c6 100644 --- a/.github/workflows/build_and_publish.yml +++ b/.github/workflows/build_and_publish.yml @@ -16,6 +16,11 @@ jobs: mv gradle.properties.tmp gradle.properties - name: Build run: ./gradlew build + - name: Publish to Gitea + continue-on-error: true + run: ./gradlew publishAllPublicationsToGiteaRepository + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} - name: Publish run: ./gradlew publishAllPublicationsToGithubPackagesRepository --no-parallel -x signJsPublication -x signJvmPublication -x signKotlinMultiplatformPublication continue-on-error: true From 962d079f465ddb0a10b3d934ef76c820ea774fcd Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 11 Dec 2022 09:17:08 +0600 Subject: [PATCH 5/8] Update build_and_publish.yml --- .github/workflows/build_and_publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_publish.yml b/.github/workflows/build_and_publish.yml index 4f6e8c6..40ce2f9 100644 --- a/.github/workflows/build_and_publish.yml +++ b/.github/workflows/build_and_publish.yml @@ -22,7 +22,7 @@ jobs: env: GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} - name: Publish - run: ./gradlew publishAllPublicationsToGithubPackagesRepository --no-parallel -x signJsPublication -x signJvmPublication -x signKotlinMultiplatformPublication + run: ./gradlew publishAllPublicationsToGithubPackagesRepository --no-parallel continue-on-error: true env: GITHUBPACKAGES_USER: ${{ github.actor }} From 9c25b082969a42dc194e1275ef962028bb88702f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 11 Dec 2022 11:13:38 +0600 Subject: [PATCH 6/8] add opportunity to subscribe on quota changes --- CHANGELOG.md | 2 ++ .../saucenaoapi/utils/RequestQuotaManager.kt | 25 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e1ea64..9e2411c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # SauceNaoAPI Changelog +## 0.13.0 + ## 0.12.2 * Versions: diff --git a/src/commonMain/kotlin/dev/inmo/saucenaoapi/utils/RequestQuotaManager.kt b/src/commonMain/kotlin/dev/inmo/saucenaoapi/utils/RequestQuotaManager.kt index 4843527..32c86a4 100644 --- a/src/commonMain/kotlin/dev/inmo/saucenaoapi/utils/RequestQuotaManager.kt +++ b/src/commonMain/kotlin/dev/inmo/saucenaoapi/utils/RequestQuotaManager.kt @@ -9,17 +9,34 @@ import dev.inmo.saucenaoapi.models.Header import dev.inmo.saucenaoapi.models.LimitsState import kotlinx.coroutines.* import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.merge import kotlin.math.max import kotlin.math.min internal class RequestQuotaManager ( scope: CoroutineScope ) { - private var longQuota = 1 - private var shortQuota = 1 - private var longMaxQuota = 1 - private var shortMaxQuota = 1 + private val longQuotaFlow = MutableStateFlow(1) + private val shortQuotaFlow = MutableStateFlow(1) + private val longMaxQuotaFlow = MutableStateFlow(1) + private val shortMaxQuotaFlow = MutableStateFlow(1) + private var longQuota by longQuotaFlow::value + private var shortQuota by shortQuotaFlow::value + private var longMaxQuota by longMaxQuotaFlow::value + private var shortMaxQuota by shortMaxQuotaFlow::value + val limitsStateFlow = merge( + longQuotaFlow, shortQuotaFlow, longMaxQuotaFlow, shortMaxQuotaFlow + ).map { _ -> + LimitsState( + shortMaxQuota, + longMaxQuota, + shortQuota, + longQuota + ) + } val limitsState: LimitsState get() = LimitsState( shortMaxQuota, From cf8ec465133f41e84008575edf5aadda7a464ac4 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 11 Dec 2022 11:17:28 +0600 Subject: [PATCH 7/8] fill changelog and improve RequestQoutaManager API --- CHANGELOG.md | 7 +++++++ .../saucenaoapi/utils/RequestQuotaManager.kt | 21 ++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e2411c..5931d6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ ## 0.13.0 +* Versions: + * `Kotlin`: `1.7.20` -> `1.7.22` + * `Serialization`: `1.4.0` -> `1.4.1` + * `Klock`: `3.2.0` -> `3.4.0` + * `Ktor`: `2.1.2` -> `2.2.1` +* Now it is possible to subscribe onto API limits changes + ## 0.12.2 * Versions: diff --git a/src/commonMain/kotlin/dev/inmo/saucenaoapi/utils/RequestQuotaManager.kt b/src/commonMain/kotlin/dev/inmo/saucenaoapi/utils/RequestQuotaManager.kt index 32c86a4..e325928 100644 --- a/src/commonMain/kotlin/dev/inmo/saucenaoapi/utils/RequestQuotaManager.kt +++ b/src/commonMain/kotlin/dev/inmo/saucenaoapi/utils/RequestQuotaManager.kt @@ -10,6 +10,7 @@ import dev.inmo.saucenaoapi.models.LimitsState import kotlinx.coroutines.* import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.merge import kotlin.math.max @@ -18,15 +19,19 @@ import kotlin.math.min internal class RequestQuotaManager ( scope: CoroutineScope ) { - private val longQuotaFlow = MutableStateFlow(1) - private val shortQuotaFlow = MutableStateFlow(1) - private val longMaxQuotaFlow = MutableStateFlow(1) - private val shortMaxQuotaFlow = MutableStateFlow(1) - private var longQuota by longQuotaFlow::value - private var shortQuota by shortQuotaFlow::value - private var longMaxQuota by longMaxQuotaFlow::value - private var shortMaxQuota by shortMaxQuotaFlow::value + private val _longQuotaFlow = MutableStateFlow(1) + private val _shortQuotaFlow = MutableStateFlow(1) + private val _longMaxQuotaFlow = MutableStateFlow(1) + private val _shortMaxQuotaFlow = MutableStateFlow(1) + private var longQuota by _longQuotaFlow::value + private var shortQuota by _shortQuotaFlow::value + private var longMaxQuota by _longMaxQuotaFlow::value + private var shortMaxQuota by _shortMaxQuotaFlow::value + val longQuotaFlow = _longQuotaFlow.asStateFlow() + val shortQuotaFlow = _shortQuotaFlow.asStateFlow() + val longMaxQuotaFlow = _longMaxQuotaFlow.asStateFlow() + val shortMaxQuotaFlow = _shortMaxQuotaFlow.asStateFlow() val limitsStateFlow = merge( longQuotaFlow, shortQuotaFlow, longMaxQuotaFlow, shortMaxQuotaFlow ).map { _ -> From bcc36dbfb7c003acc2f1029f9c02d726ecceaa19 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 11 Dec 2022 11:19:08 +0600 Subject: [PATCH 8/8] provide opportunity to get public properties from sauce nao api --- src/commonMain/kotlin/dev/inmo/saucenaoapi/SauceNaoAPI.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/commonMain/kotlin/dev/inmo/saucenaoapi/SauceNaoAPI.kt b/src/commonMain/kotlin/dev/inmo/saucenaoapi/SauceNaoAPI.kt index fcbce0e..4984397 100644 --- a/src/commonMain/kotlin/dev/inmo/saucenaoapi/SauceNaoAPI.kt +++ b/src/commonMain/kotlin/dev/inmo/saucenaoapi/SauceNaoAPI.kt @@ -52,8 +52,12 @@ data class SauceNaoAPI( private val timeManager = TimeManager(subscope) private val quotaManager = RequestQuotaManager(subscope) - val limitsState: LimitsState - get() = quotaManager.limitsState + val limitsState: LimitsState by quotaManager::limitsState + val longQuotaFlow by quotaManager::longQuotaFlow + val shortQuotaFlow by quotaManager::shortQuotaFlow + val longMaxQuotaFlow by quotaManager::longMaxQuotaFlow + val shortMaxQuotaFlow by quotaManager::shortMaxQuotaFlow + val limitsStateFlow by quotaManager::limitsStateFlow private val requestsJob = subscope.launch { for ((callback, requestBuilder) in requestsChannel) {