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
1e8264a30f
commit
a06570f39c
@ -1,8 +1,11 @@
|
|||||||
package org.dromara.system.controller.system;
|
package org.dromara.system.controller.system;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.dromara.common.core.domain.R;
|
||||||
import org.dromara.common.shortlink.enums.ValidityType;
|
import org.dromara.common.shortlink.enums.ValidityType;
|
||||||
|
import org.dromara.common.shortlink.properties.ShortLinkProperties;
|
||||||
import org.dromara.common.shortlink.utils.ShortLinkUtils;
|
import org.dromara.common.shortlink.utils.ShortLinkUtils;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@ -20,6 +23,8 @@ import org.springframework.web.servlet.view.RedirectView;
|
|||||||
@RequestMapping("/resource/short")
|
@RequestMapping("/resource/short")
|
||||||
public class SysShortLinkController {
|
public class SysShortLinkController {
|
||||||
|
|
||||||
|
private final ShortLinkProperties shortLinkProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据短链接获取长链接并重定向
|
* 根据短链接获取长链接并重定向
|
||||||
*
|
*
|
||||||
@ -28,7 +33,7 @@ public class SysShortLinkController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/link")
|
@GetMapping("/link")
|
||||||
public RedirectView getLongLink(@NotBlank(message = "参数不能为空") String shortUrl) {
|
public RedirectView getLongLink(@NotBlank(message = "参数不能为空") String shortUrl) {
|
||||||
String longLink = ShortLinkUtils.getLongLink(shortUrl, "/error");
|
String longLink = ShortLinkUtils.getLongLink(shortUrl, shortLinkProperties.getErrorAddress());
|
||||||
return new RedirectView(longLink);
|
return new RedirectView(longLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,8 +44,16 @@ public class SysShortLinkController {
|
|||||||
* @return 完整的短链接
|
* @return 完整的短链接
|
||||||
*/
|
*/
|
||||||
@PostMapping("/shorturl")
|
@PostMapping("/shorturl")
|
||||||
public String generateShortUrl(@NotBlank(message = "参数不能为空") String longUrl) {
|
public R<String> generateShortUrl(HttpServletRequest request, @NotBlank(message = "参数不能为空") String longUrl) {
|
||||||
return ShortLinkUtils.generateShortUrl(longUrl, ValidityType.THREE_DAYS);
|
String shorturl;
|
||||||
|
if (Boolean.FALSE.equals(shortLinkProperties.getEnabled())) {
|
||||||
|
shorturl = ShortLinkUtils.generateShortUrl(shortLinkProperties.getAddress(), longUrl, ValidityType.THREE_DAYS);
|
||||||
|
} else {
|
||||||
|
StringBuffer requestURL = request.getRequestURL();
|
||||||
|
String address = requestURL.substring(0, requestURL.indexOf("shorturl")) + "link?shortUrl=";
|
||||||
|
shorturl = ShortLinkUtils.generateShortUrl(address, longUrl, ValidityType.THREE_DAYS);
|
||||||
|
}
|
||||||
|
return R.ok(shorturl);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user