mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-09-02 10:41:40 +12:00
Various small fixes for beacon exchanges
This commit is contained in:
parent
5ce39cf11e
commit
560efbd345
9 changed files with 57 additions and 21 deletions
|
@ -1,5 +1,6 @@
|
||||||
package io.xpipe.beacon;
|
package io.xpipe.beacon;
|
||||||
|
|
||||||
|
import io.xpipe.beacon.exchange.WriteStreamExchange;
|
||||||
import io.xpipe.beacon.exchange.cli.StoreAddExchange;
|
import io.xpipe.beacon.exchange.cli.StoreAddExchange;
|
||||||
import io.xpipe.beacon.util.QuietDialogHandler;
|
import io.xpipe.beacon.util.QuietDialogHandler;
|
||||||
import io.xpipe.core.impl.InternalStreamStore;
|
import io.xpipe.core.impl.InternalStreamStore;
|
||||||
|
@ -174,13 +175,26 @@ public abstract class BeaconConnection implements AutoCloseable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public InternalStreamStore createInternalStreamStore() {
|
public InternalStreamStore createInternalStreamStore() {
|
||||||
|
return createInternalStreamStore(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InternalStreamStore createInternalStreamStore(String name) {
|
||||||
var store = new InternalStreamStore();
|
var store = new InternalStreamStore();
|
||||||
var addReq = StoreAddExchange.Request.builder().storeInput(store).name(store.getUuid().toString()).build();
|
var addReq = StoreAddExchange.Request.builder().storeInput(store).name(name != null ? name : store.getUuid().toString()).build();
|
||||||
StoreAddExchange.Response addRes = performSimpleExchange(addReq);
|
StoreAddExchange.Response addRes = performSimpleExchange(addReq);
|
||||||
QuietDialogHandler.handle(addRes.getConfig(), this);
|
QuietDialogHandler.handle(addRes.getConfig(), this);
|
||||||
return store;
|
return store;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void writeStream(InternalStreamStore s, InputStream in) {
|
||||||
|
writeStream(s.getUuid().toString(), in);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeStream(String name, InputStream in) {
|
||||||
|
performOutputExchange(
|
||||||
|
WriteStreamExchange.Request.builder().name(name).build(), in::transferTo);
|
||||||
|
}
|
||||||
|
|
||||||
private BeaconException unwrapException(Exception exception) {
|
private BeaconException unwrapException(Exception exception) {
|
||||||
if (exception instanceof ServerException s) {
|
if (exception instanceof ServerException s) {
|
||||||
return new BeaconException("An internal server error occurred", s);
|
return new BeaconException("An internal server error occurred", s);
|
||||||
|
|
|
@ -21,8 +21,6 @@ public class RemoveStoreExchange implements MessageExchange {
|
||||||
public static class Request implements RequestMessage {
|
public static class Request implements RequestMessage {
|
||||||
@NonNull
|
@NonNull
|
||||||
String storeName;
|
String storeName;
|
||||||
|
|
||||||
boolean removeUnderlying;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Jacksonized
|
@Jacksonized
|
||||||
|
|
|
@ -10,6 +10,7 @@ import lombok.Value;
|
||||||
import lombok.extern.jackson.Jacksonized;
|
import lombok.extern.jackson.Jacksonized;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class StoreProviderListExchange implements MessageExchange {
|
public class StoreProviderListExchange implements MessageExchange {
|
||||||
|
|
||||||
|
@ -28,6 +29,6 @@ public class StoreProviderListExchange implements MessageExchange {
|
||||||
@Value
|
@Value
|
||||||
public static class Response implements ResponseMessage {
|
public static class Response implements ResponseMessage {
|
||||||
@NonNull
|
@NonNull
|
||||||
List<ProviderEntry> entries;
|
Map<String, List<ProviderEntry>> entries;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,10 +30,14 @@ public class WriteExecuteExchange implements MessageExchange {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
UUID id;
|
UUID id;
|
||||||
|
|
||||||
|
String mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Jacksonized
|
@Jacksonized
|
||||||
@Builder
|
@Builder
|
||||||
@Value
|
@Value
|
||||||
public static class Response implements ResponseMessage {}
|
public static class Response implements ResponseMessage {
|
||||||
|
boolean hasBody;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,9 @@ public class WritePreparationExchange implements MessageExchange {
|
||||||
public static class Request implements RequestMessage {
|
public static class Request implements RequestMessage {
|
||||||
String type;
|
String type;
|
||||||
|
|
||||||
@NonNull
|
DataStore outputStore;
|
||||||
DataStore output;
|
|
||||||
|
DataSourceReference outputSource;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
DataSourceReference source;
|
DataSourceReference source;
|
||||||
|
@ -38,8 +39,6 @@ public class WritePreparationExchange implements MessageExchange {
|
||||||
@Builder
|
@Builder
|
||||||
@Value
|
@Value
|
||||||
public static class Response implements ResponseMessage {
|
public static class Response implements ResponseMessage {
|
||||||
boolean hasBody;
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
DialogReference config;
|
DialogReference config;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,18 @@ public class FileNames {
|
||||||
return normalize(joined);
|
return normalize(joined);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isAbsolute(String file) {
|
||||||
|
if (!file.contains("/") && !file.contains("\\")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file.startsWith("/") && !file.startsWith("~") && !file.matches("^\\w:.*")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static String getParent(String file) {
|
public static String getParent(String file) {
|
||||||
return file.substring(0, file.length() - getFileName(file).length() - 1);
|
return file.substring(0, file.length() - getFileName(file).length() - 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,9 @@ public class FileStore extends JacksonizedValue implements FilenameStore, Stream
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
throw new IllegalStateException("File is missing");
|
throw new IllegalStateException("File is missing");
|
||||||
}
|
}
|
||||||
|
if (!FileNames.isAbsolute(file)) {
|
||||||
|
throw new IllegalStateException("File path is not absolute");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -20,16 +20,13 @@ public class WriteMode extends JacksonizedValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonTypeName("replace")
|
@JsonTypeName("replace")
|
||||||
public static final class Replace extends WriteMode {
|
public static final class Replace extends WriteMode {}
|
||||||
}
|
|
||||||
|
|
||||||
@JsonTypeName("append")
|
@JsonTypeName("append")
|
||||||
public static final class Append extends WriteMode {
|
public static final class Append extends WriteMode {}
|
||||||
}
|
|
||||||
|
|
||||||
@JsonTypeName("prepend")
|
@JsonTypeName("prepend")
|
||||||
public static final class Prepend extends WriteMode {
|
public static final class Prepend extends WriteMode {}
|
||||||
}
|
|
||||||
|
|
||||||
public static final Replace REPLACE = new Replace();
|
public static final Replace REPLACE = new Replace();
|
||||||
public static final Append APPEND = new Append();
|
public static final Append APPEND = new Append();
|
||||||
|
@ -38,4 +35,11 @@ public class WriteMode extends JacksonizedValue {
|
||||||
public final String getId() {
|
public final String getId() {
|
||||||
return getClass().getAnnotation(JsonTypeName.class).value();
|
return getClass().getAnnotation(JsonTypeName.class).value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static WriteMode byId(String id) {
|
||||||
|
return ALL.stream()
|
||||||
|
.filter(writeMode -> writeMode.getId().equalsIgnoreCase(id))
|
||||||
|
.findFirst()
|
||||||
|
.orElseThrow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,13 +112,14 @@ public class TrackEvent {
|
||||||
if (tags.size() > 0) {
|
if (tags.size() > 0) {
|
||||||
s.append(" {\n");
|
s.append(" {\n");
|
||||||
for (var e : tags.entrySet()) {
|
for (var e : tags.entrySet()) {
|
||||||
var value = e.toString().contains("\n")
|
var valueString = e.getValue() != null ? e.getValue().toString() : "null";
|
||||||
|
var value = valueString.contains("\n")
|
||||||
? "\n"
|
? "\n"
|
||||||
+ (e.toString()
|
+ (valueString.toString()
|
||||||
.lines()
|
.lines()
|
||||||
.map(line -> " | " + line)
|
.map(line -> " | " + line)
|
||||||
.collect(Collectors.joining("\n")))
|
.collect(Collectors.joining("\n")))
|
||||||
: e.toString();
|
: valueString;
|
||||||
s.append(" ")
|
s.append(" ")
|
||||||
.append(e.getKey())
|
.append(e.getKey())
|
||||||
.append("=")
|
.append("=")
|
||||||
|
|
Loading…
Reference in a new issue