perf:增加版本对比器
This commit is contained in:
@@ -14,7 +14,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableTieshengWeb(webConfigurer = DemoWebConfigurer.class)
|
@EnableTieshengWeb(webConfigurer = DemoWebConfigurer.class)
|
||||||
@EnableEncryptConfig
|
//@EnableEncryptConfig
|
||||||
public class DemoApplication {
|
public class DemoApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class TestController {
|
|||||||
@TokenIgnore
|
@TokenIgnore
|
||||||
public void redirect(HttpServletResponse response) {
|
public void redirect(HttpServletResponse response) {
|
||||||
// tsTokenConfig.validToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NzYwMDY4NzUsImlkIjoiMSIsImVudmlyb25tZW50VHlwZSI6Im1vYmlsZSIsInNlcnZpY2UiOiJjb250ZXN0LXJlc2VydmUiLCJleHRyYSI6IiJ9.nsfxEFpCNHC7eNCS5DJXdu1VDdnHrTjSfgrozND70Lc", true);
|
// tsTokenConfig.validToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NzYwMDY4NzUsImlkIjoiMSIsImVudmlyb25tZW50VHlwZSI6Im1vYmlsZSIsInNlcnZpY2UiOiJjb250ZXN0LXJlc2VydmUiLCJleHRyYSI6IiJ9.nsfxEFpCNHC7eNCS5DJXdu1VDdnHrTjSfgrozND70Lc", true);
|
||||||
// globalConfig.redirect("mobile", "/test", response);
|
globalConfig.redirect("mobile", "/test", response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ tiesheng:
|
|||||||
id: "1111"
|
id: "1111"
|
||||||
global:
|
global:
|
||||||
version: 2
|
version: 2
|
||||||
host: http://localhost:8080
|
host: http://localhost:8100
|
||||||
aliyun:
|
aliyun:
|
||||||
access-key-id: LTAI5tJtbgBCnTY5eS4SmrTf
|
access-key-id: LTAI5tJtbgBCnTY5eS4SmrTf
|
||||||
access-key-secret: JIHqpRUFffCHhXaJEVvWN31WcexWqG
|
access-key-secret: JIHqpRUFffCHhXaJEVvWN31WcexWqG
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.tiesheng.util.config;
|
package com.tiesheng.util.config;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.comparator.VersionComparator;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
@@ -12,6 +14,8 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
|||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hao
|
* @author hao
|
||||||
@@ -62,15 +66,22 @@ public class GlobalConfig {
|
|||||||
* @param route
|
* @param route
|
||||||
*/
|
*/
|
||||||
public void redirect(String htmlDir, String route, HttpServletResponse response) {
|
public void redirect(String htmlDir, String route, HttpServletResponse response) {
|
||||||
|
if (!StrUtil.endWith(htmlDir, "/")) {
|
||||||
|
htmlDir = htmlDir + "/";
|
||||||
|
}
|
||||||
PathMatchingResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
|
PathMatchingResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
|
||||||
try {
|
try {
|
||||||
Resource[] resources = patternResolver.getResources(String.format("classpath*:static/%s/*/index.html", htmlDir));
|
Resource[] resources = patternResolver.getResources(String.format("classpath*:static/%s/*/index.html", htmlDir));
|
||||||
if (resources.length == 0) {
|
List<String> versions = new ArrayList<>();
|
||||||
|
for (Resource resource : resources) {
|
||||||
|
String path = FileUtil.normalize(resource.getURL().getPath());
|
||||||
|
versions.add(StrUtil.subBetween(path, htmlDir, "/index.html"));
|
||||||
|
}
|
||||||
|
if (CollUtil.isEmpty(versions)) {
|
||||||
throw new ApiException("无法重定向,请检查资源");
|
throw new ApiException("无法重定向,请检查资源");
|
||||||
}
|
}
|
||||||
String filename = resources[resources.length - 1].getURL().getPath();
|
CollUtil.sort(versions, (o1, o2) -> -VersionComparator.INSTANCE.compare(o1, o2));
|
||||||
filename = FileUtil.normalize(filename);
|
String path = buildPath(String.format("/%s%s/index.html#%s", htmlDir, versions.get(0), route));
|
||||||
String path = buildPath(String.format("/%s%s#%s", htmlDir, StrUtil.subAfter(filename, htmlDir, true), route));
|
|
||||||
response.sendRedirect(path);
|
response.sendRedirect(path);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogFactory.get().info(e);
|
LogFactory.get().info(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user