mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-09-27 02:45:36 +00:00
Small fixes for proxies
This commit is contained in:
@@ -14,6 +14,7 @@ import io.xpipe.beacon.exchange.data.ServerErrorMessage;
|
||||
import io.xpipe.core.store.ShellStore;
|
||||
import io.xpipe.core.util.Deobfuscator;
|
||||
import io.xpipe.core.util.JacksonMapper;
|
||||
import io.xpipe.core.util.ProxyManagerProvider;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
@@ -122,6 +123,9 @@ public class BeaconClient implements AutoCloseable {
|
||||
|
||||
public static BeaconClient connectProxy(ShellStore proxy) throws Exception {
|
||||
var control = proxy.create().start();
|
||||
if (!ProxyManagerProvider.get().setup(control)) {
|
||||
throw new IOException("X-Pipe connector required to perform operation");
|
||||
}
|
||||
var command = control.command("xpipe beacon --raw").start();
|
||||
command.discardErr();
|
||||
return new BeaconClient(command, command.getStdout(), command.getStdin()) {
|
||||
|
||||
@@ -26,15 +26,6 @@ import java.util.function.Function;
|
||||
|
||||
public class BeaconProxyImpl extends ProxyProvider {
|
||||
|
||||
@SneakyThrows
|
||||
private static DataSource<?> downstreamTransform(DataSource<?> input, ShellStore proxy) {
|
||||
var proxyNode = JacksonMapper.newMapper().valueToTree(proxy);
|
||||
var inputNode = JacksonMapper.newMapper().valueToTree(input);
|
||||
var localNode = JacksonMapper.newMapper().valueToTree(ShellStore.local());
|
||||
replace(inputNode, node -> node.equals(proxyNode) ? Optional.of(localNode) : Optional.empty());
|
||||
return JacksonMapper.newMapper().treeToValue(inputNode, DataSource.class);
|
||||
}
|
||||
|
||||
private static JsonNode replace(JsonNode node, Function<JsonNode, Optional<JsonNode>> function) {
|
||||
var value = function.apply(node);
|
||||
if (value.isPresent()) {
|
||||
@@ -55,6 +46,17 @@ public class BeaconProxyImpl extends ProxyProvider {
|
||||
return replacement;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T downstreamTransform(T object, ShellStore proxy) {
|
||||
var proxyNode = JacksonMapper.getDefault().valueToTree(proxy);
|
||||
var inputNode = JacksonMapper.getDefault().valueToTree(object);
|
||||
var localNode = JacksonMapper.getDefault().valueToTree(ShellStore.local());
|
||||
replace(inputNode, node -> node.equals(proxyNode) ? Optional.of(localNode) : Optional.empty());
|
||||
return (T) JacksonMapper.getDefault().treeToValue(inputNode, object.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShellStore getProxy(Object base) {
|
||||
var proxy = base instanceof Proxyable p ? p.getProxy() : null;
|
||||
|
||||
Reference in New Issue
Block a user