Skip to content

Commit

Permalink
28
Browse files Browse the repository at this point in the history
28
  • Loading branch information
umerov1999 committed May 22, 2023
1 parent fef2b85 commit c00579a
Show file tree
Hide file tree
Showing 92 changed files with 3,072 additions and 1,802 deletions.
8 changes: 4 additions & 4 deletions app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ object Constants {
const val API_VERSION = "5.131"
const val AUTH_VERSION = API_VERSION

const val DATABASE_FENRIR_VERSION = 27
const val DATABASE_TEMPORARY_VERSION = 5
const val DATABASE_FENRIR_VERSION = 28
const val DATABASE_TEMPORARY_VERSION = 6
const val EXPORT_SETTINGS_FORMAT = 1
const val forceDeveloperMode = BuildConfig.FORCE_DEVELOPER_MODE

Expand All @@ -17,8 +17,8 @@ object Constants {
const val FILE_PROVIDER_AUTHORITY: String = BuildConfig.APPLICATION_ID + ".file_provider"
const val VK_ANDROID_APP_VERSION_NAME = "8.15"
const val VK_ANDROID_APP_VERSION_CODE = "15271"
const val KATE_APP_VERSION_NAME = "99 lite"
const val KATE_APP_VERSION_CODE = "535"
const val KATE_APP_VERSION_NAME = "100 lite"
const val KATE_APP_VERSION_CODE = "536"
const val API_ID: Int = BuildConfig.VK_API_APP_ID
const val SECRET: String = BuildConfig.VK_CLIENT_SECRET
const val PHOTOS_PATH = "DCIM/Fenrir"
Expand Down
14 changes: 14 additions & 0 deletions app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/impl/AbsApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ internal open class AbsApi(val accountId: Long, private val restProvider: IServi
.blockingGet()
}
}
/*
response.executeErrors.nonNullNoEmpty {
it[0].requireNonNull { sit ->
throw Exceptions.propagate(ApiException(sit))
}
}
*/
response.response ?: throw NullPointerException("VK return null response")
}
}
Expand All @@ -254,6 +261,13 @@ internal open class AbsApi(val accountId: Long, private val restProvider: IServi
.blockingGet()
}
}
/*
response.executeErrors.nonNullNoEmpty {
it[0].requireNonNull { sit ->
throw Exceptions.propagate(ApiException(sit))
}
}
*/
Completable.complete()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
package dev.ragnarok.fenrir.api.impl

import dev.ragnarok.fenrir.Constants
import dev.ragnarok.fenrir.api.IServiceProvider
import dev.ragnarok.fenrir.api.TokenType
import dev.ragnarok.fenrir.api.interfaces.IStoreApi
import dev.ragnarok.fenrir.api.model.VKApiStickerSetsData
import dev.ragnarok.fenrir.api.model.Dictionary
import dev.ragnarok.fenrir.api.model.Items
import dev.ragnarok.fenrir.api.model.VKApiSticker
import dev.ragnarok.fenrir.api.model.VKApiStickerSet
import dev.ragnarok.fenrir.api.model.VKApiStickersKeywords
import dev.ragnarok.fenrir.api.services.IStoreService
import io.reactivex.rxjava3.core.Single

