diff --git a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/DownloadFile.kt b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/DownloadFile.kt index 96b6902..32f30bd 100644 --- a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/DownloadFile.kt +++ b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/DownloadFile.kt @@ -49,7 +49,7 @@ internal object DownloadFile: IActionHandler() { headerMap[k] = v } } - return invoke(url, threadCnt, headerMap, echo) + return invoke(url, threadCnt, headerMap, name, echo) } else if (base64 != null) { return invoke(base64, name, echo) } else { @@ -88,6 +88,7 @@ internal object DownloadFile: IActionHandler() { url: String, threadCnt: Int, headers: Map, + name: String?, echo: JsonElement = EmptyJsonString ): String { return kotlin.runCatching { @@ -100,7 +101,13 @@ internal object DownloadFile: IActionHandler() { )) { return error("下载失败 (0x1)", echo) } - tmp = FileUtils.renameByMd5(tmp) + tmp = if (name == null) { + FileUtils.renameByMd5(tmp) + } else { + val newFile = tmp.parentFile!!.resolve(name) + tmp.renameTo(newFile) + newFile + } ok(data = DownloadResult( file = tmp.absolutePath, md5 = MD5.genFileMd5Hex(tmp.absolutePath) diff --git a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/UploadGroupFile.kt b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/UploadGroupFile.kt index b39042d..5ee6010 100644 --- a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/UploadGroupFile.kt +++ b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/UploadGroupFile.kt @@ -17,12 +17,12 @@ import kotlinx.coroutines.withTimeoutOrNull import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.json.JsonElement +import moe.fuqiuluo.qqinterface.servlet.transfile.RichMediaUploadHandler import moe.fuqiuluo.shamrock.helper.LogCenter import moe.fuqiuluo.shamrock.helper.MessageHelper import moe.fuqiuluo.shamrock.helper.TransfileHelper import moe.fuqiuluo.shamrock.remote.action.ActionSession import moe.fuqiuluo.shamrock.remote.action.IActionHandler -import moe.fuqiuluo.qqinterface.servlet.transfile.RichMediaUploadHandler import moe.fuqiuluo.shamrock.tools.EmptyJsonString import moe.fuqiuluo.shamrock.utils.FileUtils import moe.fuqiuluo.shamrock.utils.MD5 @@ -55,6 +55,20 @@ internal object UploadGroupFile : IActionHandler() { if (!srcFile.exists()) { srcFile = FileUtils.getFile(file) } + if (!srcFile.exists()) { + srcFile = file.let { + val md5 = it.replace( + regex = "[{}\\-]".toRegex(), + replacement = "" + ).split(".")[0].lowercase() + if (md5.length == 32) { + FileUtils.getFileByMd5(it) + } else { + FileUtils.parseAndSave(it) + } + } + } + if (!srcFile.exists()) { return badParam("文件不存在", echo) } @@ -64,6 +78,7 @@ internal object UploadGroupFile : IActionHandler() { fileElement.fileName = name fileElement.filePath = srcFile.absolutePath fileElement.fileSize = srcFile.length() + fileElement.folderId = srcFile.parent ?: "" fileElement.picWidth = 0 fileElement.picHeight = 0 fileElement.videoDuration = 0 diff --git a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/UploadPrivateFile.kt b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/UploadPrivateFile.kt index 99c6d3b..ffe5b84 100644 --- a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/UploadPrivateFile.kt +++ b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/UploadPrivateFile.kt @@ -53,6 +53,21 @@ internal object UploadPrivateFile : IActionHandler() { if (!srcFile.exists()) { srcFile = FileUtils.getFile(file) } + + if (!srcFile.exists()) { + srcFile = file.let { + val md5 = it.replace( + regex = "[{}\\-]".toRegex(), + replacement = "" + ).split(".")[0].lowercase() + if (md5.length == 32) { + FileUtils.getFileByMd5(it) + } else { + FileUtils.parseAndSave(it) + } + } + } + if (!srcFile.exists()) { return badParam("文件不存在", echo) } @@ -62,6 +77,7 @@ internal object UploadPrivateFile : IActionHandler() { fileElement.fileName = name fileElement.filePath = srcFile.absolutePath fileElement.fileSize = srcFile.length() + fileElement.folderId = srcFile.parent ?: "" fileElement.picWidth = 0 fileElement.picHeight = 0 fileElement.videoDuration = 0 @@ -108,8 +124,10 @@ internal object UploadPrivateFile : IActionHandler() { msgService.sendMsgWithMsgId( contact, msgIdPair.qqMsgId, arrayListOf(msgElement) ) { code, reason -> - LogCenter.log("私聊文件消息发送异常(code = $code, reason = $reason)") - it.resume(null) + if (code != 0) { + LogCenter.log("私聊文件消息发送异常(code = $code, reason = $reason)") + it.resume(null) + } } RichMediaUploadHandler.registerListener(msgIdPair.qqMsgId) { it.resume(this)