Skip to content

Commit

Permalink
Simplify rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Dec 20, 2024
1 parent 0d4b527 commit 8361135
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
31 changes: 0 additions & 31 deletions server/src/main/java/com/soulfiremc/server/grpc/RPCUtils.java

This file was deleted.

0 comments on commit 8361135

Please sign in to comment.