mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 07:30:14 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
0a911a821c
@ -9,16 +9,20 @@
|
|||||||
|
|
||||||
package upload
|
package upload
|
||||||
|
|
||||||
|
import io.ktor.client.request.forms.MultiPartFormDataContent
|
||||||
|
import io.ktor.client.request.forms.formData
|
||||||
|
import io.ktor.client.request.post
|
||||||
|
import io.ktor.client.statement.HttpResponse
|
||||||
|
import io.ktor.http.isSuccess
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.kotlin.dsl.provideDelegate
|
import org.gradle.kotlin.dsl.provideDelegate
|
||||||
import org.jsoup.Connection
|
|
||||||
import org.jsoup.Jsoup
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
object CuiCloud {
|
object CuiCloud {
|
||||||
private fun getUrl(project: Project): String {
|
private fun getUrl(project: Project): String {
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
@ -83,23 +87,47 @@ object CuiCloud {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseExperimental(ExperimentalStdlibApi::class)
|
||||||
private suspend fun uploadToCuiCloud(
|
private suspend fun uploadToCuiCloud(
|
||||||
cuiCloudUrl: String,
|
cuiCloudUrl: String,
|
||||||
cuiToken: String,
|
cuiToken: String,
|
||||||
filePath: String,
|
filePath: String,
|
||||||
content: ByteArray
|
content: ByteArray
|
||||||
) {
|
) {
|
||||||
|
println("filePath=$filePath")
|
||||||
|
println("content=${content.size / 1024 / 1024} MB")
|
||||||
|
|
||||||
val response = withContext(Dispatchers.IO) {
|
val response = withContext(Dispatchers.IO) {
|
||||||
Jsoup.connect(cuiCloudUrl).method(Connection.Method.POST)
|
Http.post<HttpResponse>(cuiCloudUrl) {
|
||||||
.data("base64", Base64.getEncoder().encodeToString(content))
|
body = MultiPartFormDataContent(
|
||||||
.data("filePath", filePath)
|
formData {
|
||||||
.data("key", cuiToken)
|
append("base64", Base64.getEncoder().encodeToString(content))
|
||||||
.timeout(Int.MAX_VALUE)
|
append("filePath", filePath)
|
||||||
.execute()
|
append("key", cuiToken)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (response.statusCode() != 200) {
|
println(response.status)
|
||||||
println(response.body())
|
|
||||||
error("Cui Cloud Does Not Return 200")
|
val buffer = ByteArray(4096)
|
||||||
|
val resp = buildList<Byte> {
|
||||||
|
while (true) {
|
||||||
|
val read = response.content.readAvailable(buffer, 0, buffer.size)
|
||||||
|
if (read == -1) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
addAll(buffer.toList().take(read))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println(String(resp.toByteArray()))
|
||||||
|
|
||||||
|
if (!response.status.isSuccess()) {
|
||||||
|
error("Cui cloud response: ${response.status}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline fun <E> buildList(builderAction: MutableList<E>.() -> Unit): List<E> {
|
||||||
|
return ArrayList<E>().apply(builderAction)
|
||||||
|
}
|
||||||
|
@ -18,6 +18,17 @@ import org.jsoup.Jsoup
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
internal val Http = HttpClient(CIO) {
|
||||||
|
engine {
|
||||||
|
requestTimeout = 600_000
|
||||||
|
}
|
||||||
|
install(HttpTimeout) {
|
||||||
|
socketTimeoutMillis = 600_000
|
||||||
|
requestTimeoutMillis = 600_000
|
||||||
|
connectTimeoutMillis = 600_000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
object GitHub {
|
object GitHub {
|
||||||
|
|
||||||
private fun getGithubToken(project: Project): String {
|
private fun getGithubToken(project: Project): String {
|
||||||
@ -53,16 +64,7 @@ object GitHub {
|
|||||||
fun upload(file: File, url: String, project: Project) = runBlocking {
|
fun upload(file: File, url: String, project: Project) = runBlocking {
|
||||||
val token = getGithubToken(project)
|
val token = getGithubToken(project)
|
||||||
println("token.length=${token.length}")
|
println("token.length=${token.length}")
|
||||||
HttpClient(CIO) {
|
Http.put<String>("$url?access_token=$token") {
|
||||||
engine {
|
|
||||||
requestTimeout = 600_000
|
|
||||||
}
|
|
||||||
install(HttpTimeout) {
|
|
||||||
socketTimeoutMillis = 600_000
|
|
||||||
requestTimeoutMillis = 600_000
|
|
||||||
connectTimeoutMillis = 600_000
|
|
||||||
}
|
|
||||||
}.put<String>("$url?access_token=$token") {
|
|
||||||
val sha = getGithubSha("mirai-repo", "shadow/${project.name}/${file.name}", "master", project)
|
val sha = getGithubSha("mirai-repo", "shadow/${project.name}/${file.name}", "master", project)
|
||||||
println("sha=$sha")
|
println("sha=$sha")
|
||||||
val content = String(Base64.getEncoder().encode(file.readBytes()))
|
val content = String(Base64.getEncoder().encode(file.readBytes()))
|
||||||
|
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
|||||||
#Thu Feb 06 14:10:33 CST 2020
|
#Tue Mar 31 10:18:00 CST 2020
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
Loading…
Reference in New Issue
Block a user