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
2bf0a963
Commit
2bf0a963
authored
Nov 28, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update libraries and reduce redundant code
parent
d5e6c2f8
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
24 additions
and
70 deletions
+24
-70
gradle.properties
gradle.properties
+4
-4
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsAndroid.kt
...Main/kotlin/net/mamoe/mirai/utils/PlatformUtilsAndroid.kt
+0
-23
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/Subscribers.kt
...rc/commonMain/kotlin/net.mamoe.mirai/event/Subscribers.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotSession.kt
...c/commonMain/kotlin/net.mamoe.mirai/network/BotSession.kt
+1
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/action/GroupImage.kt
...oe.mirai/network/protocol/tim/packet/action/GroupImage.kt
+2
-2
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/action/HttpAPIAccessor.kt
...rai/network/protocol/tim/packet/action/HttpAPIAccessor.kt
+15
-2
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/PlatformUtils.kt
.../commonMain/kotlin/net.mamoe.mirai/utils/PlatformUtils.kt
+0
-6
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
.../jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
+1
-32
No files found.
gradle.properties
View file @
2bf0a963
...
@@ -9,11 +9,11 @@ kotlinVersion=1.3.61
...
@@ -9,11 +9,11 @@ kotlinVersion=1.3.61
# kotlin libraries
# kotlin libraries
serializationVersion
=
0.13.0
serializationVersion
=
0.13.0
coroutinesVersion
=
1.3.2
coroutinesVersion
=
1.3.2
atomicFuVersion
=
0.1
3.0
atomicFuVersion
=
0.1
4.1
kotlinXIoVersion
=
0.1.1
5
kotlinXIoVersion
=
0.1.1
6
coroutinesIoVersion
=
0.
24.0
coroutinesIoVersion
=
0.
1.16
# utility
# utility
ktorVersion
=
1.2.
4
ktorVersion
=
1.2.
6
klockVersion
=
1.7.0
klockVersion
=
1.7.0
# gradle plugin
# gradle plugin
protobufJavaVersion
=
3.10.0
protobufJavaVersion
=
3.10.0
\ No newline at end of file
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsAndroid.kt
View file @
2bf0a963
...
@@ -2,12 +2,7 @@ package net.mamoe.mirai.utils
...
@@ -2,12 +2,7 @@ package net.mamoe.mirai.utils
import
io.ktor.client.HttpClient
import
io.ktor.client.HttpClient
import
io.ktor.client.engine.cio.CIO
import
io.ktor.client.engine.cio.CIO
import
io.ktor.client.request.HttpRequestBuilder
import
io.ktor.http.ContentType
import
io.ktor.http.content.OutgoingContent
import
io.ktor.util.KtorExperimentalAPI
import
io.ktor.util.KtorExperimentalAPI
import
kotlinx.coroutines.io.ByteWriteChannel
import
kotlinx.io.core.Input
import
java.io.DataInput
import
java.io.DataInput
import
java.io.EOFException
import
java.io.EOFException
import
java.io.InputStream
import
java.io.InputStream
...
@@ -33,24 +28,6 @@ internal actual val Http: HttpClient
...
@@ -33,24 +28,6 @@ internal actual val Http: HttpClient
*/
*/
actual
fun
localIpAddress
():
String
=
InetAddress
.
getLocalHost
().
hostAddress
actual
fun
localIpAddress
():
String
=
InetAddress
.
getLocalHost
().
hostAddress
internal
actual
fun
HttpRequestBuilder
.
configureBody
(
inputSize
:
Long
,
input
:
Input
)
{
body
=
object
:
OutgoingContent
.
WriteChannelContent
()
{
override
val
contentType
:
ContentType
=
ContentType
.
Image
.
PNG
override
val
contentLength
:
Long
=
inputSize
override
suspend
fun
writeTo
(
channel
:
ByteWriteChannel
)
{
//不知道为什么这个 channel 在 common 找不到...
val
buffer
=
byteArrayOf
(
1
)
repeat
(
contentLength
.
toInt
())
{
input
.
readFully
(
buffer
,
0
,
1
)
channel
.
writeFully
(
buffer
,
0
,
1
)
}
}
}
}
/**
/**
* MD5 算法
* MD5 算法
*
*
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/Subscribers.kt
View file @
2bf0a963
...
@@ -14,7 +14,7 @@ import kotlin.reflect.KClass
...
@@ -14,7 +14,7 @@ import kotlin.reflect.KClass
/**
/**
* 订阅者的状态
* 订阅者的状态
*/
*/
// Not using enum for Android
inline
class
ListeningStatus
(
inline
val
listening
:
Boolean
)
{
inline
class
ListeningStatus
(
inline
val
listening
:
Boolean
)
{
companion
object
{
companion
object
{
@JvmStatic
@JvmStatic
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotSession.kt
View file @
2bf0a963
...
@@ -86,6 +86,7 @@ abstract class BotSessionBase(
...
@@ -86,6 +86,7 @@ abstract class BotSessionBase(
field
=
value
field
=
value
_gtk
=
getGTK
(
value
)
_gtk
=
getGTK
(
value
)
}
}
@Suppress
(
"PropertyName"
)
internal
lateinit
var
_cookies
:
String
internal
lateinit
var
_cookies
:
String
private
var
_gtk
:
Int
=
0
private
var
_gtk
:
Int
=
0
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/action/GroupImage.kt
View file @
2bf0a963
...
@@ -75,8 +75,8 @@ class ImageDownloadInfo(
...
@@ -75,8 +75,8 @@ class ImageDownloadInfo(
@SerialId
(
13
)
private
val
_original
:
String
?
=
null
,
@SerialId
(
13
)
private
val
_original
:
String
?
=
null
,
@SerialId
(
14
)
private
val
_compressed
:
String
?
=
null
@SerialId
(
14
)
private
val
_compressed
:
String
?
=
null
)
:
GroupImageResponse
,
ImageLink
{
)
:
GroupImageResponse
,
ImageLink
{
private
val
port
:
List
<
Byte
>
get
()
=
_port
!!
private
inline
val
port
:
List
<
Byte
>
get
()
=
_port
!!
private
val
host
:
String
get
()
=
"http://"
+
_host
!!
private
inline
val
host
:
String
get
()
=
"http://"
+
_host
!!
val
thumbnail
:
String
get
()
=
host
+
":"
+
port
.
first
()
+
_thumbnail
!!
val
thumbnail
:
String
get
()
=
host
+
":"
+
port
.
first
()
+
_thumbnail
!!
override
val
original
:
String
get
()
=
host
+
":"
+
port
.
first
()
+
_original
!!
override
val
original
:
String
get
()
=
host
+
":"
+
port
.
first
()
+
_original
!!
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/action/HttpAPIAccessor.kt
View file @
2bf0a963
...
@@ -4,12 +4,14 @@ package net.mamoe.mirai.network.protocol.tim.packet.action
...
@@ -4,12 +4,14 @@ package net.mamoe.mirai.network.protocol.tim.packet.action
import
io.ktor.client.HttpClient
import
io.ktor.client.HttpClient
import
io.ktor.client.request.post
import
io.ktor.client.request.post
import
io.ktor.http.ContentType
import
io.ktor.http.HttpStatusCode
import
io.ktor.http.HttpStatusCode
import
io.ktor.http.URLProtocol
import
io.ktor.http.URLProtocol
import
io.ktor.http.content.OutgoingContent
import
io.ktor.http.userAgent
import
io.ktor.http.userAgent
import
kotlinx.coroutines.io.ByteWriteChannel
import
kotlinx.io.core.Input
import
kotlinx.io.core.Input
import
net.mamoe.mirai.contact.GroupId
import
net.mamoe.mirai.contact.GroupId
import
net.mamoe.mirai.utils.configureBody
@Suppress
(
"SpellCheckingInspection"
)
@Suppress
(
"SpellCheckingInspection"
)
...
@@ -41,7 +43,18 @@ internal suspend inline fun HttpClient.postImage(
...
@@ -41,7 +43,18 @@ internal suspend inline fun HttpClient.postImage(
userAgent
(
"QQClient"
)
userAgent
(
"QQClient"
)
}
}
configureBody
(
inputSize
,
imageInput
)
body
=
object
:
OutgoingContent
.
WriteChannelContent
()
{
override
val
contentType
:
ContentType
=
ContentType
.
Image
.
PNG
override
val
contentLength
:
Long
=
inputSize
override
suspend
fun
writeTo
(
channel
:
ByteWriteChannel
)
{
val
buffer
=
byteArrayOf
(
1
)
repeat
(
contentLength
.
toInt
())
{
imageInput
.
readFully
(
buffer
,
0
,
1
)
channel
.
writeFully
(
buffer
,
0
,
1
)
}
}
}
}
==
HttpStatusCode
.
OK
}
==
HttpStatusCode
.
OK
}
finally
{
}
finally
{
imageInput
.
close
()
imageInput
.
close
()
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/PlatformUtils.kt
View file @
2bf0a963
...
@@ -4,8 +4,6 @@ package net.mamoe.mirai.utils
...
@@ -4,8 +4,6 @@ package net.mamoe.mirai.utils
import
com.soywiz.klock.DateTime
import
com.soywiz.klock.DateTime
import
io.ktor.client.HttpClient
import
io.ktor.client.HttpClient
import
io.ktor.client.request.HttpRequestBuilder
import
kotlinx.io.core.Input
/**
/**
* 时间戳
* 时间戳
...
@@ -45,7 +43,3 @@ expect fun localIpAddress(): String
...
@@ -45,7 +43,3 @@ expect fun localIpAddress(): String
*/
*/
@PublishedApi
@PublishedApi
internal
expect
val
Http
:
HttpClient
internal
expect
val
Http
:
HttpClient
// FIXME: 2019/10/28 这个方法不是很好的实现
internal
expect
fun
HttpRequestBuilder
.
configureBody
(
inputSize
:
Long
,
input
:
Input
)
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
View file @
2bf0a963
...
@@ -4,13 +4,6 @@ package net.mamoe.mirai.utils
...
@@ -4,13 +4,6 @@ package net.mamoe.mirai.utils
import
io.ktor.client.HttpClient
import
io.ktor.client.HttpClient
import
io.ktor.client.engine.cio.CIO
import
io.ktor.client.engine.cio.CIO
import
io.ktor.client.request.HttpRequestBuilder
import
io.ktor.client.request.get
import
io.ktor.http.ContentType
import
io.ktor.http.content.OutgoingContent
import
kotlinx.coroutines.io.ByteWriteChannel
import
kotlinx.io.core.ByteReadPacket
import
kotlinx.io.core.Input
import
java.io.DataInput
import
java.io.DataInput
import
java.io.EOFException
import
java.io.EOFException
import
java.io.InputStream
import
java.io.InputStream
...
@@ -57,28 +50,4 @@ actual fun solveIpAddress(hostname: String): String = InetAddress.getByName(host
...
@@ -57,28 +50,4 @@ actual fun solveIpAddress(hostname: String): String = InetAddress.getByName(host
actual
fun
localIpAddress
():
String
=
InetAddress
.
getLocalHost
().
hostAddress
actual
fun
localIpAddress
():
String
=
InetAddress
.
getLocalHost
().
hostAddress
actual
val
Http
:
HttpClient
get
()
=
HttpClient
(
CIO
)
actual
val
Http
:
HttpClient
get
()
=
HttpClient
(
CIO
)
\ No newline at end of file
suspend
fun
HttpClient
.
getURL
(
url
:
String
):
ByteReadPacket
{
return
this
.
get
(
url
)
}
internal
actual
fun
HttpRequestBuilder
.
configureBody
(
inputSize
:
Long
,
input
:
Input
)
{
//body = ByteArrayContent(input.readBytes(), ContentType.Image.PNG)
body
=
object
:
OutgoingContent
.
WriteChannelContent
()
{
override
val
contentType
:
ContentType
=
ContentType
.
Image
.
PNG
override
val
contentLength
:
Long
=
inputSize
override
suspend
fun
writeTo
(
channel
:
ByteWriteChannel
)
{
//不知道为什么这个 channel 在 common 找不到...
val
buffer
=
byteArrayOf
(
1
)
repeat
(
contentLength
.
toInt
())
{
input
.
readFully
(
buffer
,
0
,
1
)
channel
.
writeFully
(
buffer
,
0
,
1
)
}
}
}
}
\ No newline at end of file
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