Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
4ba2b34a
Commit
4ba2b34a
authored
Feb 04, 2020
by
ryoii
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix StateCode serialization
parent
696889ba
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
18 deletions
+19
-18
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/VerifyDTO.kt
...src/main/kotlin/net/mamoe/mirai/api/http/dto/VerifyDTO.kt
+7
-9
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/AuthRouteModule.kt
.../kotlin/net/mamoe/mirai/api/http/route/AuthRouteModule.kt
+3
-3
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/BaseRoute.kt
...c/main/kotlin/net/mamoe/mirai/api/http/route/BaseRoute.kt
+7
-4
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/MessageRouteModule.kt
...tlin/net/mamoe/mirai/api/http/route/MessageRouteModule.kt
+2
-2
No files found.
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/VerifyDTO.kt
View file @
4ba2b34a
...
@@ -15,19 +15,17 @@ abstract class VerifyDTO : DTO {
...
@@ -15,19 +15,17 @@ abstract class VerifyDTO : DTO {
data class
BindDTO
(
override
val
sessionKey
:
String
,
val
qq
:
Long
)
:
VerifyDTO
()
data class
BindDTO
(
override
val
sessionKey
:
String
,
val
qq
:
Long
)
:
VerifyDTO
()
// 写成data class并继承DTO接口是为了返回时的形式统一
@Serializable
@Serializable
sealed
class
StateCodeDTO
(
val
code
:
Int
,
var
msg
:
String
)
:
DTO
{
open
class
StateCode
(
val
code
:
Int
,
var
msg
:
String
)
{
object
Success
:
StateCodeDTO
(
0
,
"success"
)
// 成功
object
Success
:
StateCode
(
0
,
"success"
)
// 成功
// object AUTH_WRONG : CodeDTO(1) // AuthKey错误, @see AuthResDTO
object
NoBot
:
StateCode
(
2
,
"指定Bot不存在"
)
object
NoBot
:
StateCodeDTO
(
2
,
"指定Bot不存在"
)
object
IllegalSession
:
StateCode
(
3
,
"Session失效或不存在"
)
object
IllegalSession
:
StateCodeDTO
(
3
,
"Session失效或不存在"
)
object
NotVerifySession
:
StateCode
(
4
,
"Session未认证"
)
object
NotVerifySession
:
StateCodeDTO
(
4
,
"Session未认证"
)
object
NoElement
:
StateCode
(
5
,
"指定对象不存在"
)
object
NoElement
:
StateCodeDTO
(
5
,
"指定对象不存在"
)
// KS bug: 主构造器中不能有非字段参数 https://github.com/Kotlin/kotlinx.serialization/issues/575
// KS bug: 主构造器中不能有非字段参数 https://github.com/Kotlin/kotlinx.serialization/issues/575
@Serializable
@Serializable
class
IllegalAccess
()
:
StateCode
DTO
(
400
,
""
)
{
// 非法访问
class
IllegalAccess
()
:
StateCode
(
400
,
""
)
{
// 非法访问
constructor
(
msg
:
String
)
:
this
()
{
constructor
(
msg
:
String
)
:
this
()
{
this
.
msg
=
msg
this
.
msg
=
msg
}
}
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/AuthRouteModule.kt
View file @
4ba2b34a
...
@@ -27,15 +27,15 @@ fun Application.authModule() {
...
@@ -27,15 +27,15 @@ fun Application.authModule() {
closeSession
(
it
.
sessionKey
)
closeSession
(
it
.
sessionKey
)
allSession
[
it
.
sessionKey
]
=
AuthedSession
(
bot
,
EmptyCoroutineContext
)
allSession
[
it
.
sessionKey
]
=
AuthedSession
(
bot
,
EmptyCoroutineContext
)
}
}
call
.
respond
DTO
(
StateCodeDTO
.
Success
)
call
.
respond
StateCode
(
StateCode
.
Success
)
}
catch
(
e
:
NoSuchElementException
)
{
}
catch
(
e
:
NoSuchElementException
)
{
call
.
respond
DTO
(
StateCodeDTO
.
NoBot
)
call
.
respond
StateCode
(
StateCode
.
NoBot
)
}
}
}
}
miraiVerify
<
BindDTO
>(
"/release"
)
{
miraiVerify
<
BindDTO
>(
"/release"
)
{
SessionManager
.
closeSession
(
it
.
sessionKey
)
SessionManager
.
closeSession
(
it
.
sessionKey
)
call
.
respond
DTO
(
StateCodeDTO
.
Success
)
call
.
respond
StateCode
(
StateCode
.
Success
)
}
}
}
}
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/BaseRoute.kt
View file @
4ba2b34a
...
@@ -105,19 +105,22 @@ internal inline fun Route.intercept(crossinline blk: suspend PipelineContext<Uni
...
@@ -105,19 +105,22 @@ internal inline fun Route.intercept(crossinline blk: suspend PipelineContext<Uni
try
{
try
{
blk
(
this
)
blk
(
this
)
}
catch
(
e
:
IllegalSessionException
)
{
}
catch
(
e
:
IllegalSessionException
)
{
call
.
respond
DTO
(
StateCodeDTO
.
IllegalSession
)
call
.
respond
StateCode
(
StateCode
.
IllegalSession
)
}
catch
(
e
:
NotVerifiedSessionException
)
{
}
catch
(
e
:
NotVerifiedSessionException
)
{
call
.
respond
DTO
(
StateCodeDTO
.
NotVerifySession
)
call
.
respond
StateCode
(
StateCode
.
NotVerifySession
)
}
catch
(
e
:
NoSuchElementException
)
{
}
catch
(
e
:
NoSuchElementException
)
{
call
.
respond
DTO
(
StateCodeDTO
.
NoElement
)
call
.
respond
StateCode
(
StateCode
.
NoElement
)
}
catch
(
e
:
IllegalAccessException
)
{
}
catch
(
e
:
IllegalAccessException
)
{
call
.
respond
DTO
(
StateCodeDTO
.
IllegalAccess
(
e
.
message
),
HttpStatusCode
.
BadRequest
)
call
.
respond
StateCode
(
StateCode
(
400
,
e
.
message
),
HttpStatusCode
.
BadRequest
)
}
}
}
}
/*
/*
extend function
extend function
*/
*/
internal
suspend
inline
fun
<
reified
T
:
StateCode
>
ApplicationCall
.
respondStateCode
(
code
:
T
,
status
:
HttpStatusCode
=
HttpStatusCode
.
OK
)
=
respondJson
(
code
.
toJson
(
StateCode
.
serializer
()),
status
)
internal
suspend
inline
fun
<
reified
T
:
DTO
>
ApplicationCall
.
respondDTO
(
dto
:
T
,
status
:
HttpStatusCode
=
HttpStatusCode
.
OK
)
internal
suspend
inline
fun
<
reified
T
:
DTO
>
ApplicationCall
.
respondDTO
(
dto
:
T
,
status
:
HttpStatusCode
=
HttpStatusCode
.
OK
)
=
respondJson
(
dto
.
toJson
(),
status
)
=
respondJson
(
dto
.
toJson
(),
status
)
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/MessageRouteModule.kt
View file @
4ba2b34a
...
@@ -18,12 +18,12 @@ fun Application.messageModule() {
...
@@ -18,12 +18,12 @@ fun Application.messageModule() {
miraiVerify
<
SendDTO
>(
"/sendFriendMessage"
)
{
miraiVerify
<
SendDTO
>(
"/sendFriendMessage"
)
{
it
.
session
.
bot
.
getFriend
(
it
.
target
).
sendMessage
(
it
.
messageChain
.
toMessageChain
())
it
.
session
.
bot
.
getFriend
(
it
.
target
).
sendMessage
(
it
.
messageChain
.
toMessageChain
())
call
.
respond
DTO
(
StateCodeDTO
.
Success
)
call
.
respond
StateCode
(
StateCode
.
Success
)
}
}
miraiVerify
<
SendDTO
>(
"/sendGroupMessage"
)
{
miraiVerify
<
SendDTO
>(
"/sendGroupMessage"
)
{
it
.
session
.
bot
.
getGroup
(
it
.
target
).
sendMessage
(
it
.
messageChain
.
toMessageChain
())
it
.
session
.
bot
.
getGroup
(
it
.
target
).
sendMessage
(
it
.
messageChain
.
toMessageChain
())
call
.
respond
DTO
(
StateCodeDTO
.
Success
)
call
.
respond
StateCode
(
StateCode
.
Success
)
}
}
miraiVerify
<
VerifyDTO
>(
"/event/message"
)
{
miraiVerify
<
VerifyDTO
>(
"/event/message"
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment