From 836113525a3e4157655fa24e439d296ad0e83037 Mon Sep 17 00:00:00 2001
From: AlexProgrammerDE <40795980+AlexProgrammerDE@users.noreply.github.com>
Date: Fri, 20 Dec 2024 09:15:03 +0100
Subject: [PATCH] Simplify rpc

---
 .../server/grpc/DownloadServiceImpl.java      | 10 +++++-
 .../com/soulfiremc/server/grpc/RPCUtils.java  | 31 -------------------
 2 files changed, 9 insertions(+), 32 deletions(-)
 delete mode 100644 server/src/main/java/com/soulfiremc/server/grpc/RPCUtils.java

diff --git a/server/src/main/java/com/soulfiremc/server/grpc/DownloadServiceImpl.java b/server/src/main/java/com/soulfiremc/server/grpc/DownloadServiceImpl.java
index 6953c379c..e275ea662 100644
--- a/server/src/main/java/com/soulfiremc/server/grpc/DownloadServiceImpl.java
+++ b/server/src/main/java/com/soulfiremc/server/grpc/DownloadServiceImpl.java
@@ -19,25 +19,33 @@
 
 import com.google.protobuf.ByteString;
 import com.soulfiremc.grpc.generated.*;
+import com.soulfiremc.server.proxy.SFProxy;
 import com.soulfiremc.server.user.PermissionContext;
 import com.soulfiremc.server.util.ReactorHttpHelper;
 import io.grpc.Status;
 import io.grpc.StatusRuntimeException;
 import io.grpc.stub.StreamObserver;
 import lombok.extern.slf4j.Slf4j;
+import org.jetbrains.annotations.Nullable;
 
 import java.net.URI;
 import java.util.UUID;
+import java.util.function.BooleanSupplier;
+import java.util.function.Supplier;
 
 @Slf4j
 public class DownloadServiceImpl extends DownloadServiceGrpc.DownloadServiceImplBase {
+  public static @Nullable SFProxy convertProxy(BooleanSupplier hasProxy, Supplier<ProxyProto> proxy) {
+    return hasProxy.getAsBoolean() ? SFProxy.fromProto(proxy.get()) : null;
+  }
+
   @Override
   public void download(DownloadRequest request, StreamObserver<DownloadResponse> responseObserver) {
     var instanceId = UUID.fromString(request.getInstanceId());
     ServerRPCConstants.USER_CONTEXT_KEY.get().hasPermissionOrThrow(PermissionContext.instance(InstancePermission.DOWNLOAD_URL, instanceId));
 
     try {
-      var proxy = RPCUtils.convertProxy(request::hasProxy, request::getProxy);
+      var proxy = convertProxy(request::hasProxy, request::getProxy);
       ReactorHttpHelper.createReactorClient(proxy, false)
         .headers(h -> request.getHeadersList().forEach(header -> h.set(header.getKey(), header.getValue())))
         .get()
diff --git a/server/src/main/java/com/soulfiremc/server/grpc/RPCUtils.java b/server/src/main/java/com/soulfiremc/server/grpc/RPCUtils.java
deleted file mode 100644
index 6293cf61e..000000000
--- a/server/src/main/java/com/soulfiremc/server/grpc/RPCUtils.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * SoulFire
- * Copyright (C) 2024  AlexProgrammerDE
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-package com.soulfiremc.server.grpc;
-
-import com.soulfiremc.grpc.generated.ProxyProto;
-import com.soulfiremc.server.proxy.SFProxy;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.function.BooleanSupplier;
-import java.util.function.Supplier;
-
-public class RPCUtils {
-  public static @Nullable SFProxy convertProxy(BooleanSupplier hasProxy, Supplier<ProxyProto> proxy) {
-    return hasProxy.getAsBoolean() ? SFProxy.fromProto(proxy.get()) : null;
-  }
-}