mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
commit
abbac6315c
@ -1,6 +1,6 @@
|
|||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
plugins {
|
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("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
|
||||||
}
|
}
|
||||||
|
@ -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")
|
||||||
|
}
|
@ -9,8 +9,7 @@ import moe.fuqiuluo.shamrock.tools.EmptyJsonString
|
|||||||
import moe.fuqiuluo.shamrock.utils.AudioUtils
|
import moe.fuqiuluo.shamrock.utils.AudioUtils
|
||||||
import moe.fuqiuluo.symbols.OneBotHandler
|
import moe.fuqiuluo.symbols.OneBotHandler
|
||||||
|
|
||||||
@OneBotHandler("get_record")
|
@OneBotHandler("get_record") internal object GetRecord : IActionHandler() {
|
||||||
internal object GetRecord: IActionHandler() {
|
|
||||||
override suspend fun internalHandle(session: ActionSession): String {
|
override suspend fun internalHandle(session: ActionSession): String {
|
||||||
val file = session.getString("file")
|
val file = session.getString("file")
|
||||||
.replace(regex = "[{}\\-]".toRegex(), replacement = "")
|
.replace(regex = "[{}\\-]".toRegex(), replacement = "")
|
||||||
@ -30,9 +29,9 @@ internal object GetRecord: IActionHandler() {
|
|||||||
}
|
}
|
||||||
ok(
|
ok(
|
||||||
OutResource(
|
OutResource(
|
||||||
audioFile.toString(),
|
audioFile.toString(), url = "/res/${audioFile.nameWithoutExtension}", md5 = audioFile.nameWithoutExtension
|
||||||
url = "/res/${audioFile.nameWithoutExtension}"
|
), echo
|
||||||
), echo)
|
)
|
||||||
} else {
|
} else {
|
||||||
error("not found record file from cache", echo)
|
error("not found record file from cache", echo)
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,12 @@ fun Routing.fetchRes() {
|
|||||||
call.respondText(GetRecord(file, format), ContentType.Application.Json)
|
call.respondText(GetRecord(file, format), ContentType.Application.Json)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getOrPost("/get_file") {
|
||||||
|
val file = formatFileName( fetchGetOrThrow("file") )
|
||||||
|
val fileType = fetchOrThrow("file_type")
|
||||||
|
call.respondText(GetFile(file, fileType), ContentType.Application.Json)
|
||||||
|
}
|
||||||
|
|
||||||
getOrPost("/get_image") {
|
getOrPost("/get_image") {
|
||||||
val file = formatFileName( fetchGetOrThrow("file") )
|
val file = formatFileName( fetchGetOrThrow("file") )
|
||||||
call.respondText(GetImage(file), ContentType.Application.Json)
|
call.respondText(GetImage(file), ContentType.Application.Json)
|
||||||
|
@ -1,9 +1,16 @@
|
|||||||
package moe.fuqiuluo.shamrock.remote.service.data
|
package moe.fuqiuluo.shamrock.remote.service.data
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
import java.util.Base64
|
||||||
|
|
||||||
@Serializable
|
@Serializable internal data class OutResource(
|
||||||
internal data class OutResource(
|
|
||||||
val file: String,
|
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,
|
||||||
)
|
)
|
Loading…
x
Reference in New Issue
Block a user