From 93eab6b8a82bcc6cf754198455738646dc638d64 Mon Sep 17 00:00:00 2001 From: yutou Date: Tue, 22 Jun 2021 15:39:53 +0800 Subject: [PATCH] =?UTF-8?q?OSS=E6=96=B0=E5=A2=9E=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E5=AF=B9=E6=AF=94=EF=BC=8C=E7=BA=BF=E4=B8=8AAPI=E5=BE=97?= =?UTF-8?q?=E8=A6=81=E9=92=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/yutou/nas/NasApplication.java | 2 +- src/main/java/com/yutou/nas/utils/OSSManager.java | 10 +++++++++- src/main/java/com/yutou/nas/utils/RedisTools.java | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/yutou/nas/NasApplication.java b/src/main/java/com/yutou/nas/NasApplication.java index b73ffcd..12579eb 100644 --- a/src/main/java/com/yutou/nas/NasApplication.java +++ b/src/main/java/com/yutou/nas/NasApplication.java @@ -12,7 +12,7 @@ import org.springframework.context.annotation.Import; @Import(BTDownloadManager.class) @SpringBootApplication public class NasApplication { - public static final String version="1.1.5.1"; + public static final String version="1.1.6"; public static void main(String[] args) { SpringApplication.run(NasApplication.class, args); AppData.defaultMusicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir"); diff --git a/src/main/java/com/yutou/nas/utils/OSSManager.java b/src/main/java/com/yutou/nas/utils/OSSManager.java index 915ec57..0d2e442 100644 --- a/src/main/java/com/yutou/nas/utils/OSSManager.java +++ b/src/main/java/com/yutou/nas/utils/OSSManager.java @@ -78,11 +78,18 @@ public class OSSManager { uploadPath = uploadPath.substring(1); } String md5 = BinaryUtil.toBase64String(Tools.getFileMD5Byte(file)); + String redisMd5=RedisTools.get(file.getAbsolutePath(),RedisTools.DATABASES_ALI_OSS); + if(!StringUtils.isEmpty(redisMd5)){ + if(redisMd5.equals(md5)){ + Log.i("OSS", "[本地]文件已存在:" + file.getName()); + continue; + } + } if (isExist(client, ConfigTools.load(ConfigTools.CONFIG, type, String.class), uploadPath, md5)) { Log.i("OSS", "文件已存在:" + file.getName()); + RedisTools.set(RedisTools.DATABASES_ALI_OSS,file.getAbsolutePath(),md5); continue; } - Log.i("OSS", "即将上传:" + file.getName()); //client.putObject(ConfigTools.load(ConfigTools.CONFIG,type,String.class), uploadPath, file); int limitSpeed = 1024 * 1024 * 8; ObjectMetadata metadata = new ObjectMetadata(); @@ -113,6 +120,7 @@ public class OSSManager { });*/ client.putObject(request); Log.i("OSS", file.getName() + "已上传"); + RedisTools.set(RedisTools.DATABASES_ALI_OSS,file.getAbsolutePath(),md5); } } catch (Exception e) { diff --git a/src/main/java/com/yutou/nas/utils/RedisTools.java b/src/main/java/com/yutou/nas/utils/RedisTools.java index fecff0d..4771b2e 100644 --- a/src/main/java/com/yutou/nas/utils/RedisTools.java +++ b/src/main/java/com/yutou/nas/utils/RedisTools.java @@ -19,6 +19,7 @@ public class RedisTools { private static String host; private static int port; public static int TOKEN_TIMEOUT_DEFAULT = 360; + public final static int DATABASES_ALI_OSS=4; private RedisTools() {