diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/LobFileHost.java b/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/LobFileHost.java index 928777a9b..1f68725eb 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/LobFileHost.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/LobFileHost.java @@ -26,6 +26,7 @@ public class LobFileHost implements ResourcePackHost { public static final Factory FACTORY = new Factory(); private final Path forcedPackPath; private final String apiKey; + private AccountInfo accountInfo; private String url; private String sha1; @@ -36,6 +37,19 @@ public class LobFileHost implements ResourcePackHost { this.apiKey = apiKey; } + public AccountInfo getAccountInfo() { + return accountInfo; + } + + public String getSpaceUsageText() { + if (accountInfo == null) return "Usage data not available"; + return String.format("Storage: %d/%d MB (%.1f%% used)", + accountInfo.getSpaceUsed() / 1_000_000, + accountInfo.getSpaceQuota() / 1_000_000, + (accountInfo.getSpaceUsed() * 100.0) / accountInfo.getSpaceQuota() + ); + } + @Override public CompletableFuture> requestResourcePackDownloadLink(UUID player) { if (url == null) return CompletableFuture.completedFuture(Collections.emptyList()); @@ -77,6 +91,28 @@ public class LobFileHost implements ResourcePackHost { return future; } + public CompletableFuture fetchAccountInfo() { + try (HttpClient client = HttpClient.newHttpClient()) { + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("https://lobfile.com/api/v3/rest/get-account-info")) + .header("X-API-Key", apiKey) + .GET() + .build(); + + return client.sendAsync(request, HttpResponse.BodyHandlers.ofString()) + .thenApply(response -> { + if (response.statusCode() == 200) { + AccountInfo info = GsonHelper.get().fromJson(response.body(), AccountInfo.class); + if (info.isSuccess()) { + this.accountInfo = info; + return info; + } + } + throw new RuntimeException("Failed to fetch account info: " + response.statusCode()); + }); + } + } + private Map calculateHashes(Path path) throws IOException, NoSuchAlgorithmException { Map hashes = new HashMap<>(); MessageDigest sha1Digest = MessageDigest.getInstance("SHA-1"); @@ -123,13 +159,21 @@ public class LobFileHost implements ResourcePackHost { try { if (response.statusCode() == 200) { Map json = parseJson(response.body()); - if (Boolean.TRUE.equals(json.get("success"))) { this.url = (String) json.get("url"); this.sha1 = localSha1; this.uuid = UUID.randomUUID(); CraftEngine.instance().logger().info("[LobFile] Upload success! Resource pack URL: " + this.url); - future.complete(null); + fetchAccountInfo() + .thenAccept(info -> { + CraftEngine.instance().logger().info("[LobFile] Account Usage Updated: " + getSpaceUsageText()); + future.complete(null); + }) + .exceptionally(ex -> { + CraftEngine.instance().logger().warn("[LobFile] Usage check failed (upload still succeeded): ", ex); + future.complete(null); + return null; + }); } else { future.completeExceptionally(new RuntimeException((String) json.get("error"))); } @@ -172,4 +216,31 @@ public class LobFileHost implements ResourcePackHost { return new LobFileHost(localFilePath, apiKey); } } + + public static class AccountInfo { + private boolean success; + private Map account_info; + private Map account_limits; + private Map account_usage; + + public String getEmail() { + return (String) account_info.get("email"); + } + + public int getSpaceQuota() { + return account_limits.getOrDefault("space_quota", 0); + } + + public int getSpaceUsed() { + return account_usage.getOrDefault("space_used", 0); + } + + public int getSlotsUsed() { + return account_usage.getOrDefault("slots_used", 0); + } + + public boolean isSuccess() { + return success; + } + } } \ No newline at end of file