Browse Source

Merge pull request #7381 in DESIGN/design from feature/10.0 to feature/big-screen

* commit 'c24a1e8f81016d0f0c5f284316967f522f12e3ae':
  REPORT-64738 设计器在线组件库中可见组件应去重且仅显示兼容当前设计器的组件
feature/big-screen
superman 3 years ago
parent
commit
4c8ee3a1e8
  1. 39
      designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java

39
designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java

@ -30,6 +30,9 @@ import java.nio.charset.StandardCharsets;
import java.security.KeyFactory;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.X509EncodedKeySpec;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* created by Harrison on 2020/05/27
@ -55,9 +58,9 @@ public class DownloadUtils {
@NotNull
public static String download(String id, String fileName, com.fr.design.extra.Process<Double> process) throws Exception {
CloseableHttpResponse fileRes = getHttpResponse(REUSES_URL, id);
CloseableHttpResponse fileRes = postDownloadHttpResponse(REUSES_URL, id);
if (fileRes.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) {
fileRes = getHttpResponse(fileRes.getHeaders("Location")[0].getValue());
fileRes = getDownloadHttpResponse(fileRes.getHeaders("Location")[0].getValue());
}
if (fileRes.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
String realPath = StableUtils.pathJoin(ProductConstants.getEnvHome(), ShareComponentConstants.PLUGIN_CACHE, ShareComponentConstants.DOWNLOAD_SHARE);
@ -93,9 +96,11 @@ public class DownloadUtils {
public static String downloadPackage(String id, String fileName, CancelCheck cancelCheck) throws Exception {
CloseableHttpResponse fileRes = getHttpResponse(PACKAGE_REUSES_URL, id);
Map<String, String> params = new HashMap<>();
params.put("designerVersion", ProductConstants.RELEASE_VERSION);
CloseableHttpResponse fileRes = postDownloadHttpResponse(PACKAGE_REUSES_URL, id, params);
if (fileRes.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) {
fileRes = getHttpResponse(fileRes.getHeaders("Location")[0].getValue());
fileRes = getDownloadHttpResponse(fileRes.getHeaders("Location")[0].getValue());
}
String realPath = StableUtils.pathJoin(ProductConstants.getEnvHome(), ShareComponentConstants.PLUGIN_CACHE, ShareComponentConstants.DOWNLOAD_PACKAGE_SHARE);
String filePath;
@ -130,21 +135,33 @@ public class DownloadUtils {
}
}
private static CloseableHttpResponse getHttpResponse(String url, String id) throws Exception {
private static CloseableHttpResponse postDownloadHttpResponse(String url, String id) throws Exception {
return postDownloadHttpResponse(url, id, new HashMap<>());
}
private static CloseableHttpResponse postDownloadHttpResponse(String url, String id, Map<String, String> params) throws Exception {
//先登录一下。不然可能失败
CloseableHttpClient client = createClient();
FineLoggerFactory.getLogger().info("login fr-market");
FineLoggerFactory.getLogger().info("start download widget {}", id);
HttpUriRequest file = RequestBuilder.post()
RequestBuilder builder = RequestBuilder.post()
.setHeader("User-Agent", "Mozilla/5.0")
.setUri(url).addParameter("id", encrypt(id)).addParameter("userId",
String.valueOf(DesignerEnvManager.getEnvManager().getDesignerLoginUid()))
.build();
return client.execute(file);
.setUri(url)
.addParameter("id", encrypt(id))
.addParameter("userId", String.valueOf(DesignerEnvManager.getEnvManager().getDesignerLoginUid()));
if (params != null) {
Set<String> keys = params.keySet();
for (String key: keys) {
builder.addParameter(key, params.get(key));
}
}
return client.execute(builder.build());
}
private static CloseableHttpResponse getHttpResponse(String url) throws Exception {
private static CloseableHttpResponse getDownloadHttpResponse(String url) throws Exception {
//先登录一下。不然可能失败
CloseableHttpClient client = createClient();
HttpUriRequest file = RequestBuilder.get()

Loading…
Cancel
Save