实现stp文件Windows本地预览。
This commit is contained in:
parent
85b0521e62
commit
9bd93c68bc
|
|
@ -28,6 +28,7 @@ import org.springframework.stereotype.Component;
|
|||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
|
@ -61,6 +62,31 @@ public class LoginInterceptor implements HandlerInterceptor {
|
|||
return ipAddress;
|
||||
}
|
||||
|
||||
private static String getSuffixFromUrl(String url) {
|
||||
if (url == null || url.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// 先去除查询参数和锚点
|
||||
int queryIndex = url.indexOf('?');
|
||||
int fragmentIndex = url.indexOf('#');
|
||||
|
||||
String path = url;
|
||||
if (queryIndex > 0) {
|
||||
path = url.substring(0, queryIndex);
|
||||
} else if (fragmentIndex > 0) {
|
||||
path = url.substring(0, fragmentIndex);
|
||||
}
|
||||
|
||||
// 获取最后一个点之后的部分
|
||||
int lastDotIndex = path.lastIndexOf('.');
|
||||
if (lastDotIndex > 0 && lastDotIndex < path.length() - 1) {
|
||||
return path.substring(lastDotIndex + 1).toLowerCase();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private static String parseIpFromUrl(String url) {
|
||||
|
||||
int start = url.indexOf("//");
|
||||
|
|
@ -76,6 +102,14 @@ public class LoginInterceptor implements HandlerInterceptor {
|
|||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
|
||||
String uri = request.getRequestURI();
|
||||
List<String> suffixs = Arrays.asList("js", "css", "html", "htm", "ico", "png", "jpg", "gif", "map", "wasm");
|
||||
String suffix = getSuffixFromUrl(uri);
|
||||
if (suffixs.contains(suffix)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
request.getSession().setAttribute("accessStartTime", System.currentTimeMillis());
|
||||
// 首先校验token
|
||||
boolean isTokenValid = checkToken(request, response);
|
||||
|
|
|
|||
|
|
@ -24,11 +24,14 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
|||
registry.addResourceHandler("swagger-ui.html")
|
||||
.addResourceLocations("classpath:/META-INF/resources/");
|
||||
|
||||
registry.addResourceHandler("index-plush.html")
|
||||
.addResourceLocations("classpath:/static/");
|
||||
|
||||
registry.addResourceHandler("/webjars/**")
|
||||
.addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
|
||||
registry.addResourceHandler("index.html")
|
||||
.addResourceLocations("classpath:/static/");
|
||||
.addResourceLocations("classpath:/static/model");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue