Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

加入文件操作 #294

Merged
merged 45 commits into from
Apr 2, 2021
Merged
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b302211
加入文件信息识别
Doctor-Yin Mar 26, 2021
56fa422
加入获取指定目录下文件/目录
Doctor-Yin Mar 27, 2021
0268aee
加入获取指定目录下文件/目录
Doctor-Yin Mar 27, 2021
be0682e
Merge remote-tracking branch 'origin/master'
Doctor-Yin Mar 27, 2021
f78e7be
加入获取指定文件信息
Doctor-Yin Mar 27, 2021
4fe3364
Recompile with mirai 2.5.1-dev-1
Doctor-Yin Mar 27, 2021
d677764
还原
Doctor-Yin Mar 27, 2021
4428689
修复
Doctor-Yin Mar 27, 2021
0d99156
整理
Doctor-Yin Mar 27, 2021
982ca47
整理
Doctor-Yin Mar 27, 2021
71044e7
整理
Doctor-Yin Mar 27, 2021
cdebfa2
修改path路径为groupFile...
Doctor-Yin Mar 27, 2021
252e06b
添加群文件名字修改
Doctor-Yin Mar 27, 2021
e87f0aa
添加群文件移动
Doctor-Yin Mar 27, 2021
ec2f1a5
添加群文件/目录删除
Doctor-Yin Mar 27, 2021
304cd62
Merge remote-tracking branch 'upstream/master'
Doctor-Yin Mar 27, 2021
3644373
处理合并
Doctor-Yin Mar 27, 2021
a71158f
添加群文件发送
Doctor-Yin Mar 27, 2021
ae90641
添加群文件发送
Doctor-Yin Mar 27, 2021
91d8ab7
写了转发文件的TODO
Doctor-Yin Mar 29, 2021
69a976f
Update mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/c…
Doctor-Yin Mar 29, 2021
9773915
Update mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/c…
Doctor-Yin Mar 29, 2021
e13e80d
Update mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/…
Doctor-Yin Mar 29, 2021
4b882e3
更新建议
Doctor-Yin Mar 29, 2021
700bd8b
更新建议
Doctor-Yin Mar 29, 2021
437ab40
更新建议
Doctor-Yin Mar 29, 2021
fe7056d
更新建议
Doctor-Yin Mar 29, 2021
50b5869
更新建议
Doctor-Yin Mar 29, 2021
d73ab7d
更新建议
Doctor-Yin Mar 29, 2021
bf99cfe
Merge remote-tracking branch 'upstream/master'
Doctor-Yin Mar 30, 2021
f71cdcc
更新建议
Doctor-Yin Mar 30, 2021
bd124f3
Update mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/…
Doctor-Yin Mar 30, 2021
2d90293
更新建议(core的锅)
Doctor-Yin Mar 30, 2021
c32e914
更新API
Doctor-Yin Mar 30, 2021
b70cfa4
添加移动目录时自动创建目录,更新API
Doctor-Yin Mar 30, 2021
a27953a
添加移动目录时自动创建目录,更新API
Doctor-Yin Mar 30, 2021
3a94ef2
Update docs/API.md
Doctor-Yin Mar 30, 2021
c62f516
更新建议
Doctor-Yin Mar 30, 2021
f708084
更新API
Doctor-Yin Mar 30, 2021
1dc3ed6
还原API文档
Doctor-Yin Apr 1, 2021
3dad79d
还原API文档
Doctor-Yin Apr 1, 2021
8bc8311
更新API文档
Doctor-Yin Apr 1, 2021
e1f5023
解决合并
Doctor-Yin Apr 2, 2021
6410f84
解决合并
Doctor-Yin Apr 2, 2021
19877f3
Update API.md
Karlatemp Apr 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ import net.mamoe.mirai.api.http.data.StateCode
import net.mamoe.mirai.api.http.data.common.DTO
import net.mamoe.mirai.api.http.data.common.VerifyDTO
import net.mamoe.mirai.api.http.generateSessionKey
import net.mamoe.mirai.message.data.FileMessage
import net.mamoe.mirai.message.data.OnlineMessageSource
import net.mamoe.mirai.message.data.*
import net.mamoe.mirai.utils.ExternalResource.Companion.sendTo
import kotlin.io.use

/**
* 群文件管理路由
Expand Down Expand Up @@ -96,30 +94,30 @@ fun Application.fileRouteModule() {
* 上传文件并且发送
*/

miraiMultiPart("uploadFileAndSend") { session, parts ->
miraiMultiPart("/uploadFileAndSend") { session, parts ->
val type = parts.value("type")
val target = parts.value("target").toLongOrNull() ?: error("target不能为空")
val path = parts.value("path")
var source: OnlineMessageSource.Outgoing
val file = parts.file("file") ?: error("file不能为空")
file.provider().use { inPutStream ->
val newFile = HttpApiPluginBase.saveFileAsync(
file.originalFileName ?: generateSessionKey(), inPutStream.readBytes()
)
when (type) {
"Group" -> session.bot.getGroupOrFail(target).let { group ->
group.filesRoot.resolve(path).let { remoteFile ->
if (!remoteFile.exists()) {
if (!remoteFile.mkdir())
call.respondStateCode(StateCode.PermissionDenied)
return@miraiMultiPart
} else source = newFile.await().sendTo(group, "/$path/${newFile.await().name}").source
}
var messageChain: MessageChain
val newFile = HttpApiPluginBase.saveFileAsync(
file.originalFileName ?: generateSessionKey(), file.provider().readBytes()
)
when (type) {
"Group" -> session.bot.getGroupOrFail(target).let { group ->
group.filesRoot.resolve(path).let { remoteFile ->
if (remoteFile.parent != null && !remoteFile.exists()) {
if (!remoteFile.mkdir())
call.respondStateCode(StateCode.PermissionDenied)
return@miraiMultiPart
} else messageChain =
newFile.await().sendTo(group, "/$path").source.originalMessage
}
else -> error("不支持类型 $type")
}
else -> error("不支持类型 $type")
}
call.respondDTO(UploadFileRetDTO(id = (source.originalMessage.last() as FileMessage).id))

call.respondDTO(UploadFileRetDTO(id = (messageChain[FileMessage.topmostKey] as FileMessage).id))
}

}
Expand Down