Merge branch 'feature/shikimori' of github.com:SkyfaceD/Kotatsu into feature/shikimori

This commit is contained in:
Koitharu
2022-06-22 13:39:09 +03:00
3 changed files with 17 additions and 5 deletions

View File

@@ -24,6 +24,10 @@ android {
arg 'room.schemaLocation', "$projectDir/schemas".toString()
}
}
// define this values in your local.properties file
buildConfigField 'String', 'SHIKIMORI_CLIENT_ID', "\"${localProperty('shikimori.clientId')}\""
buildConfigField 'String', 'SHIKIMORI_CLIENT_SECRET', "\"${localProperty('shikimori.clientSecret')}\""
}
buildTypes {
debug {

View File

@@ -5,6 +5,7 @@ import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request
import org.json.JSONObject
import org.koitharu.kotatsu.BuildConfig
import org.koitharu.kotatsu.core.db.MangaDatabase
import org.koitharu.kotatsu.parsers.model.MangaChapter
import org.koitharu.kotatsu.parsers.util.await
@@ -20,8 +21,6 @@ import org.koitharu.kotatsu.scrobbling.domain.model.ScrobblerService
import org.koitharu.kotatsu.scrobbling.shikimori.data.model.ShikimoriUser
import org.koitharu.kotatsu.utils.ext.toRequestBody
private const val CLIENT_ID = "Mw6F0tPEOgyV7F9U9Twg50Q8SndMY7hzIOfXg0AX_XU"
private const val CLIENT_SECRET = "euBMt1GGRSDpVIFQVPxZrO7Kh6X4gWyv0dABuj4B-M8"
private const val REDIRECT_URI = "kotatsu://shikimori-auth"
private const val BASE_URL = "https://shikimori.one/"
private const val MANGA_PAGE_SIZE = 10
@@ -33,7 +32,7 @@ class ShikimoriRepository(
) {
val oauthUrl: String
get() = "${BASE_URL}oauth/authorize?client_id=$CLIENT_ID&" +
get() = "${BASE_URL}oauth/authorize?client_id=${BuildConfig.SHIKIMORI_CLIENT_ID}&" +
"redirect_uri=$REDIRECT_URI&response_type=code&scope="
val isAuthorized: Boolean
@@ -42,8 +41,8 @@ class ShikimoriRepository(
suspend fun authorize(code: String?) {
val body = FormBody.Builder()
body.add("grant_type", "authorization_code")
body.add("client_id", CLIENT_ID)
body.add("client_secret", CLIENT_SECRET)
body.add("client_id", BuildConfig.SHIKIMORI_CLIENT_ID)
body.add("client_secret", BuildConfig.SHIKIMORI_CLIENT_SECRET)
if (code != null) {
body.add("redirect_uri", REDIRECT_URI)
body.add("code", code)

View File

@@ -23,6 +23,15 @@ allprojects {
}
}
Object localProperty(String name, Object defaultValue = 'null') {
Properties localProperties = new Properties()
project.rootProject.file('local.properties').withInputStream { localProperties.load(it) }
def value = localProperties[name]
return value != null ? value : defaultValue
}
task clean(type: Delete) {
delete rootProject.buildDir
}