feat: 移除 FastDFS 模块

This commit is contained in:
xiongxiaoyang 2023-05-28 19:14:21 +08:00
parent 24c80e381c
commit 04d7b45334
10 changed files with 10 additions and 97 deletions

@ -50,8 +50,7 @@ novel-plus -- 父工程
| Spring Security | 安全框架
| Apache Shiro | 安全框架
| Redis | 缓存方案
| Aliyun OSS | 阿里云对象存储服务(图片存储方式之一一行配置即可切换)
| FastDFS | 开源轻量级分布式文件系统(图片存储方式之一一行配置即可切换)
| Aliyun OSS | 阿里云对象存储服务图片存储备选方案
| Lombok | 简化对象封装工具
| Docker | 应用容器引擎
| MySQL | 数据库服务

@ -164,12 +164,12 @@
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.10.5</version>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.10.5</version>
<version>2.6.1</version>
</dependency>
<!-- 添加redis支持-->

@ -39,19 +39,11 @@
<version>${commons-fileupload.version}</version>
</dependency>
<!--FastDfs-->
<dependency>
<groupId>com.github.tobato</groupId>
<artifactId>fastdfs-client</artifactId>
<version>${fastdfs-client.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>

@ -1,6 +1,5 @@
package com.java2nb.novel;
import com.github.tobato.fastdfs.FdfsClientConfig;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
@ -10,7 +9,6 @@ import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
@ -27,7 +25,6 @@ import java.net.InetAddress;
@EnableCaching
@ServletComponentScan
@MapperScan(basePackages = {"com.java2nb.novel.mapper"})
@Import(FdfsClientConfig.class)
@Slf4j
public class FrontNovelApplication {
@ -38,7 +35,9 @@ public class FrontNovelApplication {
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
log.info("项目启动啦,访问路径:{}", "http://" + InetAddress.getLocalHost().getHostAddress() + ":" + ctx.getEnvironment().getProperty("server.port"));
log.info("项目启动啦,访问路径:{}",
"http://" + InetAddress.getLocalHost().getHostAddress() + ":" + ctx.getEnvironment()
.getProperty("server.port"));
};
}

@ -1,60 +0,0 @@
package com.java2nb.novel.service.impl;
import com.github.tobato.fastdfs.domain.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import com.java2nb.novel.core.utils.Constants;
import com.java2nb.novel.core.utils.FileUtil;
import com.java2nb.novel.service.FileService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileInputStream;
/**
* @author 11797
*/
@Service
@RequiredArgsConstructor
@Slf4j
@ConditionalOnProperty(prefix = "pic.save", name = "storage", havingValue = "fastDfs")
public class FastDfsFileServiceImpl implements FileService {
private final FastFileStorageClient storageClient;
@Value("${fdfs.webUrl}")
private String webUrl;
@Override
public String transFile(String picSrc, String picSavePath) {
File file;
String filePath = FileUtil.network2Local(picSrc, picSavePath, Constants.LOCAL_PIC_PREFIX);
if (filePath.contains(Constants.LOCAL_PIC_PREFIX)) {
file = new File(picSavePath + filePath);
} else {
//默认图片不存储
return filePath;
}
try {
FileInputStream inputStream = new FileInputStream(file);
StorePath storePath = storageClient.uploadFile(inputStream, file.length(),
FilenameUtils.getExtension(file.getName()), null);
//这里额外加上LOCAL_PIC_PREFIX路径表明该图片是个人资源而不是爬虫爬取的网络资源不需要再次进行转换
// 实际访问时再通过nginx的rewite指令来重写路径去掉LOCAL_PIC_PREFIX
return webUrl+Constants.LOCAL_PIC_PREFIX+storePath.getFullPath();
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
//删除
file.delete();
}
return "/images/default.gif";
}
}

@ -6,7 +6,7 @@ spring:
pic:
save:
type: 1 #图片保存方式, 1不保存使用爬取的网络图片 2保存在自己的存储介质
storage: local #存储介质local本地OSS阿里云对象存储fastDfs分布式文件系统
storage: local #存储介质local本地OSS阿里云对象存储
path: /Users/xiongxiaoyang/java/ #图片保存路径

@ -1,16 +0,0 @@
#FastDfs的配置 ====================================
#读取inputsream阻塞时间
fdfs:
connect-timeout: 600
so-timeout: 1500
#tracker地址
trackerList: 127.0.0.1:22122
#缩略图配置
thumbImage:
height: 150
width: 150
#通过nginx 访问地址
webUrl: http://127.0.0.1/
#获取连接池最大数量
pool.max-total: 200

@ -1,6 +1,6 @@
spring:
profiles:
include: [common-prod]
include: [ common-prod ]
#静态文件路径配置
resources:
@ -18,7 +18,7 @@ templates:
pic:
save:
type: 2 #图片保存方式, 1不保存使用爬取的网络图片 2保存在自己的存储介质
storage: local #存储介质local本地OSS阿里云对象存储fastDfs分布式文件系统
storage: local #存储介质local本地OSS阿里云对象存储
path: /var/pic #图片保存路径

@ -4,7 +4,7 @@ server:
spring:
profiles:
active: dev
include: website,alipay,oss,fastdfs
include: website,alipay,oss
jwt:
secret: novel!#20191230

@ -44,7 +44,6 @@
<sharding.jdbc.version>3.1.0</sharding.jdbc.version>
<aliyun-sdk-oss.version>3.15.2</aliyun-sdk-oss.version>
<commons-fileupload.version>1.5</commons-fileupload.version>
<fastdfs-client.version>1.27.2</fastdfs-client.version>
<alipay-sdk-java.version>4.35.139.ALL</alipay-sdk-java.version>
<xxyopen.version>1.0.0</xxyopen.version>
</properties>