perf:版本号现在可以从外部目录中获取
This commit is contained in:
@@ -5,6 +5,7 @@ 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;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
import cn.hutool.log.LogFactory;
|
import cn.hutool.log.LogFactory;
|
||||||
import com.tiesheng.util.exception.ApiException;
|
import com.tiesheng.util.exception.ApiException;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
@@ -13,6 +14,7 @@ import org.springframework.core.io.Resource;
|
|||||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -71,12 +73,24 @@ public class GlobalConfig {
|
|||||||
}
|
}
|
||||||
PathMatchingResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
|
PathMatchingResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
|
||||||
try {
|
try {
|
||||||
Resource[] resources = patternResolver.getResources(String.format("classpath*:static/%s*/index.html", htmlDir));
|
|
||||||
List<String> versions = new ArrayList<>();
|
List<String> versions = new ArrayList<>();
|
||||||
|
|
||||||
|
// jar包中的资源
|
||||||
|
Resource[] resources = patternResolver.getResources(String.format("classpath*:static/%s*/index.html", htmlDir));
|
||||||
for (Resource resource : resources) {
|
for (Resource resource : resources) {
|
||||||
String path = FileUtil.normalize(resource.getURL().getPath());
|
String path = FileUtil.normalize(resource.getURL().getPath());
|
||||||
versions.add(StrUtil.subBetween(path, htmlDir, "/index.html"));
|
versions.add(StrUtil.subBetween(path, htmlDir, "/index.html"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 目录中的资源
|
||||||
|
String folder = String.format("%s/static/%s", System.getProperty("user.dir"), htmlDir);
|
||||||
|
if (FileUtil.exist(folder)) {
|
||||||
|
File[] files = FileUtil.ls(folder);
|
||||||
|
for (File file : files) {
|
||||||
|
versions.add(StrUtil.subAfter(file.getAbsolutePath(), htmlDir, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (CollUtil.isEmpty(versions)) {
|
if (CollUtil.isEmpty(versions)) {
|
||||||
throw new ApiException("无法重定向,请检查资源");
|
throw new ApiException("无法重定向,请检查资源");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user