1. 附件加密上传下载

This commit is contained in:
chenbowen
2025-07-22 19:36:46 +08:00
parent d17fa356ba
commit 8ab6cb4bae
26 changed files with 411 additions and 94 deletions

View File

@@ -14,6 +14,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.data.redis.core.StringRedisTemplate;
import java.time.LocalDateTime;
import java.util.concurrent.atomic.AtomicReference;
@@ -32,6 +33,9 @@ public class FileServiceImplTest extends BaseDbUnitTest {
@Resource
private FileServiceImpl fileService;
@MockBean
private StringRedisTemplate stringRedisTemplate;
@Resource
private FileMapper fileMapper;
@@ -99,7 +103,7 @@ public class FileServiceImplTest extends BaseDbUnitTest {
}), eq(type))).thenReturn(url);
when(client.getId()).thenReturn(10L);
// 调用
String result = fileService.createFile(content, name, directory, type);
String result = fileService.createFile(content, name, directory, type, false);
// 断言
assertEquals(result, url);
// 校验数据
@@ -131,7 +135,7 @@ public class FileServiceImplTest extends BaseDbUnitTest {
}), eq(type))).thenReturn(url);
when(client.getId()).thenReturn(10L);
// 调用
String result = fileService.createFile(content, null, null, null);
String result = fileService.createFile(content, null, null, null, false);
// 断言
assertEquals(result, url);
// 校验数据
@@ -330,11 +334,11 @@ public class FileServiceImplTest extends BaseDbUnitTest {
when(client.getId()).thenReturn(10L);
// 首次上传
String result1 = fileService.createFile(content, name, directory, type);
String result1 = fileService.createFile(content, name, directory, type, false);
assertEquals(result1, url);
// 再次上传同样的内容,应该复用已存在的文件
String result2 = fileService.createFile(content, name, directory, type);
String result2 = fileService.createFile(content, name, directory, type, false);
assertEquals(result2, url);
// 校验数据

View File

@@ -50,3 +50,5 @@ mybatis-plus:
yudao:
info:
base-package: cn.iocoder.yudao.module.infra
AES:
key: XDV71a+xqStEA3WH

View File

@@ -46,6 +46,7 @@ CREATE TABLE IF NOT EXISTS "infra_file" (
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint not null default '0',
"hash" varchar(64) DEFAULT NULL COMMENT '文件哈希值SHA-256',
"aes_iv" varchar(64) DEFAULT NULL COMMENT '文件哈希值SHA-256',
PRIMARY KEY ("id")
) COMMENT '文件表';