2
0
Эх сурвалжийг харах

Update readme, changelog, docs, tester

Signed-off-by: Hieuzest <[email protected]>
Hieuzest 5 жил өмнө
parent
commit
34452e4b48

+ 54 - 0
API-Tester/mirai-http-api.json

@@ -469,6 +469,60 @@
                 "headers": []
               }
             },
+            {
+              "entity": {
+                "type": "Request",
+                "method": {
+                  "requestBody": true,
+                  "link": "http://tools.ietf.org/html/rfc7231#section-4.3.3",
+                  "name": "POST"
+                },
+                "body": {
+                  "formBody": {
+                    "overrideContentType": true,
+                    "encoding": "multipart/form-data",
+                    "items": [
+                      {
+                        "enabled": true,
+                        "type": "Text",
+                        "name": "sessionKey",
+                        "value": "${session}"
+                      },
+                      {
+                        "enabled": true,
+                        "type": "Text",
+                        "name": "type",
+                        "value": "group"
+                      },
+                      {
+                        "enabled": true,
+                        "type": "File",
+                        "name": "voice"
+                      }
+                    ]
+                  },
+                  "bodyType": "Form",
+                  "textBody": ""
+                },
+                "uri": {
+                  "query": {
+                    "delimiter": "&",
+                    "items": []
+                  },
+                  "host": "${host}",
+                  "path": "/uploadVoice"
+                },
+                "id": "48754e04-64fa-488d-bba2-a09fe8c4c22c",
+                "name": "语音文件上传",
+                "headers": [
+                  {
+                    "enabled": true,
+                    "name": "Content-Type",
+                    "value": "multipart/form-data"
+                  }
+                ]
+              }
+            },
             {
               "entity": {
                 "type": "Request",

+ 14 - 0
CHANGELOG.md

@@ -1,5 +1,19 @@
 # 更新日志
 
+## \[1.7.5\] - 2020-08-20
+
+### 变更
+
+* 更新 `core` 依赖到 1.2.1
+
+### 新增
+
+* 支持 `Voice` 语音类型
+* `uploadVoice` 接口
+
+### 修复
+
+* `CacheQueue`
 
 ## \[1.7.4\] - 2020-07-31
 

+ 20 - 1
MessageType.md

@@ -126,7 +126,26 @@
 
 同 `Image`
 
-> 三个参数任选其一,出现多个参数时,按照imageId > url > file的优先级
+> 三个参数任选其一,出现多个参数时,按照imageId > url > path的优先级
+
+#### Voice
+
+```json5
+{
+    "type": "Voice",
+    "imageId": "23C477720A37FEB6A9EE4BCCF654014F.amr",
+    "url": "http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
+    "path": null
+}
+```
+
+| 名字    | 类型   | 说明                                                         |
+| ------- | ------ | ------------------------------------------------------------ |
+| voiceId | String | 语音的voiceId,不为空时将忽略url属性 |
+| url     | String | 语音的URL,发送时可作网络语音的链接;接收时为腾讯语音服务器的链接,可用于语音下载 |
+| path    | String | 语音的路径,发送本地语音,相对路径于`plugins/MiraiAPIHTTP/voices` |
+
+> 三个参数任选其一,出现多个参数时,按照voiceId > url > path的优先级
 
 #### Xml
 

+ 31 - 0
README.md

@@ -418,6 +418,37 @@ Content-Type:multipart/form-data
 
 
 
+### 语音文件上传
+
+```
+[POST] /uploadVoice
+```
+
+使用此方法上传语音文件至服务器并返回VoiceId
+
+#### 请求
+
+Content-Type:multipart/form-data
+
+| 名字         | 类型   | 可选  | 举例        | 说明                               |
+| ------------ | ------ | ----- | ----------- | ---------------------------------- |
+| sessionKey   | String | false | YourSession | 已经激活的Session                  |
+| type         | String | false | "group"     | 当前仅支持 "group"                   |
+| voice        | File   | false | -           | 语音文件                           |
+
+
+#### 响应: 语音的VoiceId
+
+```json5
+{
+    "imageId": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.amr",
+    "url": "xxxxxxxxxxxxxxxxxxxx",
+    "path": "xxxxxxxxxx"
+}
+```
+
+
+
 ### 撤回消息
 
 ```

+ 4 - 5
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/MessageDTO.kt

@@ -80,6 +80,7 @@ data class FlashImageDTO(
 @Serializable
 @SerialName("Voice")
 data class VoiceDTO(
+    val voiceId: String? = null,
     val url: String? = null,
     val path: String? = null
 ) : MessageDTO()
@@ -167,7 +168,7 @@ suspend fun Message.toDTO() = when (this) {
     is PlainText -> PlainDTO(content)
     is Image -> ImageDTO(imageId, queryUrl())
     is FlashImage -> FlashImageDTO(image.imageId, image.queryUrl())
-    is Voice -> VoiceDTO(url, fileName)
+    is Voice -> VoiceDTO(fileName, url)
     is ServiceMessage -> XmlDTO(content)
     is LightApp -> AppDTO(content)
     is QuoteReply -> QuoteDTO(source.id, source.fromId, source.targetId,
@@ -213,9 +214,8 @@ suspend fun MessageDTO.toMessage(contact: Contact) = when (this) {
     }?.flash()
     is VoiceDTO -> when {
         contact !is Group -> null
-        !url.isNullOrBlank() -> contact.uploadVoice(withContext(Dispatchers.IO) { URL(url).openStream() }).also {
-            println("${it.url} ${it.fileName} ${it.fileSize} ${it.md5}")
-        }
+        !voiceId.isNullOrBlank() -> Voice(voiceId, ByteArray(0), 0, "")
+        !url.isNullOrBlank() -> contact.uploadVoice(withContext(Dispatchers.IO) { URL(url).openStream() })
         !path.isNullOrBlank() -> with(HttpApiPluginBase.voice(path)) {
             if (exists()) {
                 contact.uploadVoice(this.inputStream())
@@ -233,4 +233,3 @@ suspend fun MessageDTO.toMessage(contact: Contact) = when (this) {
     is UnknownMessageDTO
     -> null
 }
-

+ 4 - 6
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/MessageRouteModule.kt

@@ -280,10 +280,9 @@ fun Application.messageModule() {
 
                 voice?.apply {
                     call.respondDTO(UploadVoiceRetDTO(
-                            url,
-                            fileName,
-                            fileSize,
-                            path
+                        fileName,
+                        url,
+                        path
                     ))
                 } ?: throw IllegalAccessException("语音上传错误")
 
@@ -338,9 +337,8 @@ private class UploadImageRetDTO(
 @Serializable
 @Suppress("unused")
 private class UploadVoiceRetDTO(
+    val voiceId: String,
     val url: String?,
-    val fileName: String,
-    val fileSize: Long,
     val path: String?
 ) : DTO