判断是否重复上传

master
tangwenkang 2023-11-06 20:59:46 +08:00
parent 8e446d19e9
commit b8e3169977
2 changed files with 12 additions and 1 deletions

View File

@ -151,7 +151,10 @@
<version>3.16.0</version> <version>3.16.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
</dependencies> </dependencies>

View File

@ -30,6 +30,7 @@ import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import com.health.video.server.utils.DogeUtil; import com.health.video.server.utils.DogeUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -58,6 +59,8 @@ public class VideoServiceImpl implements VideoService {
private RedissonClient redissonClient; private RedissonClient redissonClient;
@Autowired @Autowired
private RemoteWalletService remoteWalletService; private RemoteWalletService remoteWalletService;
@Autowired
private RedisTemplate<String,String> redisTemplate;
/** /**
* *
@ -253,6 +256,11 @@ public class VideoServiceImpl implements VideoService {
File localFile = new File(filePath); File localFile = new File(filePath);
// 计算文件的 SHA-256 哈希值比MD5加密更安全 // 计算文件的 SHA-256 哈希值比MD5加密更安全
String fileMD5 = calculateFileSHA256(localFile); String fileMD5 = calculateFileSHA256(localFile);
// 把文件存入redis记录30秒 30秒内不能重复上传视频
redisTemplate.opsForValue().set(fileMD5, String.valueOf(localFile),30,TimeUnit.SECONDS);
if(redisTemplate.hasKey(fileMD5)){
throw new RuntimeException("请不要重复上传视频!");
}
System.out.println("SHA-256加密内容为"+fileMD5); System.out.println("SHA-256加密内容为"+fileMD5);
// 检查目录是否存在,如果不存在则创建 // 检查目录是否存在,如果不存在则创建
File localDirectory = localFile.getParentFile(); File localDirectory = localFile.getParentFile();