99
1010package net.mamoe.mirai.api.http.adapter.http.router
1111
12- import io.ktor.server.application.*
1312import io.ktor.http.content.*
13+ import io.ktor.server.application.*
1414import io.ktor.server.routing.*
1515import net.mamoe.mirai.api.http.adapter.common.IllegalParamException
1616import net.mamoe.mirai.api.http.adapter.http.dto.CountDTO
1717import net.mamoe.mirai.api.http.adapter.internal.action.*
1818import net.mamoe.mirai.api.http.adapter.internal.consts.Paths
1919import net.mamoe.mirai.api.http.adapter.internal.dto.EventListRestfulResult
2020import net.mamoe.mirai.api.http.adapter.internal.dto.IntRestfulResult
21+ import java.net.URL
2122
2223/* *
2324 * 消息路由
@@ -104,8 +105,15 @@ internal fun Application.messageRouter() = routing {
104105 */
105106 httpAuthedMultiPart(Paths .uploadImage) { session, parts ->
106107 val type = parts.value(" type" )
107- val ret = parts.file(" img" )?.run { onUploadImage(session, streamProvider(), type) }
108- ? : throw IllegalParamException (" 缺少参数 img" )
108+ val url = parts.valueOrNull(" url" )
109+ val stream = if (url != null ) {
110+ URL (url).openStream()
111+ } else {
112+ val f = parts.file(" img" ) ? : throw IllegalParamException (" 缺少参数 img" )
113+ f.streamProvider()
114+ }
115+
116+ val ret = onUploadImage(session, stream, type)
109117 call.respondDTO(ret)
110118 }
111119
@@ -114,8 +122,14 @@ internal fun Application.messageRouter() = routing {
114122 */
115123 httpAuthedMultiPart(Paths .uploadVoice) { session, parts ->
116124 val type = parts.value(" type" )
117- val ret = parts.file(" voice" )?.run { onUploadVoice(session, streamProvider(), type) }
118- ? : throw IllegalParamException (" 缺少参数 voice" )
125+ val url = parts.valueOrNull(" url" )
126+ val stream = if (url != null ) {
127+ URL (url).openStream()
128+ } else {
129+ val f = parts.file(" voice" ) ? : throw IllegalParamException (" 缺少参数 voice" )
130+ f.streamProvider()
131+ }
132+ val ret = onUploadVoice(session, stream, type)
119133 call.respondDTO(ret)
120134 }
121135
0 commit comments