fix file preview

This commit is contained in:
Evan You
2025-03-29 13:23:21 +08:00
parent 41a8535056
commit 197f08bebb
5 changed files with 21 additions and 17 deletions

View File

@@ -15,8 +15,8 @@ android {
applicationId = "com.donut.mixfile"
minSdk = 26
targetSdk = 35
versionCode = 91
versionName = "1.12.8"
versionCode = 92
versionName = "1.12.9"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {

View File

@@ -37,13 +37,11 @@ import java.io.InputStream
var DOWNLOAD_TASK_COUNT by cachedMutableOf(5, "download_task_count")
var UPLOAD_TASK_COUNT by cachedMutableOf(10, "upload_task_count")
var enableAccessKey by cachedMutableOf(false, "enable_mix_file_access_key")
var enableServerAccessKey by cachedMutableOf(false, "enable_mix_file_access_key")
var UPLOAD_RETRY_TIMES by cachedMutableOf(10, "UPLOAD_RETRY_TIMES")
val mixFileServer = object : MixFileServer(
accessKeyTip = "网页端已被禁止访问,请到APP设置中开启",
enableAccessKey = enableAccessKey,
) {
override fun onDownloadData(data: ByteArray) {
@@ -54,14 +52,22 @@ val mixFileServer = object : MixFileServer(
increaseUploadData(data.size.toLong())
}
override val accessKeyTip: String
get() = "网页端已被禁止访问,请到APP设置中开启"
override val downloadTaskCount: Int
get() = DOWNLOAD_TASK_COUNT.toInt()
override val uploadTaskCount: Int
get() = UPLOAD_TASK_COUNT.toInt()
override val requestRetryCount: Int
get() = UPLOAD_RETRY_TIMES.toInt()
override val enableAccessKey: Boolean
get() = enableServerAccessKey
override fun onError(error: Throwable) {
showError(error)
@@ -116,7 +122,7 @@ class FileService : Service() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
appScope.launch(Dispatchers.IO) {
mixFileServer.start()
mixFileServer.start(false)
delay(1000)
serverStarted = true
}

View File

@@ -27,9 +27,6 @@ import java.net.ServerSocket
abstract class MixFileServer(
var serverPort: Int = 4719,
var accessKey: String = genRandomString(32),
var enableAccessKey: Boolean = false,
var accessKeyTip: String = "Require Access Key",
) {
init {
@@ -39,6 +36,9 @@ abstract class MixFileServer(
abstract val downloadTaskCount: Int
abstract val uploadTaskCount: Int
abstract val requestRetryCount: Int
open val enableAccessKey: Boolean = false
open val accessKey: String = genRandomString(32)
open val accessKeyTip: String = "Require Access Key"
abstract fun onError(error: Throwable)
@@ -78,7 +78,7 @@ abstract class MixFileServer(
}
fun start() {
fun start(wait: Boolean) {
serverPort = findAvailablePort(serverPort) ?: serverPort
embeddedServer(Netty, port = serverPort, watchPaths = emptyList()) {
intercept(ApplicationCallPipeline.Call) {
@@ -112,7 +112,7 @@ abstract class MixFileServer(
}
}
routing(getRoutes())
}.start(wait = true)
}.start(wait = wait)
}
}

View File

@@ -38,9 +38,8 @@ import com.donut.mixfile.server.UPLOAD_RETRY_TIMES
import com.donut.mixfile.server.UPLOAD_TASK_COUNT
import com.donut.mixfile.server.core.uploaders.hidden.A1Uploader
import com.donut.mixfile.server.currentUploader
import com.donut.mixfile.server.enableAccessKey
import com.donut.mixfile.server.enableServerAccessKey
import com.donut.mixfile.server.getCurrentUploader
import com.donut.mixfile.server.mixFileServer
import com.donut.mixfile.ui.component.common.CommonSwitch
import com.donut.mixfile.ui.component.common.MixDialogBuilder
import com.donut.mixfile.ui.component.common.SingleSelectItemList
@@ -179,12 +178,11 @@ val MixSettings = MixNavPage(
autoAddFavorite = it
}
CommonSwitch(
checked = enableAccessKey,
checked = enableServerAccessKey,
text = "禁止网页端访问:",
description = "开启后网页端将禁止访问"
) {
enableAccessKey = it
mixFileServer.enableAccessKey = it
enableServerAccessKey = it
}
CommonSwitch(
checked = useSystemPlayer,

View File

@@ -147,7 +147,7 @@ fun FileCardList(
) {
items(cardList.size) { index ->
PreviewCard(cardList[index]) {
deleteFavoriteLog(cardList[index])
longClick(cardList[index])
}
}
}