云文件管理系统上传组件优化

This commit is contained in:
2026-04-02 12:52:40 +08:00
parent abbc0781be
commit 5053d396f8
6 changed files with 73 additions and 9 deletions

View File

@@ -50,6 +50,13 @@ public class SecurityConfig {
.requestMatchers("/files/avatar/**").permitAll()
.requestMatchers("/api/files/avatar/**").permitAll()
.requestMatchers("/api/messages/file/**").permitAll()
.requestMatchers("/webapp/**").permitAll()
.requestMatchers("/assets/**").permitAll()
.requestMatchers("/login", "/register").permitAll()
.requestMatchers("/").permitAll()
.requestMatchers("/desktop").permitAll()
.requestMatchers("/desktop/**").permitAll()
.requestMatchers("/favicon.ico").permitAll()
.anyRequest().authenticated()
)
.exceptionHandling(exception -> exception

View File

@@ -2,11 +2,13 @@ package com.filesystem.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.nio.file.Paths;
import java.util.concurrent.TimeUnit;
@Configuration
public class WebConfig implements WebMvcConfigurer {
@@ -24,7 +26,20 @@ public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// 上传文件目录
registry.addResourceHandler("/uploads/**")
.addResourceLocations("file:" + Paths.get(uploadDir).toAbsolutePath() + "/");
// 前端静态资源webapp 目录)
registry.addResourceHandler("/webapp/**")
.addResourceLocations("classpath:/webapp/")
.setCacheControl(CacheControl.noCache().mustRevalidate());
registry.addResourceHandler("/assets/**")
.addResourceLocations("classpath:/webapp/assets/")
.setCacheControl(CacheControl.noCache().mustRevalidate());
registry.addResourceHandler("/favicon.ico")
.addResourceLocations("classpath:/webapp/");
}
}

View File

@@ -0,0 +1,19 @@
package com.filesystem.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class IndexController {
@GetMapping({"/", "/login", "/register"})
public String forward() {
return "forward:/webapp/index.html";
}
// 捕获所有前端路由,返回 index.html 让 Vue Router 处理
@GetMapping("/desktop/**")
public String desktop() {
return "forward:/webapp/index.html";
}
}

View File

@@ -32,7 +32,15 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
new AntPathRequestMatcher("/api/files/test"),
new AntPathRequestMatcher("/ws/**"),
new AntPathRequestMatcher("/api/files/avatar/**"),
new AntPathRequestMatcher("/api/messages/file/**")
new AntPathRequestMatcher("/api/messages/file/**"),
new AntPathRequestMatcher("/webapp/**"),
new AntPathRequestMatcher("/assets/**"),
new AntPathRequestMatcher("/favicon.ico"),
new AntPathRequestMatcher("/login"),
new AntPathRequestMatcher("/register"),
new AntPathRequestMatcher("/"),
new AntPathRequestMatcher("/desktop"),
new AntPathRequestMatcher("/desktop/**")
);
@Override