From e781718db8acf82a99b8b4870f7f3214c30a2dbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=B3=E5=85=89=E5=BC=80=E6=9C=97=E5=A4=A7=E7=94=B7?= =?UTF-8?q?=E5=AD=A9?= <12163695+jiangwentianya@user.noreply.gitee.com> Date: Wed, 28 Feb 2024 17:46:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=9B=BE=E7=89=87=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E5=AE=89=E5=85=A8=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../strategy/impl/LocalUploadStrategyImpl.java | 14 ++++++++++++++ .../src/main/resources/application-prod.yml | 2 ++ 2 files changed, 16 insertions(+) diff --git a/aurora-springboot/src/main/java/com/aurora/strategy/impl/LocalUploadStrategyImpl.java b/aurora-springboot/src/main/java/com/aurora/strategy/impl/LocalUploadStrategyImpl.java index 8561f35f..6c197f87 100644 --- a/aurora-springboot/src/main/java/com/aurora/strategy/impl/LocalUploadStrategyImpl.java +++ b/aurora-springboot/src/main/java/com/aurora/strategy/impl/LocalUploadStrategyImpl.java @@ -17,6 +17,12 @@ public class LocalUploadStrategyImpl extends AbstractUploadStrategyImpl { @Value("${upload.local.baseUrl}") private String baseUrl; + @Value("${upload.local.username}") + private String username; + + @Value("${upload.local.password}") + private String password; + @Autowired private LocalProperties localProperties; private String imagePath; @@ -33,9 +39,17 @@ public Boolean exists(String filePath) { // 检查文件是否存在 return new File(imagePath + filePath).exists(); } + private boolean validateCredentials() { + // 在这里实现账号密码验证逻辑,例如: + return "admin".equals(username) && "secretpassword".equals(password); + } @Override public void upload(String path, String fileName, InputStream inputStream) throws IOException { + // 验证账号密码 + if (!validateCredentials()) { + throw new RuntimeException("无效的凭据"); + } // 重命名文件,添加自定义前缀 // String customFileName = "aurora_" + fileName; String customFileName = fileName; diff --git a/aurora-springboot/src/main/resources/application-prod.yml b/aurora-springboot/src/main/resources/application-prod.yml index e9d983ef..a235e72e 100644 --- a/aurora-springboot/src/main/resources/application-prod.yml +++ b/aurora-springboot/src/main/resources/application-prod.yml @@ -104,6 +104,8 @@ upload: secretKey: 密码 bucketName: 桶的名称 local: + username: admin + password: secretpassword imagePath: 'C:/code/images/' baseUrl: http://localhost:8080/ # baseUrl: https://local.gysy.ltd/