Skip to content

Commit 60fff0d

Browse files
author
Thomasr
committed
add flow api
1 parent b23adc8 commit 60fff0d

File tree

5 files changed

+90
-0
lines changed

5 files changed

+90
-0
lines changed

server/api-service/lowcoder-infra/src/main/java/org/lowcoder/infra/constant/NewUrl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ private NewUrl() {
1111
public static final String USER_URL = PREFIX + "/users";
1212
public static final String CONFIG_URL = PREFIX + "/configs";
1313
public static final String SERVER_SETTING_URL = PREFIX + "/serverSettings";
14+
public static final String FLOW_URL = PREFIX + "/flow";
1415
public static final String GROUP_URL = PREFIX + "/groups";
1516
public static final String ASSET_URL = PREFIX + "/assets";
1617

server/api-service/lowcoder-infra/src/main/java/org/lowcoder/infra/constant/Url.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public final class Url {
77
public static final String DATASOURCE_URL = BASE_URL + VERSION + "/datasources";
88
public static final String USER_URL = BASE_URL + VERSION + "/users";
99
public static final String CONFIG_URL = BASE_URL + VERSION + "/configs";
10+
public static final String FLOW_URL = BASE_URL + VERSION + "/flow";
1011
public static final String SERVER_SETTING_URL = BASE_URL + VERSION + "/serverSettings";
1112
public static final String GROUP_URL = BASE_URL + VERSION + "/groups";
1213
public static final String ASSET_URL = BASE_URL + VERSION + "/assets";

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/framework/security/SecurityConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
9595
// used in public viewed apps
9696
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, CONFIG_URL), // system config
9797
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, SERVER_SETTING_URL), // system env
98+
ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, FLOW_URL), // system config
9899
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, CONFIG_URL + "/deploymentId"), // system config
99100
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, APPLICATION_URL + "/*"), // application view
100101
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, APPLICATION_URL + "/*/view"), // application view
@@ -124,6 +125,8 @@ SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
124125
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.INVITATION_URL + "/**"),
125126
ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, NewUrl.CUSTOM_AUTH + "/logout"),
126127
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.CONFIG_URL),
128+
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.SERVER_SETTING_URL), // system env
129+
ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, NewUrl.FLOW_URL),
127130
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.CONFIG_URL + "/deploymentId"),
128131
ServerWebExchangeMatchers.pathMatchers(HttpMethod.HEAD, NewUrl.STATE_URL + "/healthCheck"),
129132
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.PREFIX + "/status/**"),
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.lowcoder.api.misc;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import lombok.RequiredArgsConstructor;
5+
import org.apache.commons.lang.StringUtils;
6+
import org.lowcoder.api.authentication.request.AuthException;
7+
import org.lowcoder.sdk.util.JsonUtils;
8+
import org.lowcoder.sdk.webclient.WebClientBuildHelper;
9+
import org.springframework.http.HttpHeaders;
10+
import org.springframework.http.HttpMethod;
11+
import org.springframework.http.MediaType;
12+
import org.springframework.web.bind.annotation.RestController;
13+
import org.springframework.web.reactive.function.BodyInserters;
14+
import reactor.core.publisher.Mono;
15+
16+
import java.util.Map;
17+
import java.util.function.Consumer;
18+
19+
import static org.lowcoder.api.authentication.util.AuthenticationUtils.mapToAuthToken;
20+
import static org.lowcoder.sdk.plugin.common.constant.Constants.HTTP_TIMEOUT;
21+
22+
@RequiredArgsConstructor
23+
@RestController
24+
public class ApiFlowController implements ApiFlowEndpoints
25+
{
26+
@Override
27+
public Mono<String> flow(FlowRequest flowRequest) {
28+
try {
29+
String url;
30+
if (StringUtils.isEmpty(flowRequest.host())) url = "https://flow.lowcoder.cloud/" + flowRequest.path();
31+
else url = flowRequest.host() + "/" + flowRequest.path();
32+
ObjectMapper objectMapper = new ObjectMapper();
33+
String jsonBody = objectMapper.writeValueAsString(flowRequest.data());
34+
return WebClientBuildHelper.builder()
35+
.systemProxy()
36+
.timeoutMs(HTTP_TIMEOUT)
37+
.build()
38+
.method(HttpMethod.valueOf(flowRequest.method().toUpperCase()))
39+
.uri(url)
40+
.body(BodyInserters.fromValue(jsonBody))
41+
.headers(httpHeaders -> flowRequest.headers().forEach(httpHeaders::add))
42+
.retrieve()
43+
.bodyToMono(String.class);
44+
} catch (Exception e) {
45+
return Mono.error(e);
46+
}
47+
}
48+
49+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.lowcoder.api.misc;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import io.swagger.v3.oas.annotations.Operation;
5+
import jakarta.annotation.Nullable;
6+
import org.lowcoder.infra.constant.NewUrl;
7+
import org.lowcoder.infra.constant.Url;
8+
import org.springframework.web.bind.annotation.PostMapping;
9+
import org.springframework.web.bind.annotation.RequestBody;
10+
import org.springframework.web.bind.annotation.RequestMapping;
11+
import org.springframework.web.bind.annotation.RestController;
12+
import reactor.core.publisher.Mono;
13+
14+
import java.util.Map;
15+
16+
@RestController
17+
@RequestMapping(value = {Url.FLOW_URL, NewUrl.FLOW_URL})
18+
public interface ApiFlowEndpoints
19+
{
20+
String TAG_SERVER_SETTING_MANAGEMENT = "Flow APIs";
21+
22+
@Operation(
23+
tags = TAG_SERVER_SETTING_MANAGEMENT,
24+
operationId = "flow",
25+
summary = "Call flow api",
26+
description = "Call flow api."
27+
)
28+
@PostMapping
29+
Mono<String> flow(@RequestBody FlowRequest flowRequest);
30+
public record FlowRequest(String path,
31+
String method,
32+
Map<String, Object> data,
33+
Map<String, String> headers,
34+
@Nullable String host) {
35+
}
36+
}

0 commit comments

Comments
 (0)