mirror of
https://github.com/InvertGeek/MixFile.git
synced 2026-06-01 17:10:49 +08:00
移除缓存
This commit is contained in:
@@ -6,15 +6,6 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Looper
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import coil.ImageLoader
|
||||
import coil.ImageLoaderFactory
|
||||
import coil.decode.GifDecoder
|
||||
@@ -22,15 +13,11 @@ import coil.decode.ImageDecoderDecoder
|
||||
import coil.decode.SvgDecoder
|
||||
import coil.decode.VideoFrameDecoder
|
||||
import com.donut.mixfile.server.FileService
|
||||
import com.donut.mixfile.ui.component.common.MixDialogBuilder
|
||||
import com.donut.mixfile.util.copyToClipboard
|
||||
import com.donut.mixfile.util.objects.MixActivity
|
||||
import com.donut.mixfile.util.showError
|
||||
import com.donut.mixfile.util.showErrorDialog
|
||||
import com.tencent.mmkv.MMKV
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import okhttp3.OkHttpClient
|
||||
|
||||
|
||||
@@ -38,8 +25,6 @@ val appScope by lazy { MainScope() }
|
||||
|
||||
lateinit var kv: MMKV
|
||||
|
||||
lateinit var cacheKv: MMKV
|
||||
|
||||
private lateinit var innerApp: Application
|
||||
|
||||
|
||||
@@ -60,19 +45,11 @@ class App : Application(), ImageLoaderFactory {
|
||||
if (Looper.myLooper() == null) {
|
||||
return@setDefaultUncaughtExceptionHandler
|
||||
}
|
||||
showErrorDialog(e)
|
||||
showErrorDialog(e)
|
||||
}
|
||||
innerApp = this
|
||||
MMKV.initialize(this)
|
||||
kv = MMKV.defaultMMKV()
|
||||
cacheKv = MMKV.mmkvWithID("cache", app.cacheDir.absolutePath)
|
||||
cacheKv.enableAutoKeyExpire(MMKV.ExpireInMinute)
|
||||
appScope.launch {
|
||||
while (true) {
|
||||
cacheKv.allNonExpireKeys()
|
||||
delay(1000 * 60)
|
||||
}
|
||||
}
|
||||
startService(Intent(this, FileService::class.java))
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.donut.mixfile.server.Uploader
|
||||
import com.donut.mixfile.server.uploadClient
|
||||
import com.donut.mixfile.ui.routes.getLocalServerAddress
|
||||
import com.donut.mixfile.ui.routes.serverAddress
|
||||
import com.donut.mixfile.util.CacheUtil
|
||||
import com.donut.mixfile.util.basen.BigIntBaseN
|
||||
import com.donut.mixfile.util.compressGzip
|
||||
import com.donut.mixfile.util.decompressGzip
|
||||
@@ -90,10 +89,6 @@ data class MixShareInfo(
|
||||
|
||||
suspend fun fetchFile(url: String): ByteArray? {
|
||||
val transformedUrl = Uploader.transformUrl(url)
|
||||
val cachedFileData = CacheUtil.get(transformedUrl)
|
||||
if (cachedFileData != null) {
|
||||
return cachedFileData
|
||||
}
|
||||
val transformedReferer = Uploader.transformReferer(referer)
|
||||
val result: ByteArray? = uploadClient.prepareGet(transformedUrl) {
|
||||
if (transformedReferer.trim().isNotEmpty()) {
|
||||
@@ -104,9 +99,6 @@ data class MixShareInfo(
|
||||
channel.discard(headSize.toLong())
|
||||
decryptAES(channel, ENCODER.decode(key))
|
||||
}
|
||||
if (result != null) {
|
||||
CacheUtil.put(transformedUrl, result)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.donut.mixfile.util
|
||||
|
||||
import com.donut.mixfile.cacheKv
|
||||
import com.tencent.mmkv.MMKV
|
||||
|
||||
object CacheUtil {
|
||||
|
||||
fun get(key: String): ByteArray? {
|
||||
return cacheKv.getBytes(key, null)
|
||||
}
|
||||
|
||||
fun put(key: String, value: ByteArray, duration: Int = MMKV.ExpireInMinute) {
|
||||
cacheKv.putBytes(key, value, duration)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user