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
98540004
Commit
98540004
authored
Oct 28, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add comments
parent
28149dfe
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
80 deletions
+6
-80
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/PlatformUtils.kt
.../commonMain/kotlin/net.mamoe.mirai/utils/PlatformUtils.kt
+3
-78
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/OutputUtils.kt
...commonMain/kotlin/net.mamoe.mirai/utils/io/OutputUtils.kt
+3
-2
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/PlatformUtils.kt
View file @
98540004
...
...
@@ -5,12 +5,7 @@ package net.mamoe.mirai.utils
import
com.soywiz.klock.DateTime
import
io.ktor.client.HttpClient
import
io.ktor.client.request.HttpRequestBuilder
import
io.ktor.client.request.post
import
io.ktor.http.HttpStatusCode
import
io.ktor.http.URLProtocol
import
io.ktor.http.userAgent
import
kotlinx.io.core.Input
import
net.mamoe.mirai.contact.GroupId
/**
* 时间戳
...
...
@@ -38,7 +33,7 @@ expect fun md5(byteArray: ByteArray): ByteArray
/**
* Hostname 解析 IP 地址
*/
expect
fun
solveIpAddress
(
hostname
:
String
):
String
expect
fun
solveIpAddress
(
hostname
:
String
):
String
// TODO: 2019/10/28 是否有必要?
/**
* Localhost 解析
...
...
@@ -46,80 +41,10 @@ expect fun solveIpAddress(hostname: String): String
expect
fun
localIpAddress
():
String
/**
*
Provided by Ktor Http
*
Ktor HttpClient. 不同平台使用不同引擎.
*/
internal
expect
val
httpClient
:
HttpClient
/**
* 上传好友图片
*/
@Suppress
(
"DuplicatedCode"
)
suspend
fun
httpPostFriendImage
(
botAccount
:
UInt
,
uKeyHex
:
String
,
imageInput
:
Input
,
inputSize
:
Long
):
Boolean
=
(
httpClient
.
postImage
(
htcmd
=
"0x6ff0070"
,
uin
=
botAccount
,
groupcode
=
null
,
imageInput
=
imageInput
,
inputSize
=
inputSize
,
uKeyHex
=
uKeyHex
)
as
HttpStatusCode
).
value
==
200
/**
* 上传群图片
*/
@Suppress
(
"DuplicatedCode"
)
suspend
fun
httpPostGroupImage
(
botAccount
:
UInt
,
groupId
:
GroupId
,
uKeyHex
:
String
,
imageInput
:
Input
,
inputSize
:
Long
):
Boolean
=
(
httpClient
.
postImage
(
htcmd
=
"0x6ff0071"
,
uin
=
botAccount
,
groupcode
=
groupId
,
imageInput
=
imageInput
,
inputSize
=
inputSize
,
uKeyHex
=
uKeyHex
)
as
HttpStatusCode
).
value
==
200
@Suppress
(
"SpellCheckingInspection"
)
private
suspend
inline
fun
<
reified
T
>
HttpClient
.
postImage
(
htcmd
:
String
,
uin
:
UInt
,
groupcode
:
GroupId
?,
imageInput
:
Input
,
inputSize
:
Long
,
uKeyHex
:
String
):
T
=
try
{
post
{
url
{
protocol
=
URLProtocol
.
HTTP
host
=
"htdata2.qq.com"
path
(
"cgi-bin/httpconn"
)
parameters
[
"htcmd"
]
=
htcmd
parameters
[
"uin"
]
=
uin
.
toLong
().
toString
()
if
(
groupcode
!=
null
)
parameters
[
"groupcode"
]
=
groupcode
.
value
.
toLong
().
toString
()
parameters
[
"term"
]
=
"pc"
parameters
[
"ver"
]
=
"5603"
parameters
[
"filesize"
]
=
inputSize
.
toString
()
parameters
[
"range"
]
=
0
.
toString
()
parameters
[
"ukey"
]
=
uKeyHex
userAgent
(
"QQClient"
)
}
configureBody
(
inputSize
,
imageInput
)
}
}
finally
{
imageInput
.
close
()
}
// FIXME: 2019/10/28 这个方法不是很好的实现
internal
expect
fun
HttpRequestBuilder
.
configureBody
(
inputSize
:
Long
,
input
:
Input
)
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/OutputUtils.kt
View file @
98540004
...
...
@@ -26,6 +26,7 @@ fun BytePacketBuilder.writeShortLVByteArray(byteArray: ByteArray) {
}
// will box, but it doesn't matter
private
fun
<
N
:
Comparable
<
N
>>
N
.
coerceAtMostOrFail
(
maximumValue
:
N
):
N
=
if
(
this
>
maximumValue
)
error
(
"value is greater than its expected maximum value $maximumValue"
)
else
this
...
...
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