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
588d2d16
Commit
588d2d16
authored
Mar 25, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gradle tasks for uploading artifacts
parent
b70627f3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
54 deletions
+45
-54
build.gradle.kts
build.gradle.kts
+2
-2
buildSrc/build.gradle.kts
buildSrc/build.gradle.kts
+19
-0
buildSrc/src/main/kotlin/upload/GitToken.kt
buildSrc/src/main/kotlin/upload/GitToken.kt
+24
-52
No files found.
build.gradle.kts
View file @
588d2d16
...
@@ -81,11 +81,11 @@ subprojects {
...
@@ -81,11 +81,11 @@ subprojects {
acc
+
100.0
.
pow
(
2
-
index
).
toInt
()
*
(
s
.
toIntOrNull
()
?:
0
)
acc
+
100.0
.
pow
(
2
-
index
).
toInt
()
*
(
s
.
toIntOrNull
()
?:
0
)
}
}
}
?.
let
{
(
_
,
file
)
->
}
?.
let
{
(
_
,
file
)
->
val
filename
=
file
.
name
WithoutExtension
.
substringAfterLast
(
'-'
)
val
filename
=
file
.
name
println
(
"filename=$filename"
)
println
(
"filename=$filename"
)
upload
.
GitToken
.
upload
(
upload
.
GitToken
.
upload
(
file
,
file
,
"https://api.github.com/repos/mamoe/mirai/contents/shdaow/${project.name}/$filename"
"https://api.github.com/repos/mamoe/mirai
-repo
/contents/shdaow/${project.name}/$filename"
)
)
}
}
}
}
...
...
buildSrc/build.gradle.kts
View file @
588d2d16
...
@@ -4,4 +4,23 @@ plugins {
...
@@ -4,4 +4,23 @@ plugins {
repositories
{
repositories
{
jcenter
()
jcenter
()
}
kotlin
{
sourceSets
{
all
{
languageSettings
.
useExperimentalAnnotation
(
"kotlin.Experimental"
)
}
}
}
dependencies
{
fun
kotlinx
(
id
:
String
,
version
:
String
)
=
"org.jetbrains.kotlinx:kotlinx-$id:$version"
fun
ktor
(
id
:
String
,
version
:
String
)
=
"io.ktor:ktor-$id:$version"
api
(
kotlinx
(
"coroutines-core"
,
"1.3.3"
))
api
(
ktor
(
"client-core"
,
"1.3.2"
))
api
(
ktor
(
"client-cio"
,
"1.3.2"
))
api
(
ktor
(
"client-json"
,
"1.3.2"
))
}
}
\ No newline at end of file
buildSrc/src/main/kotlin/upload/GitToken.kt
View file @
588d2d16
@
file
:
Suppress
(
"EXPERIMENTAL_API_USAGE"
)
package
upload
package
upload
import
java.io.*
import
io.ktor.client.HttpClient
import
java.net.HttpURLConnection
import
io.ktor.client.engine.cio.CIO
import
java.net.URL
import
io.ktor.client.features.HttpTimeout
import
io.ktor.client.features.timeout
import
io.ktor.client.request.put
import
kotlinx.coroutines.runBlocking
import
java.io.File
import
java.util.*
import
java.util.*
object
GitToken
{
object
GitToken
{
...
@@ -14,56 +20,22 @@ object GitToken {
...
@@ -14,56 +20,22 @@ object GitToken {
}
}
}
}
fun
upload
(
file
:
File
,
url
:
String
)
{
fun
upload
(
file
:
File
,
url
:
String
)
=
runBlocking
{
val
begin
=
System
.
currentTimeMillis
()
HttpClient
(
CIO
)
{
println
(
"上传开始..."
)
install
(
HttpTimeout
)
//StringBuffer result = new StringBuffer();
}.
put
<
String
>(
"""$url?access_token=${getGitToken()}"""
)
{
//StringBuffer result = new StringBuffer();
timeout
{
var
`in`
:
BufferedReader
?
=
null
connectTimeoutMillis
=
600
_000
var
conn
:
HttpURLConnection
?
=
null
requestTimeoutMillis
=
600
_000
conn
=
URL
(
url
).
openConnection
()
as
HttpURLConnection
socketTimeoutMillis
=
600
_000
conn
.
connectTimeout
=
120000
conn
.
readTimeout
=
120000
// 设置
conn
.
doOutput
=
true
// 需要输出
conn
.
doInput
=
true
// 需要输入
conn
.
useCaches
=
false
// 不允许缓存
conn
.
requestMethod
=
"PUT"
// 设置PUT方式连接
conn
.
setRequestProperty
(
"Content-Type"
,
"application/json"
)
conn
.
setRequestProperty
(
"Authorization"
,
"token "
+
getGitToken
())
conn
.
setRequestProperty
(
"User-Agent"
,
"Github File Uploader App"
)
conn
.
connect
()
// 传输数据
val
dos
=
DataOutputStream
(
conn
.
outputStream
)
// 传输json头部
dos
.
writeBytes
(
"{\"message\":\".\",\"content\":\""
)
// 传输文件内容
val
buffer
=
ByteArray
(
1024
*
1002
)
// 3的倍数
val
raf
=
RandomAccessFile
(
file
,
"r"
)
var
size
:
Long
=
raf
.
read
(
buffer
).
toLong
()
while
(
size
>
-
1
)
{
if
(
size
==
buffer
.
size
.
toLong
())
{
dos
.
write
(
Base64
.
getEncoder
().
encode
(
buffer
))
}
else
{
val
tmp
=
ByteArray
(
size
.
toInt
())
System
.
arraycopy
(
buffer
,
0
,
tmp
,
0
,
size
.
toInt
())
dos
.
write
(
Base64
.
getEncoder
().
encode
(
tmp
))
}
}
size
=
raf
.
read
(
buffer
).
toLong
()
val
content
=
String
(
Base64
.
getEncoder
().
encode
(
file
.
readBytes
()))
}
body
=
"""
raf
.
close
()
{
// 传输json尾部
"message": "automatic upload",
dos
.
writeBytes
(
"\"}"
)
"content": "$content"
dos
.
flush
()
}
dos
.
close
()
"""
.
trimIndent
()
`in`
=
BufferedReader
(
InputStreamReader
(
conn
.
inputStream
))
var
line
:
String
?
while
(
`in`
.
readLine
().
also
{
line
=
it
}
!=
null
)
{
//result.append(line).append("\n");
}
}
val
end
=
System
.
currentTimeMillis
()
System
.
out
.
printf
(
"Upload finished within %d seconds\n"
,
(
end
-
begin
)
/
1000
)
//result.toString()
//result.toString()
}
}
}
}
\ No newline at end of file
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