internal class StoreApi(accountId: Long, provider: IServiceProvider) :
AbsApi(accountId, provider), IStoreApi {
override val stickerKeywords: Single<VKApiStickersKeywords>
override val stickerKeywords: Single<Dictionary<VKApiStickersKeywords>>
get() = provideService(IStoreService(), TokenType.USER)
.flatMap { service ->
service
.getStickersKeywords("var dic=API.store.getStickersKeywords({'v':'" + Constants.API_VERSION + "','aliases':1,'all_products':1}).dictionary;return {'keywords': [email protected], 'words_stickers': [email protected]_stickers};")
.getStickersKeywords()
.map(extractResponseWithErrorHandling())
}
override val stickers: Single<VKApiStickerSetsData>
override val stickersSets: Single<Items<VKApiStickerSet.Product>>
get() = provideService(IStoreService(), TokenType.USER)
.flatMap { service ->
service
.getStickers("var pack = API.store.getProducts({'v':'" + Constants.API_VERSION + "','extended':1,'filters':'active','type':'stickers'}); var recent = API.messages.getRecentStickers(); return {'sticker_pack': pack, 'recent': recent};")
.getStickersSets()
.map(extractResponseWithErrorHandling())
}
override val recentStickers: Single<Items<VKApiSticker>>
get() = provideService(IStoreService(), TokenType.USER)
.flatMap { service ->
service
.getRecentStickers()
.map(extractResponseWithErrorHandling())
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package dev.ragnarok.fenrir.api.interfaces

import dev.ragnarok.fenrir.api.model.VKApiStickerSetsData
import dev.ragnarok.fenrir.api.model.Dictionary
import dev.ragnarok.fenrir.api.model.Items
import dev.ragnarok.fenrir.api.model.VKApiSticker
import dev.ragnarok.fenrir.api.model.VKApiStickerSet
import dev.ragnarok.fenrir.api.model.VKApiStickersKeywords
import io.reactivex.rxjava3.core.Single

interface IStoreApi {
val stickerKeywords: Single<VKApiStickersKeywords>
val stickers: Single<VKApiStickerSetsData>
val stickerKeywords: Single<Dictionary<VKApiStickersKeywords>>
val stickersSets: Single<Items<VKApiStickerSet.Product>>
val recentStickers: Single<Items<VKApiSticker>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.ragnarok.fenrir.api.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
class Dictionary<I> {
@SerialName("count")
var count = 0

@SerialName("dictionary")
var dictionary: ArrayList<I>? = null
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import kotlinx.serialization.Serializable

@Serializable
class VKApiStickersKeywords {
@SerialName("words_stickers")
var words_stickers: List<List<VKApiSticker>?>? = null
@SerialName("user_stickers")
var user_stickers: List<VKApiSticker?>? = null

@SerialName("keywords")
var keywords: List<List<String>?>? = null
@SerialName("words")
var words: List<String?>? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ open class VKResponse {

/*
@SerialName("execute_errors")
var executeErrors: List<Error>? = null
*/
var executeErrors: List<Error?>? = null
*/
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.ragnarok.fenrir.api.rest

import dev.ragnarok.fenrir.api.model.Dictionary
import dev.ragnarok.fenrir.api.model.Items
import dev.ragnarok.fenrir.api.model.response.BaseResponse
import dev.ragnarok.fenrir.kJson
Expand Down Expand Up @@ -44,6 +45,10 @@ abstract class IServiceRest {
return BaseResponse.serializer(Items.serializer(serial))
}

inline fun <reified T : Any> dictionary(serial: KSerializer<T>): KSerializer<BaseResponse<Dictionary<T>>> {
return BaseResponse.serializer(Dictionary.serializer(serial))
}

private fun toSerialStr(obj: Any?): String? {
return when (obj) {
is String -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
package dev.ragnarok.fenrir.api.services

import dev.ragnarok.fenrir.api.model.VKApiStickerSetsData
import dev.ragnarok.fenrir.api.model.Dictionary
import dev.ragnarok.fenrir.api.model.Items
import dev.ragnarok.fenrir.api.model.VKApiSticker
import dev.ragnarok.fenrir.api.model.VKApiStickerSet
import dev.ragnarok.fenrir.api.model.VKApiStickersKeywords
import dev.ragnarok.fenrir.api.model.response.BaseResponse
import dev.ragnarok.fenrir.api.rest.IServiceRest
import io.reactivex.rxjava3.core.Single

class IStoreService : IServiceRest() {
fun getStickers(code: String?): Single<BaseResponse<VKApiStickerSetsData>> {
fun getRecentStickers(): Single<BaseResponse<Items<VKApiSticker>>> {
return rest.request(
"execute",
form("code" to code),
base(VKApiStickerSetsData.serializer())
"messages.getRecentStickers",
null,
items(VKApiSticker.serializer())
)
}

fun getStickersKeywords(code: String?): Single<BaseResponse<VKApiStickersKeywords>> {
fun getStickersSets(): Single<BaseResponse<Items<VKApiStickerSet.Product>>> {
return rest.request(
"execute",
form("code" to code),
base(VKApiStickersKeywords.serializer())
"store.getProducts",
form(
"extended" to 1,
"filters" to "active",
"type" to "stickers"
),
items(VKApiStickerSet.Product.serializer())
)
}

fun getStickersKeywords(): Single<BaseResponse<Dictionary<VKApiStickersKeywords>>> {
return rest.request(
"store.getStickersKeywords",
form(
"aliases" to 1,
"all_products" to 0,
"need_stickers" to 1
),
dictionary(VKApiStickersKeywords.serializer())
)
}
}
Loading

0 comments on commit c00579a

Please sign in to comment.