This repository has been archived by the owner on Aug 12, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #301 from tobycroft/master
新增get_file方法(算是补全下功能)
- Loading branch information
Showing
5 changed files
with
69 additions
and
12 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,6 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
plugins { | ||
id("com.android.application") version "8.2.0" apply false | ||
id("com.android.application") version "8.2.1" apply false | ||
id("org.jetbrains.kotlin.android") version "1.9.22" apply false | ||
id("com.android.library") version "8.2.0" apply false | ||
id("com.android.library") version "8.2.1" apply false | ||
} |
45 changes: 45 additions & 0 deletions
45
xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/GetFile.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,45 @@ | ||
package moe.fuqiuluo.shamrock.remote.action.handlers | ||
|
||
import kotlinx.serialization.json.JsonElement | ||
import moe.fuqiuluo.shamrock.remote.action.ActionSession | ||
import moe.fuqiuluo.shamrock.remote.action.IActionHandler | ||
import moe.fuqiuluo.shamrock.remote.service.data.OutResourceByBase64 | ||
import moe.fuqiuluo.shamrock.tools.EmptyJsonString | ||
import moe.fuqiuluo.shamrock.utils.FileUtils | ||
import moe.fuqiuluo.symbols.OneBotHandler | ||
import java.util.Base64 | ||
|
||
@OneBotHandler("get_file") | ||
internal object GetFile : IActionHandler() { | ||
override suspend fun internalHandle(session: ActionSession): String { | ||
val file = session.getString("file") | ||
.replace(regex = "[{}\\-]".toRegex(), replacement = "") | ||
.replace(" ", "") | ||
.split(".")[0].lowercase() | ||
val fileType = session.getStringOrNull("file_type") ?: "base64" | ||
return invoke(file, fileType, session.echo) | ||
} | ||
|
||
operator fun invoke(file: String, fileType: String = "base64", echo: JsonElement = EmptyJsonString): String { | ||
val targetFile = FileUtils.getFileByMd5(file) | ||
return if (targetFile.exists()) { | ||
when (fileType) { | ||
"base64", "" -> ok( | ||
OutResourceByBase64( | ||
"/res/${targetFile.nameWithoutExtension}", | ||
Base64.getEncoder() | ||
.encodeToString(targetFile.readBytes()), | ||
targetFile.nameWithoutExtension, | ||
), echo | ||
) | ||
|
||
else -> error("only support base64", echo) | ||
} | ||
|
||
} else { | ||
error("not found record file from md5", echo) | ||
} | ||
} | ||
|
||
override val requiredParams: Array<String> = arrayOf("file") | ||
} |
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
13 changes: 10 additions & 3 deletions
13
xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/data/ResourceData.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,9 +1,16 @@ | ||
package moe.fuqiuluo.shamrock.remote.service.data | ||
|
||
import kotlinx.serialization.Serializable | ||
import java.util.Base64 | ||
|
||
@Serializable | ||
internal data class OutResource( | ||
@Serializable internal data class OutResource( | ||
val file: String, | ||
val url: String | ||
val url: String, | ||
val md5: String, | ||
) | ||
|
||
@Serializable internal data class OutResourceByBase64( | ||
val file: String, | ||
val base64String: String, | ||
val md5: String, | ||
) |