mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-20 18:15:56 +08:00
update 优化生成短链接租户域名获取
This commit is contained in:
parent
1bc60fbc4b
commit
bf6102cf64
@ -195,7 +195,8 @@ sms:
|
|||||||
sdk-app-id: 您的sdkAppId
|
sdk-app-id: 您的sdkAppId
|
||||||
|
|
||||||
shortlink:
|
shortlink:
|
||||||
enabled: false
|
enabled: true
|
||||||
|
api: /dev-api
|
||||||
address: http://localhost/dev-api/resource/short/link?shortUrl=
|
address: http://localhost/dev-api/resource/short/link?shortUrl=
|
||||||
errorAddress: http://localhost/error
|
errorAddress: http://localhost/error
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,11 @@ public class ShortLinkProperties {
|
|||||||
*/
|
*/
|
||||||
private Boolean enabled = false;
|
private Boolean enabled = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 访问前缀 (开启时启用,可不填写,能访问到后端即可)
|
||||||
|
*/
|
||||||
|
private String api;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 短链接主机名或域名
|
* 短链接主机名或域名
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -14,6 +14,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.servlet.view.RedirectView;
|
import org.springframework.web.servlet.view.RedirectView;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 短链接 控制层
|
* 短链接 控制层
|
||||||
*/
|
*/
|
||||||
@ -44,13 +47,16 @@ public class SysShortLinkController {
|
|||||||
* @return 完整的短链接
|
* @return 完整的短链接
|
||||||
*/
|
*/
|
||||||
@PostMapping("/shorturl")
|
@PostMapping("/shorturl")
|
||||||
public R<String> generateShortUrl(HttpServletRequest request, @NotBlank(message = "参数不能为空") String longUrl) {
|
public R<String> generateShortUrl(HttpServletRequest request, @NotBlank(message = "参数不能为空") String longUrl) throws MalformedURLException {
|
||||||
String shorturl;
|
String shorturl;
|
||||||
if (Boolean.FALSE.equals(shortLinkProperties.getEnabled())) {
|
if (Boolean.FALSE.equals(shortLinkProperties.getEnabled())) {
|
||||||
shorturl = ShortLinkUtils.generateShortUrl(shortLinkProperties.getAddress(), longUrl, ValidityType.THREE_DAYS);
|
shorturl = ShortLinkUtils.generateShortUrl(shortLinkProperties.getAddress(), longUrl, ValidityType.THREE_DAYS);
|
||||||
} else {
|
} else {
|
||||||
StringBuffer requestURL = request.getRequestURL();
|
String requestUrl = request.getRequestURL().toString();
|
||||||
String address = requestURL.substring(0, requestURL.indexOf("shorturl")) + "link?shortUrl=";
|
String host = new URL(requestUrl).getHost();
|
||||||
|
String address = requestUrl
|
||||||
|
.replace(host, host + shortLinkProperties.getApi())
|
||||||
|
.replace("shorturl", "link?shortUrl=");
|
||||||
shorturl = ShortLinkUtils.generateShortUrl(address, longUrl, ValidityType.THREE_DAYS);
|
shorturl = ShortLinkUtils.generateShortUrl(address, longUrl, ValidityType.THREE_DAYS);
|
||||||
}
|
}
|
||||||
return R.ok(shorturl);
|
return R.ok(shorturl);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user