Merge pull request #152 from InsanusMokrassar/0.13.0

0.13.0
This commit is contained in:
InsanusMokrassar 2022-12-11 11:40:49 +06:00 committed by GitHub
commit ae9a7baf50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 73 additions and 13 deletions

View File

@ -16,8 +16,13 @@ jobs:
mv gradle.properties.tmp gradle.properties mv gradle.properties.tmp gradle.properties
- name: Build - name: Build
run: ./gradlew build run: ./gradlew build
- name: Publish to Gitea
continue-on-error: true
run: ./gradlew publishAllPublicationsToGiteaRepository
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
- name: Publish - name: Publish
run: ./gradlew publishAllPublicationsToGithubPackagesRepository --no-parallel -x signJsPublication -x signJvmPublication -x signKotlinMultiplatformPublication run: ./gradlew publishAllPublicationsToGithubPackagesRepository --no-parallel
continue-on-error: true continue-on-error: true
env: env:
GITHUBPACKAGES_USER: ${{ github.actor }} GITHUBPACKAGES_USER: ${{ github.actor }}

View File

@ -1,5 +1,14 @@
# SauceNaoAPI Changelog # SauceNaoAPI Changelog
## 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 ## 0.12.2
* Versions: * Versions:

View File

@ -1,3 +1,3 @@
kotlin.code.style=official kotlin.code.style=official
library_version=0.12.2 library_version=0.13.0

View File

@ -1,11 +1,11 @@
[versions] [versions]
kt = "1.7.20" kt = "1.7.22"
kt-serialization = "1.4.0" kt-serialization = "1.4.1"
kt-coroutines = "1.6.4" kt-coroutines = "1.6.4"
klock = "3.2.0" klock = "3.4.0"
ktor = "2.1.2" ktor = "2.2.1"
gh-release = "2.4.1" gh-release = "2.4.1"

View File

@ -42,20 +42,40 @@ publishing {
maven { maven {
name = "GithubPackages" name = "GithubPackages"
url = uri("https://maven.pkg.github.com/InsanusMokrassar/SauceNaoAPI") url = uri("https://maven.pkg.github.com/InsanusMokrassar/SauceNaoAPI")
credentials { credentials {
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER') 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') 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)) { if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
maven { maven {
name = "sonatype" name = "sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials { credentials {
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER') 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') password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
} }
} }
} }
} }

View File

@ -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"}}} {"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"}}}

View File

@ -52,8 +52,12 @@ data class SauceNaoAPI(
private val timeManager = TimeManager(subscope) private val timeManager = TimeManager(subscope)
private val quotaManager = RequestQuotaManager(subscope) private val quotaManager = RequestQuotaManager(subscope)
val limitsState: LimitsState val limitsState: LimitsState by quotaManager::limitsState
get() = 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 { private val requestsJob = subscope.launch {
for ((callback, requestBuilder) in requestsChannel) { for ((callback, requestBuilder) in requestsChannel) {

View File

@ -9,17 +9,39 @@ import dev.inmo.saucenaoapi.models.Header
import dev.inmo.saucenaoapi.models.LimitsState import dev.inmo.saucenaoapi.models.LimitsState
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel 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 import kotlin.math.max
import kotlin.math.min import kotlin.math.min
internal class RequestQuotaManager ( internal class RequestQuotaManager (
scope: CoroutineScope scope: CoroutineScope
) { ) {
private var longQuota = 1 private val _longQuotaFlow = MutableStateFlow(1)
private var shortQuota = 1 private val _shortQuotaFlow = MutableStateFlow(1)
private var longMaxQuota = 1 private val _longMaxQuotaFlow = MutableStateFlow(1)
private var shortMaxQuota = 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 { _ ->
LimitsState(
shortMaxQuota,
longMaxQuota,
shortQuota,
longQuota
)
}
val limitsState: LimitsState val limitsState: LimitsState
get() = LimitsState( get() = LimitsState(
shortMaxQuota, shortMaxQuota,