mirror of
https://github.com/InvertGeek/MixFile.git
synced 2026-05-31 16:40:45 +08:00
1.16.10
This commit is contained in:
@@ -16,8 +16,8 @@ android {
|
||||
applicationId = "com.donut.mixfile"
|
||||
minSdk = 26
|
||||
targetSdk = 35
|
||||
versionCode = 127
|
||||
versionName = "1.16.9"
|
||||
versionCode = 128
|
||||
versionName = "1.16.10"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
|
||||
@@ -56,7 +56,8 @@ suspend fun decryptAES(
|
||||
var size = 0
|
||||
withContext(Dispatchers.IO) {
|
||||
while (!data.isClosedForRead) {
|
||||
if (size >= limit) {
|
||||
// +12字节ghash 大小,iv已读取
|
||||
if (size >= limit + 12) {
|
||||
throw Exception("分片文件过大")
|
||||
}
|
||||
val buffer = data.readRemaining(1024 * 64).readByteArray()
|
||||
|
||||
@@ -106,12 +106,13 @@ data class MixShareInfo(
|
||||
}
|
||||
}.execute {
|
||||
val contentLength = it.contentLength() ?: 0
|
||||
if (contentLength > (limit + headSize + 192)) {
|
||||
// iv + ghash 各96位,12字节,共24字节
|
||||
if (contentLength > (limit + headSize + 24)) {
|
||||
throw Exception("分片文件过大")
|
||||
}
|
||||
val channel = it.bodyAsChannel()
|
||||
channel.discard(headSize.toLong())
|
||||
decryptAES(channel, ENCODER.decode(key), limit + 96)
|
||||
decryptAES(channel, ENCODER.decode(key), limit)
|
||||
}
|
||||
val hash = Url(url).fragment.trim()
|
||||
if (hash.isNotEmpty()) {
|
||||
@@ -136,8 +137,8 @@ data class MixShareInfo(
|
||||
|
||||
fun contentType() = fileName.parseFileMimeType()
|
||||
|
||||
suspend fun fetchMixFile(client: HttpClient): MixFile {
|
||||
val decryptedBytes = fetchFile(url, client = client)
|
||||
suspend fun fetchMixFile(client: HttpClient, referer: String = this.referer): MixFile {
|
||||
val decryptedBytes = fetchFile(url, client = client, referer = referer)
|
||||
return MixFile.fromBytes(decryptedBytes)
|
||||
}
|
||||
|
||||
|
||||
@@ -47,8 +47,13 @@ fun MixFileServer.getDownloadRoute(): RoutingHandler {
|
||||
|
||||
suspend fun MixFileServer.respondMixFile(call: ApplicationCall, shareInfo: MixShareInfo) {
|
||||
val param = call.parameters
|
||||
|
||||
val referer = param["referer"].ifNullOrBlank { shareInfo.referer }
|
||||
|
||||
val name = param["name"].ifNullOrBlank { shareInfo.fileName }
|
||||
|
||||
val mixFile = try {
|
||||
shareInfo.fetchMixFile(httpClient)
|
||||
shareInfo.fetchMixFile(httpClient, referer)
|
||||
} catch (e: Exception) {
|
||||
call.respondText(
|
||||
"解析文件索引失败: ${e.stackTraceToString()}",
|
||||
@@ -57,10 +62,6 @@ suspend fun MixFileServer.respondMixFile(call: ApplicationCall, shareInfo: MixSh
|
||||
return
|
||||
}
|
||||
|
||||
val referer = param["referer"].ifNullOrBlank { shareInfo.referer }
|
||||
|
||||
val name = param["name"].ifNullOrBlank { shareInfo.fileName }
|
||||
|
||||
var contentLength = shareInfo.fileSize
|
||||
val range: LongRange? = call.request.ranges()?.mergeToSingle(contentLength)
|
||||
call.response.apply {
|
||||
|
||||
Reference in New Issue
Block a user