mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-20 02:08:15 +08:00
update 优化短链接非租户域名生成
This commit is contained in:
parent
1e8264a30f
commit
a06570f39c
@ -1,8 +1,11 @@
|
||||
package org.dromara.system.controller.system;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.shortlink.enums.ValidityType;
|
||||
import org.dromara.common.shortlink.properties.ShortLinkProperties;
|
||||
import org.dromara.common.shortlink.utils.ShortLinkUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -20,6 +23,8 @@ import org.springframework.web.servlet.view.RedirectView;
|
||||
@RequestMapping("/resource/short")
|
||||
public class SysShortLinkController {
|
||||
|
||||
private final ShortLinkProperties shortLinkProperties;
|
||||
|
||||
/**
|
||||
* 根据短链接获取长链接并重定向
|
||||
*
|
||||
@ -28,7 +33,7 @@ public class SysShortLinkController {
|
||||
*/
|
||||
@GetMapping("/link")
|
||||
public RedirectView getLongLink(@NotBlank(message = "参数不能为空") String shortUrl) {
|
||||
String longLink = ShortLinkUtils.getLongLink(shortUrl, "/error");
|
||||
String longLink = ShortLinkUtils.getLongLink(shortUrl, shortLinkProperties.getErrorAddress());
|
||||
return new RedirectView(longLink);
|
||||
}
|
||||
|
||||
@ -39,8 +44,16 @@ public class SysShortLinkController {
|
||||
* @return 完整的短链接
|
||||
*/
|
||||
@PostMapping("/shorturl")
|
||||
public String generateShortUrl(@NotBlank(message = "参数不能为空") String longUrl) {
|
||||
return ShortLinkUtils.generateShortUrl(longUrl, ValidityType.THREE_DAYS);
|
||||
public R<String> generateShortUrl(HttpServletRequest request, @NotBlank(message = "参数不能为空") String longUrl) {
|
||||
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