mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-20 11:09:39 +00:00
57 lines
1.7 KiB
Groovy
57 lines
1.7 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.region.Region
|
|
|
|
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
|
|
}
|
|
|
|
void uploadFileToCOS(String key, File file) {
|
|
COSCredentials cred = new BasicCOSCredentials(System.getenv("COS_SECRET_ID"), System.getenv("COS_SECRET_KEY"))
|
|
ClientConfig clientConfig = new ClientConfig(new Region("ap-shanghai"))
|
|
COSClient cosClient = new COSClient(cred, clientConfig)
|
|
String bucketName = System.getenv("COS_BUCKET")
|
|
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, file)
|
|
cosClient.putObject(putObjectRequest)
|
|
println("Uploaded to COS: " + key)
|
|
}
|
|
|
|
void uploadFileToCOS(File file) {
|
|
uploadFileToCOS(getKey(file.getName()), file)
|
|
}
|
|
|
|
ext {
|
|
uploadFileToCOS = this.&uploadFileToCOS
|
|
} |