mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
get_record的ws加入单独的md5字段,方便后续get_file拿文件
This commit is contained in:
parent
5adfc544a2
commit
ea206faf4f
@ -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 = "")
|
||||||
@ -22,17 +21,17 @@ internal object GetRecord: IActionHandler() {
|
|||||||
|
|
||||||
operator fun invoke(file: String, format: String, echo: JsonElement = EmptyJsonString): String {
|
operator fun invoke(file: String, format: String, echo: JsonElement = EmptyJsonString): String {
|
||||||
val pttFile = LocalCacheHelper.getCachePttFile(file)
|
val pttFile = LocalCacheHelper.getCachePttFile(file)
|
||||||
return if(pttFile.exists()) {
|
return if (pttFile.exists()) {
|
||||||
val isSilk = AudioUtils.isSilk(pttFile)
|
val isSilk = AudioUtils.isSilk(pttFile)
|
||||||
val audioFile = when(format) {
|
val audioFile = when (format) {
|
||||||
"amr" -> AudioUtils.audioToAmr(pttFile, isSilk)
|
"amr" -> AudioUtils.audioToAmr(pttFile, isSilk)
|
||||||
else -> AudioUtils.audioToFormat(pttFile, isSilk, format)
|
else -> AudioUtils.audioToFormat(pttFile, isSilk, format)
|
||||||
}
|
}
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,13 @@ import kotlinx.serialization.Serializable
|
|||||||
import java.util.Base64
|
import java.util.Base64
|
||||||
|
|
||||||
@Serializable internal data class OutResource(
|
@Serializable internal data class OutResource(
|
||||||
val file: String, val url: String
|
val file: String,
|
||||||
|
val url: String,
|
||||||
|
val md5: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable internal data class OutResourceByBase64(
|
@Serializable internal data class OutResourceByBase64(
|
||||||
val file: String,
|
val file: String,
|
||||||
val base64String: String,
|
val base64String: String,
|
||||||
|
val md5: String,
|
||||||
)
|
)
|
Loading…
x
Reference in New Issue
Block a user