fix: better attempt to get anilist username

This commit is contained in:
rebelonion 2024-02-15 12:53:06 -06:00
parent a73c4cd678
commit fb99429dd7

View file

@ -188,10 +188,17 @@ object CommentsAPI {
@SuppressLint("GetInstance") @SuppressLint("GetInstance")
private fun generateUserId(): String? { 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 userIdEncryptKey = BuildConfig.USER_ID_ENCRYPT_KEY
val keySpec = SecretKeySpec(userIdEncryptKey.toByteArray(), KeyProperties.KEY_ALGORITHM_AES) 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) cipher.init(Cipher.ENCRYPT_MODE, keySpec)
val encrypted = cipher.doFinal(anilistId.toByteArray()) val encrypted = cipher.doFinal(anilistId.toByteArray())
return encrypted.joinToString("") { "%02x".format(it) } return encrypted.joinToString("") { "%02x".format(it) }
@ -290,7 +297,8 @@ data class ReturnedComment(
) )
object NumericBooleanSerializer : KSerializer<Boolean> { 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) { override fun serialize(encoder: Encoder, value: Boolean) {
encoder.encodeInt(if (value) 1 else 0) encoder.encodeInt(if (value) 1 else 0)