fix(console): 上传代理适配服务发现模式
feign.external.url 置空切服务发现后,AliYunRestController 直接 @Value 读该 属性拼上传 URL,得到相对地址导致 RestTemplate 报 URI is not absolute, Yumi 后台上传文件失败。 改为与 feign client 一致的双模式:属性非空用固定地址,为空时通过 LoadBalancerClient 从 Nacos 选取 rc-service-external 实例拼绝对地址。 全仓库审计确认这是唯一一处绕过 @FeignClient 直读 feign.*.url 的代码。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
8922491cbe
commit
0177ca0dce
@ -1,13 +1,17 @@
|
||||
package com.red.circle.console.adapter.app.party3rd;//package com.sugartime.app.server.api.app.external;
|
||||
|
||||
import com.red.circle.common.business.core.constant.ServiceNameConstant;
|
||||
import com.red.circle.external.inner.endpoint.oss.OssServiceClient;
|
||||
import com.red.circle.framework.core.asserts.ResponseAssert;
|
||||
import com.red.circle.tool.core.text.StringUtils;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@ -26,16 +30,32 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
/**
|
||||
* 阿里云服务.
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping(value = "/ali-yun", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping(value = "/ali-yun", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public class AliYunRestController {
|
||||
|
||||
private final OssServiceClient ossServiceClient;
|
||||
@Value("${feign.external.url}")
|
||||
private final LoadBalancerClient loadBalancerClient;
|
||||
|
||||
@Value("${feign.external.url:}")
|
||||
private String externalBaseUrl;
|
||||
|
||||
/**
|
||||
* external 服务基地址:feign.external.url 非空时用固定地址,否则走 Nacos 服务发现选一个实例.
|
||||
*/
|
||||
private String resolveExternalBaseUrl() {
|
||||
if (StringUtils.isNotBlank(externalBaseUrl)) {
|
||||
return externalBaseUrl.replaceAll("/+$", "");
|
||||
}
|
||||
ServiceInstance instance = loadBalancerClient.choose(ServiceNameConstant.SERVICE_EXTERNAL);
|
||||
if (instance == null) {
|
||||
throw new IllegalStateException("no available " + ServiceNameConstant.SERVICE_EXTERNAL + " instance");
|
||||
}
|
||||
return instance.getUri().toString().replaceAll("/+$", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 阿里云sts.
|
||||
*/
|
||||
@ -58,7 +78,7 @@ public class AliYunRestController {
|
||||
fileHeaders.setContentType(MediaType.parseMediaType(file.getContentType()));
|
||||
}
|
||||
|
||||
String uploadUrl = externalBaseUrl.replaceAll("/+$", "")
|
||||
String uploadUrl = resolveExternalBaseUrl()
|
||||
+ "/oss/upload/general?dir=" + encode(dir)
|
||||
+ "&filename=" + encode(filename);
|
||||
ResponseEntity<Map> response;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user