mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-12 18:57:38 +00:00
87 lines
2.6 KiB
Groovy
87 lines
2.6 KiB
Groovy
/**
|
|
* Gradle Script for COS
|
|
* It can be used to upload or download file from Tencent Cloud COS.
|
|
* COS: https://cloud.tencent.com/document/product/436
|
|
*/
|
|
|
|
buildscript {
|
|
repositories {
|
|
mavenCentral()
|
|
}
|
|
dependencies {
|
|
classpath 'com.qcloud:cos_api:5.4.6'
|
|
}
|
|
}
|
|
|
|
import com.qcloud.cos.COSClient
|
|
import com.qcloud.cos.ClientConfig
|
|
import com.qcloud.cos.auth.BasicCOSCredentials
|
|
import com.qcloud.cos.auth.COSCredentials
|
|
import com.qcloud.cos.model.PutObjectRequest
|
|
import com.qcloud.cos.model.GetObjectRequest
|
|
import com.qcloud.cos.region.Region
|
|
|
|
String getMcVersion(String filename) {
|
|
if (filename.endsWith(".json"))
|
|
return filename.substring(0, filename.indexOf('-'))
|
|
return filename.substring(filename.indexOf('_') + 1, filename.indexOf('-'))
|
|
}
|
|
|
|
String getKey(String filename) {
|
|
String name = filename.substring(0, filename.lastIndexOf('.'))
|
|
if (filename.endsWith(".json"))
|
|
return String.format(
|
|
"versions/%s/%s",
|
|
name,
|
|
filename
|
|
)
|
|
if (filename.endsWith(".jar"))
|
|
return String.format(
|
|
"libraries/customskinloader/%s/%s/%s",
|
|
name.substring(0, name.indexOf('-')),
|
|
name.substring(name.indexOf('-') + 1),
|
|
filename
|
|
)
|
|
return filename
|
|
}
|
|
|
|
ext.bucketName = System.getenv("COS_BUCKET")
|
|
ext.cosUrl = "https://csl.littleservice.cn/"
|
|
ext.cosClient0 = null
|
|
|
|
COSClient getCosClient() {
|
|
if (cosClient0 != null) return cosClient0
|
|
|
|
COSCredentials cred = new BasicCOSCredentials(System.getenv("COS_SECRET_ID"), System.getenv("COS_SECRET_KEY"))
|
|
ClientConfig clientConfig = new ClientConfig(new Region("ap-shanghai"))
|
|
cosClient0 = new COSClient(cred, clientConfig)
|
|
}
|
|
|
|
void uploadFile(String key, File file) {
|
|
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, file)
|
|
getCosClient().putObject(putObjectRequest)
|
|
}
|
|
|
|
void downloadFile(String key, File file) {
|
|
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key)
|
|
getCosClient().getObject(getObjectRequest, file)
|
|
}
|
|
|
|
void uploadArtifacts(String shortVersion) {
|
|
String cslversion = shortVersion.replace(".", "")
|
|
File dir = rootProject.file("build/libs")
|
|
if (!dir.isDirectory()) return
|
|
|
|
File[] files = dir.listFiles()
|
|
for (file in files) {
|
|
String key = getKey(file.getName())
|
|
uploadFile(key, file)
|
|
String url = cosUrl + key
|
|
String mcversion = getMcVersion(file.getName()).replace(".", "").toLowerCase()
|
|
println(String.format("csl-%s-%s\t%s", mcversion, cslversion, url))
|
|
}
|
|
}
|
|
|
|
ext {
|
|
uploadArtifacts = this.&uploadArtifacts
|
|
} |