fix: better attempt to get anilist username
This commit is contained in:
parent
a73c4cd678
commit
fb99429dd7
1 changed files with 25 additions and 17 deletions
|
@ -188,10 +188,17 @@ object CommentsAPI {
|
|||
|
||||
@SuppressLint("GetInstance")
|
||||
private fun generateUserId(): String? {
|
||||
val anilistId = PrefManager.getVal(PrefName.AnilistUserId, null as String?) ?: return null
|
||||
val anilistId = PrefManager.getVal(PrefName.AnilistUserId, null as String?)
|
||||
?: if (Anilist.userid != null) {
|
||||
PrefManager.setVal(PrefName.AnilistUserId, Anilist.userid.toString())
|
||||
Anilist.userid.toString()
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
val userIdEncryptKey = BuildConfig.USER_ID_ENCRYPT_KEY
|
||||
val keySpec = SecretKeySpec(userIdEncryptKey.toByteArray(), KeyProperties.KEY_ALGORITHM_AES)
|
||||
val cipher = Cipher.getInstance("${KeyProperties.KEY_ALGORITHM_AES}/ECB/${KeyProperties.ENCRYPTION_PADDING_PKCS7}")
|
||||
val cipher =
|
||||
Cipher.getInstance("${KeyProperties.KEY_ALGORITHM_AES}/ECB/${KeyProperties.ENCRYPTION_PADDING_PKCS7}")
|
||||
cipher.init(Cipher.ENCRYPT_MODE, keySpec)
|
||||
val encrypted = cipher.doFinal(anilistId.toByteArray())
|
||||
return encrypted.joinToString("") { "%02x".format(it) }
|
||||
|
@ -290,7 +297,8 @@ data class ReturnedComment(
|
|||
)
|
||||
|
||||
object NumericBooleanSerializer : KSerializer<Boolean> {
|
||||
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("NumericBoolean", PrimitiveKind.INT)
|
||||
override val descriptor: SerialDescriptor =
|
||||
PrimitiveSerialDescriptor("NumericBoolean", PrimitiveKind.INT)
|
||||
|
||||
override fun serialize(encoder: Encoder, value: Boolean) {
|
||||
encoder.encodeInt(if (value) 1 else 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue