Compare commits

...
9 Commits
Author SHA1 Message Date
33 c273dc396e feat: fix upload 2023-11-01 13:39:37 +08:00
33 6cb37301b6 feat: add cloudflare r2 2023-11-01 12:12:56 +08:00
33 e9e1955fad feat: change version to 14.18.3 2023-10-19 15:28:59 +08:00
33 933f64b810 feat: fix method not found in 1.8-1.12.2 2023-10-19 15:28:08 +08:00
33 e839362f09 feat: fix build 2023-10-16 20:31:19 +08:00
ZekerZhayard 220bddbebb Fix #272 (#273) 2023-10-15 14:51:50 +08:00
33 00c931d434 feat: fix MinecraftCapes 2023-10-11 12:29:02 +08:00
33 119892489f feat: rename enum AuthlibField 2023-10-10 13:58:32 +08:00
ZekerZhayard 9a55a4c615 Adapting to Authlib changes (#269) 2023-10-10 13:54:23 +08:00
20 changed files with 302 additions and 139 deletions

No files matched your search

+13 -9
View File
@@ -56,7 +56,7 @@ jobs:
modtype: [Fabric,Forge-Active,Forge-Legacy]
include:
-
website: TencentCOS
website: ObjectStorage
modtype: All
# -
# website: GitHub-Release
@@ -114,7 +114,7 @@ jobs:
echo "pathlist="$(find build/libs -type f|grep -v "sources"|grep -v "json")"" >> $GITHUB_OUTPUT
-
if: ${{ matrix.website == 'GitHub-PreRelease' && startsWith(github.ref, 'refs/heads') }}
name: 【GitHub Pre-Release】 Delete
name: "[GitHub Pre-Release] Delete"
uses: 8Mi-Tech/delete-release-assets-action@main
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
@@ -133,15 +133,15 @@ jobs:
EOF
-
if: ${{ matrix.website == 'GitHub-PreRelease' && startsWith(github.ref, 'refs/heads') }}
name: 【GitHub Pre-Release】 Upload Tag
uses: richardsimko/update-tag@v1
name: "[GitHub Pre-Release] Upload Tag"
uses: richardsimko/update-tag@v1.0.7
with:
tag_name: CI-Build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
if: ${{ matrix.website == 'GitHub-PreRelease' && startsWith(github.ref, 'refs/heads') }}
name: 【GitHub Pre-Release】 Publish
name: "[GitHub Pre-Release] Publish"
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
@@ -154,7 +154,7 @@ jobs:
-
if: ${{ matrix.website == 'GitHub-Release' && inputs.type == 'Release' }}
uses: softprops/action-gh-release@v1
name: 【GitHub Release】 Publish
name: "[GitHub Release] Publish"
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: CustomSkinLoader ${{ github.ref }}
@@ -162,12 +162,16 @@ jobs:
#generate_release_notes: true
files: ${{ steps.cslenv-github.outputs.pathlist }}
-
if: ${{ matrix.website == 'TencentCOS' }}
name: 【TencentCOS】 Publish
if: ${{ matrix.website == 'ObjectStorage' }}
name: "[ObjectStorage] Publish"
env:
COS_BUCKET: ${{ secrets.COS_BUCKET }}
COS_SECRET_ID: ${{ secrets.COS_SECRET_ID }}
COS_SECRET_KEY: ${{ secrets.COS_SECRET_KEY }}
R2_BASE_URL: ${{ secrets.R2_BASE_URL }}
R2_BUCKET: ${{ secrets.R2_BUCKET }}
R2_SECRET_ID: ${{ secrets.R2_SECRET_ID }}
R2_SECRET_KEY: ${{ secrets.R2_SECRET_KEY }}
IS_SNAPSHOT: ${{ inputs.is-snapshot }}
run: |
export GIT_COMMIT_DESC=$(git log --format=%B -n 1 $GITHUB_SHA)
@@ -176,7 +180,7 @@ jobs:
-
if: ${{ matrix.website == 'CurseForge_Modrinth' && inputs.type == 'Release' }}
name: 【CurseForge & Modrinth】 Publish
name: "[CurseForge & Modrinth] Publish"
uses: Kir-Antipov/[email protected]
with:
modrinth-id: idMHQ4n2
@@ -163,8 +163,8 @@ public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I
Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create();
MinecraftProfilePropertiesResponse propertiesResponce = gson.fromJson(responce.content, MinecraftProfilePropertiesResponse.class);
GameProfile newGameProfile = new GameProfile(propertiesResponce.getId(), propertiesResponce.getName());
newGameProfile.getProperties().putAll(propertiesResponce.getProperties());
GameProfile newGameProfile = new GameProfile(TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_ID.get(propertiesResponce), TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_NAME.get(propertiesResponce));
newGameProfile.getProperties().putAll(TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_PROPERTIES.get(propertiesResponce));
return newGameProfile;
}
@@ -177,7 +177,7 @@ public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I
if (textureProperty == null) {
return Maps.newHashMap();
}
String value = TextureUtil.getPropertyValue(textureProperty);
String value = TextureUtil.AuthlibField.PROPERTY_VALUE_FIELD.get(textureProperty);
if (StringUtils.isBlank(value)) {
return Maps.newHashMap();
}
@@ -185,10 +185,10 @@ public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I
Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
MinecraftTexturesPayload result = gson.fromJson(json, MinecraftTexturesPayload.class);
if (result == null || TextureUtil.getMinecraftTexturesPayloadTextures(result) == null) {
if (result == null || TextureUtil.AuthlibField.MINECRAFT_TEXTURES_PAYLOAD_TEXTURES.get(result) == null) {
return Maps.newHashMap();
}
return TextureUtil.getMinecraftTexturesPayloadTextures(result);
return TextureUtil.AuthlibField.MINECRAFT_TEXTURES_PAYLOAD_TEXTURES.get(result);
}
@Override
@@ -3,7 +3,6 @@ package customskinloader.loader.jsonapi;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import customskinloader.config.SkinSiteProfile;
import customskinloader.loader.JsonAPILoader;
import customskinloader.loader.MojangAPILoader;
import customskinloader.plugin.ICustomSkinLoaderPlugin;
@@ -31,7 +30,7 @@ public class MinecraftCapesAPI implements JsonAPILoader.IJsonAPI {
@Override
public String getRoot() {
return "https://minecraftcapes.net/profile/";
return "https://api.minecraftcapes.net/profile/";
}
}
@@ -64,11 +63,6 @@ public class MinecraftCapesAPI implements JsonAPILoader.IJsonAPI {
return profile;
}
@Override
public String getPayload(SkinSiteProfile ssp) {
return null;
}
@Override
public String getName() {
return "MinecraftCapesAPI";
@@ -49,7 +49,7 @@ public class DynamicSkullManager {
staticTextures.put(profile, Maps.newHashMap());
return;
}
String value = TextureUtil.getPropertyValue(textureProperty);
String value = TextureUtil.AuthlibField.PROPERTY_VALUE_FIELD.get(textureProperty);
if (StringUtils.isBlank(value)) {
staticTextures.put(profile, Maps.newHashMap());
return;
@@ -2,11 +2,10 @@ package customskinloader.utils;
import java.io.File;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.UUID;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload;
import customskinloader.CustomSkinLoader;
import org.apache.commons.codec.binary.Base64;
@@ -40,34 +39,31 @@ public class TextureUtil {
// Some of the classes in Authlib used after Minecraft 23w31a were changed to record classes,
// resulting in changes to method names, so reflection is used here to be compatible with these changes.
private final static Field VALUE_FIELD;
private final static Field TEXTURES_FIELD;
public enum AuthlibField {
PROPERTY_VALUE_FIELD(Property.class, "value"),
MINECRAFT_PROFILE_PROPERTIES_RESPONSE_ID(MinecraftProfilePropertiesResponse.class, "id"),
MINECRAFT_PROFILE_PROPERTIES_RESPONSE_NAME(MinecraftProfilePropertiesResponse.class, "name"),
MINECRAFT_PROFILE_PROPERTIES_RESPONSE_PROPERTIES(MinecraftProfilePropertiesResponse.class, "properties"),
MINECRAFT_TEXTURES_PAYLOAD_TEXTURES(MinecraftTexturesPayload.class, "textures");
static {
try {
VALUE_FIELD = Property.class.getDeclaredField("value");
VALUE_FIELD.setAccessible(true);
TEXTURES_FIELD = MinecraftTexturesPayload.class.getDeclaredField("textures");
TEXTURES_FIELD.setAccessible(true);
} catch (Exception e) {
throw new RuntimeException(e);
private final Field field;
AuthlibField(Class<?> clazz, String name) {
try {
this.field = clazz.getDeclaredField(name);
this.field.setAccessible(true);
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
}
public static String getPropertyValue(Property property) {
try {
return (String) VALUE_FIELD.get(property);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@SuppressWarnings("unchecked")
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getMinecraftTexturesPayloadTextures(MinecraftTexturesPayload payload) {
try {
return (Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>) TEXTURES_FIELD.get(payload);
} catch (Exception e) {
throw new RuntimeException(e);
@SuppressWarnings("unchecked")
public <T> T get(Object o) {
try {
return (T) this.field.get(o);
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
}
+1 -1
View File
@@ -51,7 +51,7 @@ net/minecraft/client/resources/SkinManager net/minecraft/client/resources/SkinMa
loadSkin (Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;)Lnet/minecraft/util/ResourceLocation; m_118825_
net/minecraft/client/resources/SkinManager$1 net/minecraft/client/resources/SkinManager$1
net/minecraft/client/resources/SkinManager$CacheKey net/minecraft/client/resources/SkinManager$CacheKey
profile ()Lcom/mojang/authlib/GameProfile; profile
profile ()Lcom/mojang/authlib/GameProfile; f_290972_
net/minecraft/client/resources/SkinManager$SkinAvailableCallback net/minecraft/client/resources/SkinManager$SkinTextureCallback
skinAvailable (Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/util/ResourceLocation;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)V m_118856_
net/minecraft/client/resources/SkinManager$TextureCache net/minecraft/client/resources/SkinManager$TextureCache
-2
View File
@@ -7,8 +7,6 @@ jar {
])
}
exclude 'net/minecraft/client/resources/IResource.class'
exclude 'net/minecraft/client/resources/IResourceManager.class'
exclude 'net/minecraft/client/resources/SkinManager.class'
exclude 'net/minecraft/client/resources/SkinManager$ISkinAvailableCallback.class'
}
+1 -1
View File
@@ -1,6 +1,6 @@
minecraft_version=1.12.2
minecraft_full_versions=1.8,1.8.8,1.8.9,1.9,1.9.4,1.10,1.10.2,1.11,1.11.2,1.12,1.12.1,1.12.2,1.13.2,1.14.2,1.14.3,1.14.4,1.15,1.15.1,1.15.2,1.16.1,1.16.2,1.16.3,1.16.4,1.16.5
java_full_versions=8,9,10,11,12,13,14,15,16,17,18
java_full_versions=8,9,10,11,12,13,14,15,16,17,18,19,20,21
#forge gradle needs forge version
forge_mc_version=1.12.2
forge_version=14.23.5.2768
@@ -79,9 +79,8 @@ public class SkinManagerTransformer {
il0.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/google/common/collect/ImmutableList", "of", sb.append(")Lcom/google/common/collect/ImmutableList;").toString(), false));
il0.add(new VarInsnNode(Opcodes.ALOAD, 1));
il0.add(new VarInsnNode(Opcodes.ALOAD, 2));
il0.add(new VarInsnNode(Opcodes.ALOAD, 3));
il0.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "createThreadDownloadImageData", "(Lcom/google/common/collect/ImmutableList;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;)[Ljava/lang/Object;", false));
il0.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "createThreadDownloadImageData", "(Lcom/google/common/collect/ImmutableList;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;)[Ljava/lang/Object;", false));
for (int i = 0, len = args.length; i < len; i++) {
il0.add(new InsnNode(Opcodes.DUP));
il0.add(new IntInsnNode(Opcodes.BIPUSH, i));
+1 -1
View File
@@ -1,3 +1,3 @@
name=CustomSkinLoader
group=customskinloader
version=14.18
version=14.18.3
+1 -1
View File
@@ -22,11 +22,11 @@ dependencies {
implementation("com.qcloud:cos_api:5.6.98")
implementation("com.tencentcloudapi:tencentcloud-sdk-java-cdn:3.1.559")
implementation("com.google.code.gson:gson:2.9.0")
implementation("commons-io:commons-io:2.11.0")
implementation("net.minecraftforge.gradle:ForgeGradle:2.3.+")
implementation("gradle.plugin.com.matthewprenger:CurseGradle:1.4.0")
implementation("gradle.plugin.com.modrinth.minotaur:Minotaur:1.2.1")
implementation("org.spongepowered:mixingradle:0.6-SNAPSHOT")
implementation("software.amazon.awssdk:s3:2.21.10")
}
apply from: file("patch.gradle")
@@ -0,0 +1,51 @@
package customskinloader.gradle.storage;
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;
import customskinloader.gradle.util.CdnUtil;
import java.nio.file.Path;
/**
* Tencent Cloud COS
*/
public class CosStorage implements Storage {
private static final String BUCKET_NAME = System.getenv("COS_BUCKET");
private COSClient cosClient = null;
private COSClient getCosClient() {
if (cosClient != null) {
return cosClient;
}
synchronized (this) {
if (cosClient != null) {
return cosClient;
}
COSCredentials cred = new BasicCOSCredentials(
System.getenv("COS_SECRET_ID"),
System.getenv("COS_SECRET_KEY")
);
ClientConfig clientConfig = new ClientConfig(new Region("ap-shanghai"));
cosClient = new COSClient(cred, clientConfig);
return cosClient;
}
}
@Override
public void put(String key, Path file) {
PutObjectRequest putObjectRequest = new PutObjectRequest(BUCKET_NAME, key, file.toFile());
getCosClient().putObject(putObjectRequest);
}
@Override
public String getPublicBaseUrl() {
return CdnUtil.TENCENT_CDN_ROOT;
}
}
@@ -0,0 +1,44 @@
package customskinloader.gradle.storage;
import customskinloader.gradle.util.CdnUtil;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import javax.annotation.Nonnull;
import java.net.URI;
/**
* CloudFlare R2
*/
public class R2Storage extends S3Storage {
@Nonnull
@Override
protected S3Client initClient() {
try {
return S3Client.builder()
.endpointOverride(new URI(System.getenv("R2_BASE_URL")))
.credentialsProvider(
StaticCredentialsProvider.create(
AwsBasicCredentials.create(
System.getenv("R2_SECRET_ID"),
System.getenv("R2_SECRET_KEY"))))
.region(Region.of("auto"))
.build();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Nonnull
@Override
protected String getBucket() {
return System.getenv("R2_BUCKET");
}
@Override
public String getPublicBaseUrl() {
return CdnUtil.CLOUDFLARE_CDN_ROOT;
}
}
@@ -0,0 +1,50 @@
package customskinloader.gradle.storage;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import javax.annotation.Nonnull;
import java.nio.file.Path;
/**
* Amazon Web Service Simple Storage Service
* There is also plenty of S3 compatible API.
*/
public abstract class S3Storage implements Storage {
private S3Client client;
/**
* The S3 client will be initialized only once.
* @return S3 client
*/
protected abstract @Nonnull S3Client initClient();
private @Nonnull S3Client getClient() {
if (client != null) {
return client;
}
synchronized (this) {
if (client != null) {
return client;
}
client = initClient();
return client;
}
}
/**
* Get bucket for object.
* @return bucket
*/
protected abstract @Nonnull String getBucket();
@Override
public void put(String key, Path file) {
getClient().putObject(
PutObjectRequest.builder()
.bucket(getBucket())
.key(key).build(),
file
);
}
}
@@ -0,0 +1,14 @@
package customskinloader.gradle.storage;
import java.nio.file.Path;
public interface Storage {
/**
* Put file to object storage service.
* @param key key
* @param file file
*/
void put(String key, Path file);
String getPublicBaseUrl();
}
@@ -0,0 +1,61 @@
package customskinloader.gradle.storage;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
public class StorageService {
private static final List<Storage> storages = new ArrayList<>();
static {
storages.add(new CosStorage());
storages.add(new R2Storage());
}
/**
* Put file to all storage.
*
* @param key key
* @param file file
*/
public static void put(String key, Path file) {
storages.forEach(it -> it.put(key, file));
}
/**
* Put file to all storage.
*
* @param key key
* @param file file
*/
public static void put(String key, File file) {
put(key, file.toPath());
}
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
/**
* Put object to all storage.
*
* @param key key
* @param obj obj
*/
public static void put(String key, Object obj) throws IOException {
for (Storage it : storages) {
Path file = Paths.get("build/libs/", key);
Files.write(file,
gson.toJson(obj).replace(BASE_URL, it.getPublicBaseUrl()).getBytes(StandardCharsets.UTF_8));
it.put(key, file);
}
}
public static final String BASE_URL = "{BASE_URL}";
}
@@ -1,18 +1,19 @@
package customskinloader.gradle.task;
import java.io.File;
import java.io.IOException;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import customskinloader.gradle.entity.CslDetail;
import customskinloader.gradle.entity.CslLatest;
import customskinloader.gradle.storage.StorageService;
import customskinloader.gradle.util.CdnUtil;
import customskinloader.gradle.util.ConfigUtil;
import customskinloader.gradle.util.CosUtil;
import customskinloader.gradle.util.StorageUtil;
import customskinloader.gradle.util.VersionUtil;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import java.io.File;
import java.io.IOException;
public abstract class UploadBaseTask extends DefaultTask {
public Project rootProject;
@@ -35,25 +36,25 @@ public abstract class UploadBaseTask extends DefaultTask {
//Don't upload sources jar to cos
continue;
}
String key = CosUtil.getKey(file.getName());
String key = StorageUtil.getKey(file.getName());
if (key == null) {
continue;
}
CosUtil.uploadFile(key, file);
String url = CdnUtil.CDN_ROOT + key;
StorageService.put(key, file);
String mcversion = VersionUtil.getMcVersion(file.getName());
if (mcversion.equals("ForgeLegacy")) {
mcversion = "Forge";
}
System.out.printf("csl-%s-%s\t%s%n",
mcversion.replace(".", "").toLowerCase(), cslversion, url);
mcversion.replace(".", "").toLowerCase(),
cslversion, CdnUtil.CLOUDFLARE_CDN_ROOT + key);
if (key.startsWith("mods/") && key.endsWith(".jar") && !key.endsWith("-sources.jar")) {
latest.downloads.put(mcversion, url);
latest.downloads.put(mcversion, StorageService.BASE_URL + key);
}
}
CosUtil.writeAndUploadObject(filename, latest);
StorageService.put(filename, latest);
return latest;
}
@@ -71,7 +72,7 @@ public abstract class UploadBaseTask extends DefaultTask {
});
detail.sortDetails();
CosUtil.writeAndUploadObject(filename, detail);
StorageService.put(filename, detail);
}
protected void uploadBase(String latestJsonName, String detailJsonName) throws IOException, TencentCloudSDKException {
@@ -9,7 +9,8 @@ import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import java.util.Arrays;
public class CdnUtil {
public static final String CDN_ROOT = "https://csl.littleservice.cn/";
public static final String TENCENT_CDN_ROOT = "https://csl.littleservice.cn/";
public static final String CLOUDFLARE_CDN_ROOT = "https://csl.3-3.dev/";
private static CdnClient cdnClient;
private static CdnClient getCdnClient() {
@@ -34,7 +35,7 @@ public class CdnUtil {
* @throws TencentCloudSDKException when Tencent Cloud API has exception
*/
public static void updateCdn(String... paths) throws TencentCloudSDKException {
String[] urls = Arrays.stream(paths).map(it -> CDN_ROOT + it).toArray(String[]::new);
String[] urls = Arrays.stream(paths).map(it -> TENCENT_CDN_ROOT + it).toArray(String[]::new);
//Purge CDN cache
PurgeUrlsCacheRequest purgeReq = new PurgeUrlsCacheRequest();
@@ -1,69 +0,0 @@
package customskinloader.gradle.util;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
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.GetObjectRequest;
import com.qcloud.cos.model.PutObjectRequest;
import com.qcloud.cos.region.Region;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class CosUtil {
public static String getKey(String filename) {
String name = filename.substring(0, filename.lastIndexOf('.'));
if (name.indexOf('-') == -1) {
return null;
}
if (filename.endsWith(".jar")) {
if (filename.contains("Fabric") || filename.contains("Forge")) {
return String.format(
"mods/%s",
filename
);
}
}
return filename;
}
private static final String BUCKET_NAME = System.getenv("COS_BUCKET");
private static COSClient cosClient0 = null;
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
private static 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);
return cosClient0;
}
public static void uploadFile(String key, File file) {
PutObjectRequest putObjectRequest = new PutObjectRequest(BUCKET_NAME, key, file);
getCosClient().putObject(putObjectRequest);
}
public static void writeAndUploadObject(String filename, Object obj) throws IOException {
File file = new File("build/libs/" + filename);
FileUtils.write(file, gson.toJson(obj), StandardCharsets.UTF_8);
CosUtil.uploadFile(filename, file);
}
public static void downloadFile(String key, File file) {
GetObjectRequest getObjectRequest = new GetObjectRequest(BUCKET_NAME, key);
getCosClient().getObject(getObjectRequest, file);
}
}
@@ -0,0 +1,19 @@
package customskinloader.gradle.util;
public class StorageUtil {
public static String getKey(String filename) {
String name = filename.substring(0, filename.lastIndexOf('.'));
if (name.indexOf('-') == -1) {
return null;
}
if (filename.endsWith(".jar")) {
if (filename.contains("Fabric") || filename.contains("Forge")) {
return String.format(
"mods/%s",
filename
);
}
}
return filename;
}
}