mirror of
https://github.com/InsanusMokrassar/SauceNaoAPI.git
synced 2024-12-23 05:07:12 +00:00
add Header adaptation
This commit is contained in:
parent
29aa4a41e6
commit
b91240149b
@ -0,0 +1,9 @@
|
||||
package com.github.insanusmokrassar.SauceNaoAPI.additional
|
||||
|
||||
typealias AccountType = Int
|
||||
const val defaultAccountType: AccountType = 1 // "basic"
|
||||
|
||||
typealias UserId = Int
|
||||
|
||||
const val SHORT_TIME_RECALCULATING_MILLIS = 30 * 1000
|
||||
const val LONG_TIME_RECALCULATING_MILLIS = 24 * 60 * 60 * 1000
|
@ -0,0 +1,43 @@
|
||||
package com.github.insanusmokrassar.SauceNaoAPI.additional.header
|
||||
|
||||
import com.github.insanusmokrassar.SauceNaoAPI.additional.*
|
||||
import com.github.insanusmokrassar.SauceNaoAPI.models.Header
|
||||
|
||||
val Header.shortLimitStatus: LimitStatus
|
||||
get() = LimitStatus(
|
||||
shortRemaining ?: Int.MAX_VALUE,
|
||||
shortLimit ?: Int.MAX_VALUE
|
||||
)
|
||||
|
||||
val Header.longLimitStatus: LimitStatus
|
||||
get() = LimitStatus(
|
||||
longRemaining ?: Int.MAX_VALUE,
|
||||
longLimit ?: Int.MAX_VALUE
|
||||
)
|
||||
|
||||
val Header.limits
|
||||
get() = Limits(shortLimitStatus, longLimitStatus)
|
||||
|
||||
val Header.accountInfo
|
||||
get() = AccountInfo(
|
||||
accountType ?: defaultAccountType,
|
||||
userId,
|
||||
limits
|
||||
)
|
||||
|
||||
|
||||
data class LimitStatus(
|
||||
val remain: Int = Int.MAX_VALUE,
|
||||
val limit: Int = Int.MAX_VALUE
|
||||
)
|
||||
|
||||
data class Limits(
|
||||
val short: LimitStatus = LimitStatus(),
|
||||
val long: LimitStatus = LimitStatus()
|
||||
)
|
||||
|
||||
data class AccountInfo(
|
||||
val accountType: AccountType = defaultAccountType,
|
||||
val userId: UserId? = null,
|
||||
val limits: Limits = Limits()
|
||||
)
|
@ -0,0 +1,24 @@
|
||||
package com.github.insanusmokrassar.SauceNaoAPI.additional.header
|
||||
|
||||
import com.github.insanusmokrassar.SauceNaoAPI.models.Header
|
||||
|
||||
data class IndexInfo(
|
||||
val id: Int,
|
||||
val status: Int = 500,
|
||||
val results: Int = 0,
|
||||
val parent_id: Int? = null
|
||||
)
|
||||
|
||||
val Header.adaptedIndexes: List<IndexInfo>
|
||||
get() = indexes.mapNotNull {
|
||||
it ?.let { _ ->
|
||||
it.id ?.let { id ->
|
||||
IndexInfo(
|
||||
id,
|
||||
it.status ?: 500, // Serverside error if not set
|
||||
it.results ?: 0,
|
||||
it.parent_id
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.github.insanusmokrassar.SauceNaoAPI.additional.header
|
||||
|
||||
import com.github.insanusmokrassar.SauceNaoAPI.models.Header
|
||||
|
||||
val Header.queryPreview
|
||||
get() = QueryResultPreview(
|
||||
queryImageDisplay,
|
||||
queryImage
|
||||
)
|
||||
|
||||
val Header.queryResults
|
||||
get() = QueryResultsMetainfo(
|
||||
status ?: 500, // server_side error if status field was not set up
|
||||
resultsCount ?: 0,
|
||||
minSimilarity ?: 0F,
|
||||
searchDepth ?: 128,
|
||||
queryPreview,
|
||||
adaptedIndexes
|
||||
)
|
||||
|
||||
data class QueryResultPreview(
|
||||
val imageDisplay: String? = null, // something like "userdata/uuid.png",
|
||||
val image: String? = null // something like "uuid.jpg"
|
||||
)
|
||||
|
||||
data class QueryResultsMetainfo(
|
||||
val status: Int = 0,
|
||||
val count: Int = 0,
|
||||
val minSimilarity: Float = 0F,
|
||||
val searchDepth: Int = 128,
|
||||
val preview: QueryResultPreview = QueryResultPreview(),
|
||||
val indexesInfo: List<IndexInfo> = emptyList()
|
||||
) {
|
||||
val isOk: Boolean = status == 0
|
||||
val isClientSideError = status < 0
|
||||
val isServerSideError = status > 0
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.github.insanusmokrassar.SauceNaoAPI.additional.header
|
||||
|
||||
import com.github.insanusmokrassar.SauceNaoAPI.models.Header
|
||||
|
||||
data class ResultMetainfo(
|
||||
val accountInfo: AccountInfo = AccountInfo(),
|
||||
val resultsInfo: QueryResultsMetainfo = QueryResultsMetainfo()
|
||||
)
|
||||
|
||||
val Header.adapted
|
||||
get() = ResultMetainfo(
|
||||
accountInfo,
|
||||
queryResults
|
||||
)
|
@ -8,22 +8,22 @@ import kotlinx.serialization.json.Json
|
||||
@Serializable
|
||||
data class Header(
|
||||
@SerialName("status")
|
||||
val status: Int,
|
||||
val status: Int? = null,
|
||||
@SerialName("results_requested")
|
||||
val resultsRequested: Int,
|
||||
val resultsRequested: Int? = null,
|
||||
@Serializable(IndexesSerializer::class)
|
||||
@SerialName("index")
|
||||
val indexes: List<HeaderIndex?>,
|
||||
val indexes: List<HeaderIndex?> = emptyList(),
|
||||
@SerialName("search_depth")
|
||||
val searchDepth: Int,
|
||||
val searchDepth: Int? = null,
|
||||
@SerialName("minimum_similarity")
|
||||
val minSimilarity: Float,
|
||||
@SerialName("query_image_display")
|
||||
val queryImageDisplay: String, // something like "userdata/uuid.png",
|
||||
@SerialName("query_image")
|
||||
val queryImage: String, // something like "uuid.jpg"
|
||||
val minSimilarity: Float? = null,
|
||||
@SerialName("results_returned")
|
||||
val resultsCount: Int,
|
||||
val resultsCount: Int? = null,
|
||||
@SerialName("query_image_display")
|
||||
val queryImageDisplay: String? = null, // something like "userdata/uuid.png",
|
||||
@SerialName("query_image")
|
||||
val queryImage: String? = null, // something like "uuid.jpg"
|
||||
@SerialName("short_remaining")
|
||||
val shortRemaining: Int? = null,
|
||||
@SerialName("long_remaining")
|
||||
@ -33,7 +33,7 @@ data class Header(
|
||||
@SerialName("long_limit")
|
||||
val longLimit: Int? = null,
|
||||
@SerialName("account_type")
|
||||
val accountType: String? = null,
|
||||
val accountType: Int? = null,
|
||||
@SerialName("user_id")
|
||||
val userId: Int? = null
|
||||
)
|
||||
|
@ -4,8 +4,8 @@ import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class HeaderIndex(
|
||||
val status: Int,
|
||||
val id: Int,
|
||||
val results: Int = 0,
|
||||
val status: Int? = null,
|
||||
val id: Int? = null,
|
||||
val results: Int? = null,
|
||||
val parent_id: Int? = null
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user