-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
264 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
app/release/* | ||
!app/release/.gitkeep | ||
|
||
app/sekret.properties | ||
|
||
*.iml | ||
.gradle | ||
/local.properties | ||
|
37 changes: 37 additions & 0 deletions
37
app/shared/src/commonMain/kotlin/dev/datlag/burningseries/module/NetworkModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,60 @@ | ||
package dev.datlag.burningseries.module | ||
|
||
import de.jensklingenberg.ktorfit.Ktorfit | ||
import de.jensklingenberg.ktorfit.ktorfitBuilder | ||
import dev.datlag.burningseries.common.launchIO | ||
import dev.datlag.burningseries.network.JsonBase | ||
import dev.datlag.burningseries.network.state.EpisodeStateMachine | ||
import dev.datlag.burningseries.network.state.HomeStateMachine | ||
import dev.datlag.burningseries.network.state.SearchStateMachine | ||
import io.ktor.client.* | ||
import io.realm.kotlin.mongodb.App | ||
import io.realm.kotlin.mongodb.Credentials | ||
import kotlinx.coroutines.DelicateCoroutinesApi | ||
import kotlinx.coroutines.GlobalScope | ||
import org.kodein.di.DI | ||
import org.kodein.di.bindSingleton | ||
import org.kodein.di.instance | ||
|
||
object NetworkModule { | ||
|
||
private const val TAG_KTORFIT_JSONBASE = "JsonBaseKtorfit" | ||
const val NAME = "NetworkModule" | ||
|
||
@OptIn(DelicateCoroutinesApi::class) | ||
val di = DI.Module(NAME) { | ||
import(DatabaseModule.di) | ||
|
||
bindSingleton { | ||
ktorfitBuilder { | ||
httpClient(instance<HttpClient>()) | ||
} | ||
} | ||
bindSingleton(TAG_KTORFIT_JSONBASE) { | ||
val builder = instance<Ktorfit.Builder>() | ||
builder.build { | ||
baseUrl("https://jsonbase.com/") | ||
} | ||
} | ||
bindSingleton { | ||
val jsonBaseKtor: Ktorfit = instance(TAG_KTORFIT_JSONBASE) | ||
jsonBaseKtor.create<JsonBase>() | ||
} | ||
bindSingleton { | ||
HomeStateMachine(instance()) | ||
} | ||
bindSingleton { | ||
SearchStateMachine(instance()) | ||
} | ||
bindSingleton { | ||
EpisodeStateMachine(instance()) | ||
} | ||
bindSingleton { | ||
App.create("").also { | ||
GlobalScope.launchIO { | ||
it.login(Credentials.anonymous()) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
model/src/commonMain/kotlin/dev/datlag/burningseries/model/algorithm/MD5.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package dev.datlag.burningseries.model.algorithm | ||
|
||
import kotlin.math.abs | ||
import kotlin.math.sin | ||
|
||
data object MD5 { | ||
|
||
private val INIT_A = 0x67452301 | ||
private val INIT_B = 0xEFCDAB89L.toInt() | ||
private val INIT_C = 0x98BADCFEL.toInt() | ||
private val INIT_D = 0x10325476 | ||
|
||
private val SHIFT_AMTS = intArrayOf( | ||
7, 12, 17, 22, | ||
5, 9, 14, 20, | ||
4, 11, 16, 23, | ||
6, 10, 15, 21 | ||
) | ||
|
||
private val TABLE_T = IntArray(64) { | ||
((1L shl 32) * abs(sin(it + 1.0))).toLong().toInt() | ||
} | ||
|
||
fun compute(message: ByteArray): ByteArray { | ||
val messageLenBytes = message.size | ||
val numBlocks = ((messageLenBytes + 8) ushr 6) + 1 | ||
val totalLen = numBlocks shl 6 | ||
val paddingBytes = ByteArray(totalLen - messageLenBytes) | ||
paddingBytes[0] = 0x80.toByte() | ||
var messageLenBits = (messageLenBytes shl 3).toLong() | ||
|
||
for (i in 0..7) { | ||
paddingBytes[paddingBytes.size - 8 + i] = messageLenBits.toByte() | ||
messageLenBits = messageLenBits ushr 8 | ||
} | ||
|
||
var a = INIT_A | ||
var b = INIT_B | ||
var c = INIT_C | ||
var d = INIT_D | ||
val buffer = IntArray(16) | ||
|
||
for (i in 0 until numBlocks) { | ||
var index = i shl 6 | ||
|
||
for (j in 0..63) { | ||
val temp = if (index < messageLenBytes) message[index] else | ||
paddingBytes[index - messageLenBytes] | ||
buffer[j ushr 2] = (temp.toInt() shl 24) or (buffer[j ushr 2] ushr 8) | ||
index++ | ||
} | ||
|
||
val originalA = a | ||
val originalB = b | ||
val originalC = c | ||
val originalD = d | ||
|
||
for (j in 0..63) { | ||
val div16 = j ushr 4 | ||
var f = 0 | ||
var bufferIndex = j | ||
when (div16) { | ||
0 -> { | ||
f = (b and c) or (b.inv() and d) | ||
} | ||
|
||
1 -> { | ||
f = (b and d) or (c and d.inv()) | ||
bufferIndex = (bufferIndex * 5 + 1) and 0x0F | ||
} | ||
|
||
2 -> { | ||
f = b xor c xor d; | ||
bufferIndex = (bufferIndex * 3 + 5) and 0x0F | ||
} | ||
|
||
3 -> { | ||
f = c xor (b or d.inv()); | ||
bufferIndex = (bufferIndex * 7) and 0x0F | ||
} | ||
} | ||
|
||
val temp = b + (a + f + buffer[bufferIndex] + TABLE_T[j]).rotateLeft(SHIFT_AMTS[(div16 shl 2) or (j and 3)]) | ||
a = d | ||
d = c | ||
c = b | ||
b = temp | ||
} | ||
|
||
a += originalA | ||
b += originalB | ||
c += originalC | ||
d += originalD | ||
} | ||
|
||
val md5 = ByteArray(16) | ||
var count = 0 | ||
|
||
for (i in 0..3) { | ||
var n = if (i == 0) a else (if (i == 1) b else (if (i == 2) c else d)) | ||
|
||
for (j in 0..3) { | ||
md5[count++] = n.toByte() | ||
n = n ushr 8 | ||
} | ||
} | ||
return md5 | ||
} | ||
|
||
@OptIn(ExperimentalStdlibApi::class) | ||
fun hexString(byteArray: ByteArray): String { | ||
return compute(byteArray).toHexString() | ||
} | ||
|
||
fun hexString(value: String): String { | ||
return hexString(value.encodeToByteArray()) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
model/src/commonMain/kotlin/dev/datlag/burningseries/model/state/EpisodeState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package dev.datlag.burningseries.model.state | ||
|
||
import dev.datlag.burningseries.model.Series | ||
|
||
sealed interface EpisodeState { | ||
data object Waiting : EpisodeState | ||
data class Loading(val episode: Series.Episode) : EpisodeState | ||
data class Success(val results: Collection<String>) : EpisodeState | ||
data class Error(val msg: String) : EpisodeState | ||
} | ||
|
||
sealed interface EpisodeAction { | ||
data class Load(val episode: Series.Episode) : EpisodeAction | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.