1. 基于 db 实现文件的存储

This commit is contained in:
YunaiV
2021-01-14 21:20:32 +08:00
parent f942b34d02
commit 629fa9b407
26 changed files with 351 additions and 168 deletions

View File

@ -0,0 +1,12 @@
package cn.iocoder.dashboard.framework.file.config;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* 文件 配置类
*/
@Configuration
@EnableConfigurationProperties(FileProperties.class)
public class FileConfiguration {
}

View File

@ -0,0 +1,23 @@
package cn.iocoder.dashboard.framework.file.config;
import cn.iocoder.dashboard.modules.system.controller.common.SysFileController;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
import javax.validation.constraints.NotNull;
@ConfigurationProperties(prefix = "yudao.file")
@Validated
@Data
public class FileProperties {
/**
* 对应 {@link SysFileController#}
*/
@NotNull(message = "基础文件路径不能为空")
private String basePath;
// TODO 七牛、等等
}

View File

@ -0,0 +1,16 @@
/**
* 文件的存储,推荐使用七牛、阿里云、华为云、腾讯云等文件服务
*
* 在不采用云服务的情况下,我们有几种技术选型:
* 方案 1. 使用自建的文件服务,例如说 minIO、FastDFS 等等
* 方案 2. 使用服务器的文件系统存储
* 方案 3. 使用数据库进行存储
*
* 如果考虑额外在搭建服务,推荐方案 1。
* 对于方案 2 来说,如果要实现文件存储的高可用,需要多台服务器之间做实时同步,可以基于 rsync + inotify 来做
* 对于方案 3 的话,实现起来最简单,但是数据库本身不适合存储海量的文件
*
* 综合考虑,暂时使用方案 3 的方式,比较适合这样一个 all in one 的项目。
* 随着文件的量级大了之后,还是推荐采用云服务。
*/
package cn.iocoder.dashboard.framework.file;

View File

@ -1,7 +1,6 @@
package cn.iocoder.dashboard.framework.security.config;
import cn.iocoder.dashboard.framework.security.core.filter.JwtAuthenticationTokenFilter;
import cn.iocoder.dashboard.framework.security.core.handler.AuthenticationEntryPointImpl;
import cn.iocoder.dashboard.framework.security.core.handler.LogoutSuccessHandlerImpl;
import cn.iocoder.dashboard.framework.web.config.WebProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@ -19,8 +18,6 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.logout.LogoutFilter;
import org.springframework.web.filter.CorsFilter;
import javax.annotation.Resource;
@ -126,12 +123,13 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
// 登陆的接口,可匿名访问
.antMatchers(webProperties.getApiPrefix() + "/login").anonymous()
// 通用的接口,可匿名访问
.antMatchers( webProperties.getApiPrefix() + "/captcha/**").anonymous()
.antMatchers( webProperties.getApiPrefix() + "/system/captcha/**").anonymous()
// TODO
.antMatchers(HttpMethod.GET, "/*.html", "/**/*.html", "/**/*.css", "/**/*.js").permitAll()
.antMatchers("/profile/**").anonymous()
.antMatchers("/common/download**").anonymous()
.antMatchers("/common/download/resource**").anonymous()
// 文件的获取接口,可匿名访问
.antMatchers(webProperties.getApiPrefix() + "/system/file/get/**").anonymous()
// TODO
.antMatchers("/swagger-ui.html").anonymous()
.antMatchers("/swagger-resources/**").anonymous()
.antMatchers("/webjars/**").anonymous()