Fix copyTo

This commit is contained in:
Him188 2020-02-28 22:02:34 +08:00
parent da8a78af12
commit 01ff846929
5 changed files with 37 additions and 34 deletions

View File

@ -118,16 +118,17 @@ internal class QQImpl(
}
is LongConn.OffPicUp.Response.RequireUpload -> {
Http.postImage("0x6ff0070", bot.uin, null, imageInput = image.input, inputSize = image.inputSize, uKeyHex = response.uKey.toUHexString(""))
// HighwayHelper.uploadImage(
// client = bot.client,
// serverIp = response.serverIp[0].toIpV4AddressString(),
// serverPort = response.serverPort[0],
// imageInput = image.input,
// inputSize = image.inputSize.toInt(),
// md5 = image.md5,
// uKey = response.uKey,
// commandId = 1
// )
//HighwayHelper.uploadImage(
// client = bot.client,
// serverIp = response.serverIp[0].toIpV4AddressString(),
// serverPort = response.serverPort[0],
// imageInput = image.input,
// inputSize = image.inputSize.toInt(),
// fileMd5 = image.md5,
// uKey = response.uKey,
// commandId = 1
//)
// 为什么不能 ??
return NotOnlineImageFromFile(
filepath = response.resourceId,

View File

@ -112,7 +112,7 @@ internal open class QQAndroidClient(
private val highwayDataTransSequenceIdForGroup: AtomicInt = atomic(87017)
internal fun nextHighwayDataTransSequenceIdForGroup(): Int = highwayDataTransSequenceIdForGroup.getAndAdd(2)
private val highwayDataTransSequenceIdForFriend: AtomicInt = atomic(40717)
private val highwayDataTransSequenceIdForFriend: AtomicInt = atomic(43973)
internal fun nextHighwayDataTransSequenceIdForFriend(): Int = highwayDataTransSequenceIdForFriend.getAndAdd(2)
val appClientVersion: Int = 0

View File

@ -72,15 +72,17 @@ internal suspend fun HttpClient.postImage(
when (imageInput) {
is Input -> {
var size: Int
while (imageInput.readAvailable(buffer).also { size = it } != 0) {
while (imageInput.readAvailable(buffer).also { size = it } > 0) {
channel.writeFully(buffer, 0, size)
channel.flush()
}
}
is ByteReadChannel -> imageInput.copyAndClose(channel)
is InputStream -> {
var size: Int
while (imageInput.read(buffer).also { size = it } != 0) {
while (imageInput.read(buffer).also { size = it } > 0) {
channel.writeFully(buffer, 0, size)
channel.flush()
}
}
else -> error("unsupported imageInput: ${imageInput::class.simpleName}")

View File

@ -69,7 +69,7 @@ internal fun createImageDataPacketSequence( // RequestDataTrans
localeId = localId
),
msgSeghead = CSDataHighwayHead.SegHead(
cacheAddr = 812157193,
// cacheAddr = 812157193,
datalength = chunkedInput.bufferSize,
dataoffset = offset,
filesize = dataSize.toLong(),

View File

@ -30,11 +30,11 @@ import kotlin.jvm.JvmName
*/
suspend fun ByteReadChannel.copyTo(dst: OutputStream) {
@UseExperimental(MiraiInternalAPI::class)
ByteArrayPool.useInstance {
do {
val size = this.readAvailable(it)
dst.write(it, 0, size)
} while (size != 0)
ByteArrayPool.useInstance { buffer ->
var size: Int
while (this.readAvailable(buffer).also { size = it } > 0) {
dst.write(buffer, 0, size)
}
}
}
@ -43,11 +43,11 @@ suspend fun ByteReadChannel.copyTo(dst: OutputStream) {
*/
suspend fun ByteReadChannel.copyTo(dst: Output) {
@UseExperimental(MiraiInternalAPI::class)
ByteArrayPool.useInstance {
do {
val size = this.readAvailable(it)
dst.writeFully(it, 0, size)
} while (size != 0)
ByteArrayPool.useInstance { buffer ->
var size: Int
while (this.readAvailable(buffer).also { size = it } > 0) {
dst.writeFully(buffer, 0, size)
}
}
}
@ -75,11 +75,11 @@ suspend fun ByteReadChannel.copyTo(dst: kotlinx.coroutines.io.ByteWriteChannel)
suspend fun ByteReadChannel.copyAndClose(dst: OutputStream) {
try {
@UseExperimental(MiraiInternalAPI::class)
ByteArrayPool.useInstance {
do {
val size = this.readAvailable(it)
dst.write(it, 0, size)
} while (size != 0)
ByteArrayPool.useInstance { buffer ->
var size: Int
while (this.readAvailable(buffer).also { size = it } > 0) {
dst.write(buffer, 0, size)
}
}
} finally {
dst.close()
@ -92,11 +92,11 @@ suspend fun ByteReadChannel.copyAndClose(dst: OutputStream) {
suspend fun ByteReadChannel.copyAndClose(dst: Output) {
try {
@UseExperimental(MiraiInternalAPI::class)
ByteArrayPool.useInstance {
do {
val size = this.readAvailable(it)
dst.writeFully(it, 0, size)
} while (size != 0)
ByteArrayPool.useInstance { buffer ->
var size: Int
while (this.readAvailable(buffer).also { size = it } > 0) {
dst.writeFully(buffer, 0, size)
}
}
} finally {
dst.close()