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
0a911a82
Commit
0a911a82
authored
Mar 31, 2020
by
Him188
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
1f7bc4e5
ef86de23
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
24 deletions
+54
-24
buildSrc/src/main/kotlin/upload/CuiCloud.kt
buildSrc/src/main/kotlin/upload/CuiCloud.kt
+40
-12
buildSrc/src/main/kotlin/upload/GitHub.kt
buildSrc/src/main/kotlin/upload/GitHub.kt
+12
-10
gradle/wrapper/gradle-wrapper.properties
gradle/wrapper/gradle-wrapper.properties
+2
-2
No files found.
buildSrc/src/main/kotlin/upload/CuiCloud.kt
View file @
0a911a82
...
...
@@ -9,16 +9,20 @@
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.runBlocking
import
kotlinx.coroutines.withContext
import
org.gradle.api.Project
import
org.gradle.kotlin.dsl.provideDelegate
import
org.jsoup.Connection
import
org.jsoup.Jsoup
import
java.io.File
import
java.util.*
@Suppress
(
"DEPRECATION"
)
object
CuiCloud
{
private
fun
getUrl
(
project
:
Project
):
String
{
kotlin
.
runCatching
{
...
...
@@ -83,23 +87,47 @@ object CuiCloud {
}
}
@UseExperimental
(
ExperimentalStdlibApi
::
class
)
private
suspend
fun
uploadToCuiCloud
(
cuiCloudUrl
:
String
,
cuiToken
:
String
,
filePath
:
String
,
content
:
ByteArray
)
{
println
(
"filePath=$filePath"
)
println
(
"content=${content.size / 1024 / 1024} MB"
)
val
response
=
withContext
(
Dispatchers
.
IO
)
{
Jsoup
.
connect
(
cuiCloudUrl
).
method
(
Connection
.
Method
.
POST
)
.
data
(
"base64"
,
Base64
.
getEncoder
().
encodeToString
(
content
))
.
data
(
"filePath"
,
filePath
)
.
data
(
"key"
,
cuiToken
)
.
timeout
(
Int
.
MAX_VALUE
)
.
execute
()
Http
.
post
<
HttpResponse
>(
cuiCloudUrl
)
{
body
=
MultiPartFormDataContent
(
formData
{
append
(
"base64"
,
Base64
.
getEncoder
().
encodeToString
(
content
))
append
(
"filePath"
,
filePath
)
append
(
"key"
,
cuiToken
)
}
)
}
}
if
(
response
.
statusCode
()
!=
200
)
{
println
(
response
.
body
())
error
(
"Cui Cloud Does Not Return 200"
)
println
(
response
.
status
)
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}"
)
}
}
}
\ No newline at end of file
}
inline
fun
<
E
>
buildList
(
builderAction
:
MutableList
<
E
>.()
->
Unit
):
List
<
E
>
{
return
ArrayList
<
E
>().
apply
(
builderAction
)
}
buildSrc/src/main/kotlin/upload/GitHub.kt
View file @
0a911a82
...
...
@@ -18,6 +18,17 @@ import org.jsoup.Jsoup
import
java.io.File
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
{
private
fun
getGithubToken
(
project
:
Project
):
String
{
...
...
@@ -53,16 +64,7 @@ object GitHub {
fun
upload
(
file
:
File
,
url
:
String
,
project
:
Project
)
=
runBlocking
{
val
token
=
getGithubToken
(
project
)
println
(
"token.length=${token.length}"
)
HttpClient
(
CIO
)
{
engine
{
requestTimeout
=
600
_000
}
install
(
HttpTimeout
)
{
socketTimeoutMillis
=
600
_000
requestTimeoutMillis
=
600
_000
connectTimeoutMillis
=
600
_000
}
}.
put
<
String
>(
"$url?access_token=$token"
)
{
Http
.
put
<
String
>(
"$url?access_token=$token"
)
{
val
sha
=
getGithubSha
(
"mirai-repo"
,
"shadow/${project.name}/${file.name}"
,
"master"
,
project
)
println
(
"sha=$sha"
)
val
content
=
String
(
Base64
.
getEncoder
().
encode
(
file
.
readBytes
()))
...
...
gradle/wrapper/gradle-wrapper.properties
View file @
0a911a82
#T
hu Feb 06 14:10:33
CST 2020
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-6.2.2-
bin
.zip
#T
ue Mar 31 10:18:00
CST 2020
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-6.2.2-
all
.zip
distributionBase
=
GRADLE_USER_HOME
distributionPath
=
wrapper/dists
zipStorePath
=
wrapper/dists
...
...
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