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
3ab540d5
Commit
3ab540d5
authored
Oct 24, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename BufferedImage as ExternalImage
parent
0334d33d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
34 deletions
+31
-34
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/UploadFriendImage.kt
...oe.mirai/network/protocol/tim/packet/UploadFriendImage.kt
+5
-8
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/UploadGroupImage.kt
...moe.mirai/network/protocol/tim/packet/UploadGroupImage.kt
+17
-17
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/ExternalImage.kt
.../commonMain/kotlin/net.mamoe.mirai/utils/ExternalImage.kt
+4
-4
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/BufferedImageJvm.kt
.../jvmMain/kotlin/net/mamoe/mirai/utils/BufferedImageJvm.kt
+5
-5
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/UploadFriendImage.kt
View file @
3ab540d5
...
@@ -2,8 +2,6 @@
...
@@ -2,8 +2,6 @@
package
net.mamoe.mirai.network.protocol.tim.packet
package
net.mamoe.mirai.network.protocol.tim.packet
import
kotlinx.coroutines.GlobalScope
import
kotlinx.coroutines.launch
import
kotlinx.io.core.*
import
kotlinx.io.core.*
import
net.mamoe.mirai.contact.QQ
import
net.mamoe.mirai.contact.QQ
import
net.mamoe.mirai.message.ImageId
import
net.mamoe.mirai.message.ImageId
...
@@ -17,7 +15,7 @@ import net.mamoe.mirai.utils.io.*
...
@@ -17,7 +15,7 @@ import net.mamoe.mirai.utils.io.*
/**
/**
* 上传图片
* 上传图片
*/
*/
suspend
fun
QQ
.
uploadImage
(
image
:
Buffered
Image
):
ImageId
=
with
(
bot
.
network
.
session
)
{
suspend
fun
QQ
.
uploadImage
(
image
:
External
Image
):
ImageId
=
with
(
bot
.
network
.
session
)
{
//SubmitImageFilenamePacket(account, account, "sdiovaoidsa.png", sessionKey).sendAndExpect<ServerSubmitImageFilenameResponsePacket>().join()
//SubmitImageFilenamePacket(account, account, "sdiovaoidsa.png", sessionKey).sendAndExpect<ServerSubmitImageFilenameResponsePacket>().join()
DebugLogger
.
logPurple
(
"正在上传好友图片, md5=${image.md5.toUHexString()}"
)
DebugLogger
.
logPurple
(
"正在上传好友图片, md5=${image.md5.toUHexString()}"
)
return
FriendImageIdRequestPacket
(
this
.
qqAccount
,
sessionKey
,
this
.
qqAccount
,
image
).
sendAndExpect
<
FriendImageIdRequestPacket
.
Response
,
ImageId
>
{
return
FriendImageIdRequestPacket
(
this
.
qqAccount
,
sessionKey
,
this
.
qqAccount
,
image
).
sendAndExpect
<
FriendImageIdRequestPacket
.
Response
,
ImageId
>
{
...
@@ -106,7 +104,7 @@ class FriendImageIdRequestPacket(
...
@@ -106,7 +104,7 @@ class FriendImageIdRequestPacket(
private
val
botNumber
:
UInt
,
private
val
botNumber
:
UInt
,
private
val
sessionKey
:
ByteArray
,
private
val
sessionKey
:
ByteArray
,
private
val
target
:
UInt
,
private
val
target
:
UInt
,
private
val
image
:
Buffered
Image
private
val
image
:
External
Image
)
:
OutgoingPacket
()
{
)
:
OutgoingPacket
()
{
//00 00 00 07 00 00 00 4B 08 01 12 03 98 01 01 08 01 12 47 08 A2 FF 8C F0 03 10 89 FC A6 8C 0B 18 00 22 10 2B 23 D7 05 CA D1 F2 CF 37 10 FE 58 26 92 FC C4 28 FD 08 32 1A 7B 00 47 00 47 00 42 00 7E 00 49 00 31 00 5A 00 4D 00 43 00 28 00 25 00 49 00 38 01 48 00 70 42 78 42
//00 00 00 07 00 00 00 4B 08 01 12 03 98 01 01 08 01 12 47 08 A2 FF 8C F0 03 10 89 FC A6 8C 0B 18 00 22 10 2B 23 D7 05 CA D1 F2 CF 37 10 FE 58 26 92 FC C4 28 FD 08 32 1A 7B 00 47 00 47 00 42 00 7E 00 49 00 31 00 5A 00 4D 00 43 00 28 00 25 00 49 00 38 01 48 00 70 42 78 42
...
@@ -221,7 +219,6 @@ class FriendImageIdRequestPacket(
...
@@ -221,7 +219,6 @@ class FriendImageIdRequestPacket(
writeUVarInt
(
image
.
inputSize
.
toUInt
())
writeUVarInt
(
image
.
inputSize
.
toUInt
())
GlobalScope
.
launch
{
}
writeUByte
(
0
x32u
)
writeUByte
(
0
x32u
)
//长度应为1A
//长度应为1A
writeUVarintLVPacket
{
writeUVarintLVPacket
{
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/UploadGroupImage.kt
View file @
3ab540d5
...
@@ -12,14 +12,14 @@ import net.mamoe.mirai.utils.io.toUHexString
...
@@ -12,14 +12,14 @@ import net.mamoe.mirai.utils.io.toUHexString
suspend
fun
Group
.
uploadImage
(
suspend
fun
Group
.
uploadImage
(
image
:
Buffered
Image
image
:
External
Image
)
=
with
(
bot
.
network
.
session
)
{
)
=
with
(
bot
.
network
.
session
)
{
GroupImageIdRequestPacket
(
bot
.
qqAccount
,
group
Id
,
image
,
sessionKey
)
GroupImageIdRequestPacket
(
bot
.
qqAccount
,
internal
Id
,
image
,
sessionKey
)
.
sendAndExpect
<
GroupImageIdRequestPacket
.
Response
,
Unit
>
{
.
sendAndExpect
<
GroupImageIdRequestPacket
.
Response
,
Unit
>
{
if
(
it
.
uKey
!=
null
)
{
if
(
it
.
uKey
!=
null
)
{
httpPostGroupImage
(
httpPostGroupImage
(
botAccount
=
bot
.
qqAccount
,
botAccount
=
bot
.
qqAccount
,
groupNumber
=
group
Id
,
groupNumber
=
internal
Id
,
imageInput
=
image
.
input
,
imageInput
=
image
.
input
,
inputSize
=
image
.
inputSize
,
inputSize
=
image
.
inputSize
,
uKeyHex
=
it
.
uKey
!!
.
toUHexString
(
""
)
uKeyHex
=
it
.
uKey
!!
.
toUHexString
(
""
)
...
@@ -36,7 +36,7 @@ suspend fun Group.uploadImage(
...
@@ -36,7 +36,7 @@ suspend fun Group.uploadImage(
class
GroupImageIdRequestPacket
(
class
GroupImageIdRequestPacket
(
private
val
bot
:
UInt
,
private
val
bot
:
UInt
,
private
val
groupId
:
UInt
,
private
val
groupId
:
UInt
,
private
val
image
:
Buffered
Image
,
private
val
image
:
External
Image
,
private
val
sessionKey
:
ByteArray
private
val
sessionKey
:
ByteArray
)
:
OutgoingPacket
()
{
)
:
OutgoingPacket
()
{
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/
Buffered
Image.kt
→
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/
External
Image.kt
View file @
3ab540d5
...
@@ -6,15 +6,15 @@ import kotlinx.io.core.ByteReadPacket
...
@@ -6,15 +6,15 @@ import kotlinx.io.core.ByteReadPacket
import
kotlinx.io.core.Input
import
kotlinx.io.core.Input
import
net.mamoe.mirai.message.ImageId
import
net.mamoe.mirai.message.ImageId
fun
Buffered
Image
(
fun
External
Image
(
width
:
Int
,
width
:
Int
,
height
:
Int
,
height
:
Int
,
md5
:
ByteArray
,
md5
:
ByteArray
,
format
:
String
,
format
:
String
,
data
:
ByteReadPacket
data
:
ByteReadPacket
)
=
Buffered
Image
(
width
,
height
,
md5
,
format
,
data
,
data
.
remaining
)
)
=
External
Image
(
width
,
height
,
md5
,
format
,
data
,
data
.
remaining
)
class
Buffered
Image
(
class
External
Image
(
val
width
:
Int
,
val
width
:
Int
,
val
height
:
Int
,
val
height
:
Int
,
val
md5
:
ByteArray
,
val
md5
:
ByteArray
,
...
@@ -28,7 +28,7 @@ class BufferedImage(
...
@@ -28,7 +28,7 @@ class BufferedImage(
*/
*/
val
groupImageId
:
ImageId
by
lazy
{
ImageId
(
"{${md5[0..3]}-${md5[4..5]}-${md5[6..7]}-${md5[8..9]}-${md5[10..15]}}.$format"
)
}
val
groupImageId
:
ImageId
by
lazy
{
ImageId
(
"{${md5[0..3]}-${md5[4..5]}-${md5[6..7]}-${md5[8..9]}-${md5[10..15]}}.$format"
)
}
override
fun
toString
():
String
=
"[
Buffered
Image(${width}x${height} $format)]"
override
fun
toString
():
String
=
"[
External
Image(${width}x${height} $format)]"
}
}
private
operator
fun
ByteArray
.
get
(
range
:
IntRange
):
String
=
buildString
{
private
operator
fun
ByteArray
.
get
(
range
:
IntRange
):
String
=
buildString
{
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/BufferedImageJvm.kt
View file @
3ab540d5
...
@@ -13,7 +13,7 @@ import java.security.MessageDigest
...
@@ -13,7 +13,7 @@ import java.security.MessageDigest
import
javax.imageio.ImageIO
import
javax.imageio.ImageIO
import
java.awt.image.BufferedImage
as
JavaBufferedImage
import
java.awt.image.BufferedImage
as
JavaBufferedImage
fun
JavaBufferedImage
.
toMiraiImage
(
formatName
:
String
=
"gif"
):
Buffered
Image
{
fun
JavaBufferedImage
.
toMiraiImage
(
formatName
:
String
=
"gif"
):
External
Image
{
val
digest
=
MessageDigest
.
getInstance
(
"md5"
)
val
digest
=
MessageDigest
.
getInstance
(
"md5"
)
digest
.
reset
()
digest
.
reset
()
...
@@ -28,10 +28,10 @@ fun JavaBufferedImage.toMiraiImage(formatName: String = "gif"): BufferedImage {
...
@@ -28,10 +28,10 @@ fun JavaBufferedImage.toMiraiImage(formatName: String = "gif"): BufferedImage {
})
})
}
}
return
Buffered
Image
(
width
,
height
,
digest
.
digest
(),
formatName
,
buffer
)
return
External
Image
(
width
,
height
,
digest
.
digest
(),
formatName
,
buffer
)
}
}
fun
Buffered
Image
.
toJavaImage
():
JavaBufferedImage
=
ImageIO
.
read
(
object
:
InputStream
()
{
fun
External
Image
.
toJavaImage
():
JavaBufferedImage
=
ImageIO
.
read
(
object
:
InputStream
()
{
override
fun
read
():
Int
=
with
(
this
@
toJavaImage
.
input
)
{
override
fun
read
():
Int
=
with
(
this
@
toJavaImage
.
input
)
{
if
(!
endOfInput
)
if
(!
endOfInput
)
readByte
().
toInt
()
readByte
().
toInt
()
...
@@ -39,7 +39,7 @@ fun BufferedImage.toJavaImage(): JavaBufferedImage = ImageIO.read(object : Input
...
@@ -39,7 +39,7 @@ fun BufferedImage.toJavaImage(): JavaBufferedImage = ImageIO.read(object : Input
}
}
})
})
fun
File
.
toMiraiImage
():
Buffered
Image
{
fun
File
.
toMiraiImage
():
External
Image
{
val
image
=
ImageIO
.
getImageReaders
(
this
.
inputStream
()).
asSequence
().
first
()
val
image
=
ImageIO
.
getImageReaders
(
this
.
inputStream
()).
asSequence
().
first
()
val
digest
=
MessageDigest
.
getInstance
(
"md5"
)
val
digest
=
MessageDigest
.
getInstance
(
"md5"
)
...
@@ -53,7 +53,7 @@ fun File.toMiraiImage(): BufferedImage {
...
@@ -53,7 +53,7 @@ fun File.toMiraiImage(): BufferedImage {
})
})
val
dimension
=
image
.
defaultReadParam
.
sourceRenderSize
val
dimension
=
image
.
defaultReadParam
.
sourceRenderSize
return
Buffered
Image
(
return
External
Image
(
width
=
dimension
.
width
,
width
=
dimension
.
width
,
height
=
dimension
.
height
,
height
=
dimension
.
height
,
md5
=
digest
.
digest
(),
md5
=
digest
.
digest
(),
...
...
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