From c157d6bfeab3bc235bb7e091a7379a11010e71e2 Mon Sep 17 00:00:00 2001 From: none Date: Tue, 30 May 2023 08:10:45 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E4=BC=98=E5=8C=96Minio=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E7=9A=84url=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/xyz/playedu/api/service/impl/MinioServiceImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/xyz/playedu/api/service/impl/MinioServiceImpl.java b/src/main/java/xyz/playedu/api/service/impl/MinioServiceImpl.java index 547b35d..bfa5619 100644 --- a/src/main/java/xyz/playedu/api/service/impl/MinioServiceImpl.java +++ b/src/main/java/xyz/playedu/api/service/impl/MinioServiceImpl.java @@ -52,7 +52,11 @@ public class MinioServiceImpl implements MinioService { @Override public String url(String path) { - return c.getDomain() + c.getBucket() + "/" + path; + return c.getDomain() + + (c.getDomain().endsWith("/") ? "" : "/") + + c.getBucket() + + "/" + + path; } @Override From ac809ff3bb463aa6d62069afa1dea7090621e57a Mon Sep 17 00:00:00 2001 From: none Date: Tue, 30 May 2023 15:47:18 +0800 Subject: [PATCH 2/7] docker-base --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index beb9476..7656851 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM openjdk:17 as builder +FROM eclipse-temurin:17 as builder WORKDIR /app @@ -6,7 +6,7 @@ COPY . /app RUN /app/docker-build.sh -FROM openjdk:17 +FROM eclipse-temurin:17 WORKDIR /app From 2ad4105ea7a9a96abe49756e65a403aa801b44cd Mon Sep 17 00:00:00 2001 From: none Date: Tue, 30 May 2023 16:04:38 +0800 Subject: [PATCH 3/7] =?UTF-8?q?added:=20=E7=A6=81=E6=AD=A2=E6=8B=96?= =?UTF-8?q?=E6=8B=BD=E6=92=AD=E6=94=BE=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/xyz/playedu/api/checks/AppConfigCheck.java | 9 +++++++++ .../api/controller/frontend/SystemController.java | 1 + 2 files changed, 10 insertions(+) diff --git a/src/main/java/xyz/playedu/api/checks/AppConfigCheck.java b/src/main/java/xyz/playedu/api/checks/AppConfigCheck.java index c95d84a..d5986a8 100644 --- a/src/main/java/xyz/playedu/api/checks/AppConfigCheck.java +++ b/src/main/java/xyz/playedu/api/checks/AppConfigCheck.java @@ -154,6 +154,15 @@ public class AppConfigCheck implements ApplicationRunner { setKeyValue("1"); } }, + new AppConfig() { + { + setName("禁止拖拽播放"); + setSort(60); + setFieldType(BackendConstant.APP_CONFIG_FIELD_TYPE_SWITCH); + setKeyName("player.disabled_drag"); + setKeyValue("0"); + } + }, }); put( "学员配置", diff --git a/src/main/java/xyz/playedu/api/controller/frontend/SystemController.java b/src/main/java/xyz/playedu/api/controller/frontend/SystemController.java index 5e20852..96e5694 100644 --- a/src/main/java/xyz/playedu/api/controller/frontend/SystemController.java +++ b/src/main/java/xyz/playedu/api/controller/frontend/SystemController.java @@ -61,6 +61,7 @@ public class SystemController { data.put("player-bullet-secret-text", configs.get("player.bullet_secret_text")); data.put("player-bullet-secret-color", configs.get("player.bullet_secret_color")); data.put("player-bullet-secret-opacity", configs.get("player.bullet_secret_opacity")); + data.put("player-disabled-drag", configs.get("player.disabled_drag")); return JsonResponse.data(data); } From 43a80c26de86b27fbb085027963184f4b3af6948 Mon Sep 17 00:00:00 2001 From: none Date: Tue, 30 May 2023 16:18:01 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AD=A6=E5=91=98?= =?UTF-8?q?=E5=88=A0=E9=99=A4-=E5=85=B3=E8=81=94=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9A=84=E6=B8=85=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/listener/UserDestroyListener.java | 19 +++++++++++++++++-- .../service/UserCourseHourRecordService.java | 2 ++ .../api/service/UserCourseRecordService.java | 2 ++ .../UserLearnDurationRecordService.java | 2 ++ .../UserLearnDurationStatsService.java | 2 ++ .../api/service/UserLoginRecordService.java | 4 ++-- .../impl/UserCourseHourRecordServiceImpl.java | 5 +++++ .../impl/UserCourseRecordServiceImpl.java | 5 +++++ .../UserLearnDurationRecordServiceImpl.java | 5 +++++ .../UserLearnDurationStatsServiceImpl.java | 5 +++++ .../impl/UserLoginRecordServiceImpl.java | 13 +++++-------- 11 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/main/java/xyz/playedu/api/listener/UserDestroyListener.java b/src/main/java/xyz/playedu/api/listener/UserDestroyListener.java index 59cb42e..483bd2b 100644 --- a/src/main/java/xyz/playedu/api/listener/UserDestroyListener.java +++ b/src/main/java/xyz/playedu/api/listener/UserDestroyListener.java @@ -22,7 +22,7 @@ import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; import xyz.playedu.api.event.UserDestroyEvent; -import xyz.playedu.api.service.UserService; +import xyz.playedu.api.service.*; /** * @Author 杭州白书科技有限公司 @@ -35,8 +35,23 @@ public class UserDestroyListener { @Autowired private UserService userService; + @Autowired private UserCourseHourRecordService userCourseHourRecordService; + + @Autowired private UserCourseRecordService userCourseRecordService; + + @Autowired private UserLearnDurationRecordService userLearnDurationRecordService; + + @Autowired private UserLearnDurationStatsService userLearnDurationStatsService; + + @Autowired private UserLoginRecordService userLoginRecordService; + @EventListener - public void updateLoginInfo(UserDestroyEvent event) { + public void remoteRelation(UserDestroyEvent event) { userService.removeRelateDepartmentsByUserId(event.getUserId()); + userCourseHourRecordService.remove(event.getUserId()); + userCourseRecordService.destroy(event.getUserId()); + userLearnDurationRecordService.remove(event.getUserId()); + userLearnDurationStatsService.remove(event.getUserId()); + userLoginRecordService.remove(event.getUserId()); } } diff --git a/src/main/java/xyz/playedu/api/service/UserCourseHourRecordService.java b/src/main/java/xyz/playedu/api/service/UserCourseHourRecordService.java index cf84b71..23998de 100644 --- a/src/main/java/xyz/playedu/api/service/UserCourseHourRecordService.java +++ b/src/main/java/xyz/playedu/api/service/UserCourseHourRecordService.java @@ -51,6 +51,8 @@ public interface UserCourseHourRecordService extends IService getUserCourseHourCount( diff --git a/src/main/java/xyz/playedu/api/service/UserCourseRecordService.java b/src/main/java/xyz/playedu/api/service/UserCourseRecordService.java index ed2e702..0f40a7f 100644 --- a/src/main/java/xyz/playedu/api/service/UserCourseRecordService.java +++ b/src/main/java/xyz/playedu/api/service/UserCourseRecordService.java @@ -45,6 +45,8 @@ public interface UserCourseRecordService extends IService { void destroy(Integer userId, Integer courseId); + void destroy(Integer userId); + void removeByCourseId(Integer courseId); List chunks(List ids, List fields); diff --git a/src/main/java/xyz/playedu/api/service/UserLearnDurationRecordService.java b/src/main/java/xyz/playedu/api/service/UserLearnDurationRecordService.java index dfb43e2..79ce7bf 100644 --- a/src/main/java/xyz/playedu/api/service/UserLearnDurationRecordService.java +++ b/src/main/java/xyz/playedu/api/service/UserLearnDurationRecordService.java @@ -26,4 +26,6 @@ import xyz.playedu.api.domain.UserLearnDurationRecord; */ public interface UserLearnDurationRecordService extends IService { void store(Integer userId, Integer courseId, Integer hourId, Long startTime, Long endTime); + + void remove(Integer userId); } diff --git a/src/main/java/xyz/playedu/api/service/UserLearnDurationStatsService.java b/src/main/java/xyz/playedu/api/service/UserLearnDurationStatsService.java index f5852c3..1f7fd85 100644 --- a/src/main/java/xyz/playedu/api/service/UserLearnDurationStatsService.java +++ b/src/main/java/xyz/playedu/api/service/UserLearnDurationStatsService.java @@ -40,4 +40,6 @@ public interface UserLearnDurationStatsService extends IService dateBetween(Integer userId, String startAt, String endAt); + + void remove(Integer userId); } diff --git a/src/main/java/xyz/playedu/api/service/UserLoginRecordService.java b/src/main/java/xyz/playedu/api/service/UserLoginRecordService.java index 0db4707..0b94bfd 100644 --- a/src/main/java/xyz/playedu/api/service/UserLoginRecordService.java +++ b/src/main/java/xyz/playedu/api/service/UserLoginRecordService.java @@ -35,7 +35,7 @@ public interface UserLoginRecordService extends IService { String browserVersion, String os); - void saveIpArea(Integer id, String area); - void logout(Integer userid, String jti); + + void remove(Integer userId); } diff --git a/src/main/java/xyz/playedu/api/service/impl/UserCourseHourRecordServiceImpl.java b/src/main/java/xyz/playedu/api/service/impl/UserCourseHourRecordServiceImpl.java index 112953f..5965c46 100644 --- a/src/main/java/xyz/playedu/api/service/impl/UserCourseHourRecordServiceImpl.java +++ b/src/main/java/xyz/playedu/api/service/impl/UserCourseHourRecordServiceImpl.java @@ -151,6 +151,11 @@ public class UserCourseHourRecordServiceImpl remove(query().getWrapper().eq("user_id", userId).eq("course_id", courseId)); } + @Override + public void remove(Integer userId) { + remove(query().getWrapper().eq("user_id", userId)); + } + @Override public PaginationResult paginate( int page, int size, UserCourseHourRecordPaginateFilter filter) { diff --git a/src/main/java/xyz/playedu/api/service/impl/UserCourseRecordServiceImpl.java b/src/main/java/xyz/playedu/api/service/impl/UserCourseRecordServiceImpl.java index 5c892b1..53d8007 100644 --- a/src/main/java/xyz/playedu/api/service/impl/UserCourseRecordServiceImpl.java +++ b/src/main/java/xyz/playedu/api/service/impl/UserCourseRecordServiceImpl.java @@ -138,6 +138,11 @@ public class UserCourseRecordServiceImpl remove(query().getWrapper().in("user_id", userId).eq("course_id", courseId)); } + @Override + public void destroy(Integer userId) { + remove(query().getWrapper().in("user_id", userId)); + } + @Override public void decrease(Integer userId, Integer courseId, int count) { UserCourseRecord record = find(userId, courseId); diff --git a/src/main/java/xyz/playedu/api/service/impl/UserLearnDurationRecordServiceImpl.java b/src/main/java/xyz/playedu/api/service/impl/UserLearnDurationRecordServiceImpl.java index ed4eb47..db83676 100644 --- a/src/main/java/xyz/playedu/api/service/impl/UserLearnDurationRecordServiceImpl.java +++ b/src/main/java/xyz/playedu/api/service/impl/UserLearnDurationRecordServiceImpl.java @@ -57,4 +57,9 @@ public class UserLearnDurationRecordServiceImpl save(record); } + + @Override + public void remove(Integer userId) { + remove(query().getWrapper().eq("user_id", userId)); + } } diff --git a/src/main/java/xyz/playedu/api/service/impl/UserLearnDurationStatsServiceImpl.java b/src/main/java/xyz/playedu/api/service/impl/UserLearnDurationStatsServiceImpl.java index 8b0b716..ebfc19e 100644 --- a/src/main/java/xyz/playedu/api/service/impl/UserLearnDurationStatsServiceImpl.java +++ b/src/main/java/xyz/playedu/api/service/impl/UserLearnDurationStatsServiceImpl.java @@ -114,4 +114,9 @@ public class UserLearnDurationStatsServiceImpl return list( query().getWrapper().eq("user_id", userId).between("created_date", startAt, endAt)); } + + @Override + public void remove(Integer userId) { + remove(query().getWrapper().eq("user_id", userId)); + } } diff --git a/src/main/java/xyz/playedu/api/service/impl/UserLoginRecordServiceImpl.java b/src/main/java/xyz/playedu/api/service/impl/UserLoginRecordServiceImpl.java index 10f35cc..60b714d 100644 --- a/src/main/java/xyz/playedu/api/service/impl/UserLoginRecordServiceImpl.java +++ b/src/main/java/xyz/playedu/api/service/impl/UserLoginRecordServiceImpl.java @@ -54,14 +54,6 @@ public class UserLoginRecordServiceImpl extends ServiceImpl Date: Wed, 31 May 2023 09:37:09 +0800 Subject: [PATCH 5/7] =?UTF-8?q?minio=E9=85=8D=E7=BD=AE=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../playedu/api/checks/AppConfigCheck.java | 49 ++++++++++ .../xyz/playedu/api/config/MinioConfig.java | 70 -------------- .../xyz/playedu/api/constant/CConfig.java | 6 ++ .../controller/backend/UploadController.java | 5 - .../playedu/api/service/AppConfigService.java | 8 +- .../service/impl/AppConfigServiceImpl.java | 14 +++ .../api/service/impl/MinioServiceImpl.java | 94 +++++++++++++------ .../playedu/api/types/config/MinioConfig.java | 27 ++++++ src/main/resources/application.yml | 8 -- 9 files changed, 164 insertions(+), 117 deletions(-) delete mode 100644 src/main/java/xyz/playedu/api/config/MinioConfig.java create mode 100644 src/main/java/xyz/playedu/api/types/config/MinioConfig.java diff --git a/src/main/java/xyz/playedu/api/checks/AppConfigCheck.java b/src/main/java/xyz/playedu/api/checks/AppConfigCheck.java index d5986a8..f17b2ae 100644 --- a/src/main/java/xyz/playedu/api/checks/AppConfigCheck.java +++ b/src/main/java/xyz/playedu/api/checks/AppConfigCheck.java @@ -177,6 +177,55 @@ public class AppConfigCheck implements ApplicationRunner { } }, }); + put( + "MinIO", + new AppConfig[] { + new AppConfig() { + { + setName("AccessKey"); + setSort(10); + setFieldType(BackendConstant.APP_CONFIG_FIELD_TYPE_TEXT); + setKeyName(CConfig.MINIO_ACCESS_KEY); + setKeyValue(""); + } + }, + new AppConfig() { + { + setName("SecretKey"); + setSort(20); + setFieldType(BackendConstant.APP_CONFIG_FIELD_TYPE_TEXT); + setKeyName(CConfig.MINIO_SECRET_KEY); + setKeyValue(""); + } + }, + new AppConfig() { + { + setName("Bucket"); + setSort(30); + setFieldType(BackendConstant.APP_CONFIG_FIELD_TYPE_TEXT); + setKeyName(CConfig.MINIO_BUCKET); + setKeyValue(""); + } + }, + new AppConfig() { + { + setName("Endpoint"); + setSort(40); + setFieldType(BackendConstant.APP_CONFIG_FIELD_TYPE_TEXT); + setKeyName(CConfig.MINIO_ENDPOINT); + setKeyValue(""); + } + }, + new AppConfig() { + { + setName("Domain"); + setSort(50); + setFieldType(BackendConstant.APP_CONFIG_FIELD_TYPE_TEXT); + setKeyName(CConfig.MINIO_DOMAIN); + setKeyValue(""); + } + }, + }); } }; diff --git a/src/main/java/xyz/playedu/api/config/MinioConfig.java b/src/main/java/xyz/playedu/api/config/MinioConfig.java deleted file mode 100644 index 7e2b56e..0000000 --- a/src/main/java/xyz/playedu/api/config/MinioConfig.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2023 杭州白书科技有限公司 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package xyz.playedu.api.config; - -import io.minio.MinioAsyncClient; -import io.minio.MinioClient; - -import lombok.Data; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import xyz.playedu.api.vendor.PlayEduMinioClient; - -/** - * @Author 杭州白书科技有限公司 - * - * @create 2023/2/28 16:38 - */ -@Data -@Configuration -public class MinioConfig { - - @Value("${minio.domain}") - private String domain; - - @Value("${minio.bucket}") - private String bucket; - - @Value("${minio.access-key}") - private String accessKey; - - @Value("${minio.secret-key}") - private String secretKey; - - @Value("${minio.end-point}") - private String endPoint; - - @Bean - public MinioClient getMinioClient() { - return MinioClient.builder() - .endpoint(this.endPoint) - .credentials(this.accessKey, this.secretKey) - .build(); - } - - @Bean - public PlayEduMinioClient getPlayEduMinioClient() { - MinioAsyncClient client = - PlayEduMinioClient.builder() - .endpoint(this.endPoint) - .credentials(this.accessKey, this.secretKey) - .build(); - return new PlayEduMinioClient(client); - } -} diff --git a/src/main/java/xyz/playedu/api/constant/CConfig.java b/src/main/java/xyz/playedu/api/constant/CConfig.java index c499d55..95c0498 100644 --- a/src/main/java/xyz/playedu/api/constant/CConfig.java +++ b/src/main/java/xyz/playedu/api/constant/CConfig.java @@ -29,4 +29,10 @@ public class CConfig { public static final String SYSTEM_H5_URL = "system.h5_url"; public static final String MEMBER_DEFAULT_AVATAR = "member.default_avatar"; + + public static final String MINIO_ACCESS_KEY = "minio.access_key"; + public static final String MINIO_SECRET_KEY = "minio.secret_key"; + public static final String MINIO_BUCKET = "minio.bucket"; + public static final String MINIO_ENDPOINT = "minio.endpoint"; + public static final String MINIO_DOMAIN = "minio.domain"; } diff --git a/src/main/java/xyz/playedu/api/controller/backend/UploadController.java b/src/main/java/xyz/playedu/api/controller/backend/UploadController.java index 1422886..3735c28 100644 --- a/src/main/java/xyz/playedu/api/controller/backend/UploadController.java +++ b/src/main/java/xyz/playedu/api/controller/backend/UploadController.java @@ -36,11 +36,6 @@ import xyz.playedu.api.util.HelperUtil; import java.util.HashMap; -/** - * @Author 杭州白书科技有限公司 - * - * @create 2023/2/28 16:26 - */ @RestController @Slf4j @RequestMapping("/backend/v1/upload") diff --git a/src/main/java/xyz/playedu/api/service/AppConfigService.java b/src/main/java/xyz/playedu/api/service/AppConfigService.java index 7916d22..3cb7ce1 100644 --- a/src/main/java/xyz/playedu/api/service/AppConfigService.java +++ b/src/main/java/xyz/playedu/api/service/AppConfigService.java @@ -18,16 +18,12 @@ package xyz.playedu.api.service; import com.baomidou.mybatisplus.extension.service.IService; import xyz.playedu.api.domain.AppConfig; +import xyz.playedu.api.types.config.MinioConfig; import java.util.HashMap; import java.util.List; import java.util.Map; -/** - * @author tengteng - * @description 针对表【app_config】的数据库操作Service - * @createDate 2023-03-09 11:13:33 - */ public interface AppConfigService extends IService { Map allKeys(); @@ -37,4 +33,6 @@ public interface AppConfigService extends IService { void saveFromMap(HashMap data); Map keyValues(); + + MinioConfig getMinioConfig(); } diff --git a/src/main/java/xyz/playedu/api/service/impl/AppConfigServiceImpl.java b/src/main/java/xyz/playedu/api/service/impl/AppConfigServiceImpl.java index ee51a5b..aa0320f 100644 --- a/src/main/java/xyz/playedu/api/service/impl/AppConfigServiceImpl.java +++ b/src/main/java/xyz/playedu/api/service/impl/AppConfigServiceImpl.java @@ -19,9 +19,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; +import xyz.playedu.api.constant.CConfig; import xyz.playedu.api.domain.AppConfig; import xyz.playedu.api.mapper.AppConfigMapper; import xyz.playedu.api.service.AppConfigService; +import xyz.playedu.api.types.config.MinioConfig; import java.util.ArrayList; import java.util.HashMap; @@ -89,4 +91,16 @@ public class AppConfigServiceImpl extends ServiceImpl config = keyValues(); + minioConfig.setAccessKey(config.get(CConfig.MINIO_ACCESS_KEY)); + minioConfig.setSecretKey(config.get(CConfig.MINIO_SECRET_KEY)); + minioConfig.setBucket(config.get(CConfig.MINIO_BUCKET)); + minioConfig.setEndpoint(config.get(CConfig.MINIO_ENDPOINT)); + minioConfig.setDomain(config.get(CConfig.MINIO_DOMAIN)); + return minioConfig; + } } diff --git a/src/main/java/xyz/playedu/api/service/impl/MinioServiceImpl.java b/src/main/java/xyz/playedu/api/service/impl/MinioServiceImpl.java index bfa5619..c42b9a0 100644 --- a/src/main/java/xyz/playedu/api/service/impl/MinioServiceImpl.java +++ b/src/main/java/xyz/playedu/api/service/impl/MinioServiceImpl.java @@ -15,10 +15,7 @@ */ package xyz.playedu.api.service.impl; -import io.minio.GetPresignedObjectUrlArgs; -import io.minio.MinioClient; -import io.minio.PutObjectArgs; -import io.minio.RemoveObjectArgs; +import io.minio.*; import io.minio.http.Method; import lombok.SneakyThrows; @@ -27,8 +24,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; -import xyz.playedu.api.config.MinioConfig; +import xyz.playedu.api.exception.ServiceException; +import xyz.playedu.api.service.AppConfigService; import xyz.playedu.api.service.MinioService; +import xyz.playedu.api.types.config.MinioConfig; import xyz.playedu.api.vendor.PlayEduMinioClient; import java.io.ByteArrayInputStream; @@ -36,22 +35,57 @@ import java.io.InputStream; import java.util.HashMap; import java.util.Map; -/** - * @Author 杭州白书科技有限公司 - * - * @create 2023/3/7 13:29 - */ @Service public class MinioServiceImpl implements MinioService { - @Autowired private MinioConfig c; + private MinioConfig minioConfig = null; - @Autowired private MinioClient client; + @Autowired private AppConfigService appConfigService; - @Autowired private PlayEduMinioClient playEduMinioClient; + @SneakyThrows + private MinioConfig getMinioConfig() { + if (minioConfig == null) { + minioConfig = appConfigService.getMinioConfig(); + if (minioConfig.getAccessKey().isBlank() + || minioConfig.getSecretKey().isBlank() + || minioConfig.getBucket().isBlank() + || minioConfig.getDomain().isBlank() + || minioConfig.getEndpoint().isBlank()) { + throw new ServiceException("MinIO服务未配置"); + } + } + return minioConfig; + } + + private String bucket() { + return getMinioConfig().getBucket(); + } + + public MinioClient getMinioClient() { + MinioConfig c = getMinioConfig(); + + return MinioClient.builder() + .endpoint(c.getEndpoint()) + .credentials(c.getAccessKey(), c.getSecretKey()) + .build(); + } + + public PlayEduMinioClient getPlayEduMinioClient() { + MinioConfig c = getMinioConfig(); + + MinioAsyncClient client = + PlayEduMinioClient.builder() + .endpoint(c.getEndpoint()) + .credentials(c.getAccessKey(), c.getSecretKey()) + .build(); + + return new PlayEduMinioClient(client); + } @Override public String url(String path) { + MinioConfig c = getMinioConfig(); + return c.getDomain() + (c.getDomain().endsWith("/") ? "" : "/") + c.getBucket() @@ -63,47 +97,49 @@ public class MinioServiceImpl implements MinioService { @SneakyThrows public String saveFile(MultipartFile file, String savePath, String contentType) { PutObjectArgs objectArgs = - PutObjectArgs.builder().bucket(c.getBucket()).object(savePath).stream( + PutObjectArgs.builder().bucket(bucket()).object(savePath).stream( file.getInputStream(), file.getSize(), -1) .contentType(contentType) .build(); - client.putObject(objectArgs); + getMinioClient().putObject(objectArgs); return url(savePath); } @Override public String uploadId(String path) { - return playEduMinioClient.uploadId(c.getBucket(), path); + return getPlayEduMinioClient().uploadId(bucket(), path); } @Override @SneakyThrows public String chunkPreSignUrl(String filename, String partNumber, String uploadId) { Map extraQueryParams = new HashMap<>(); - extraQueryParams.put("partNumber", partNumber + ""); + extraQueryParams.put("partNumber", partNumber); extraQueryParams.put("uploadId", uploadId); - return client.getPresignedObjectUrl( - GetPresignedObjectUrlArgs.builder() - .bucket(c.getBucket()) - .object(filename) - .method(Method.PUT) - .expiry(60 * 60 * 24) - .extraQueryParams(extraQueryParams) - .build()); + return getMinioClient() + .getPresignedObjectUrl( + GetPresignedObjectUrlArgs.builder() + .bucket(bucket()) + .object(filename) + .method(Method.PUT) + .expiry(60 * 60 * 24) + .extraQueryParams(extraQueryParams) + .build()); } @Override public String merge(String filename, String uploadId) { - playEduMinioClient.merge(c.getBucket(), filename, uploadId); + getPlayEduMinioClient().merge(bucket(), filename, uploadId); return url(filename); } @Override @SneakyThrows public void removeByPath(String path) { - client.removeObject(RemoveObjectArgs.builder().bucket(c.getBucket()).object(path).build()); + getMinioClient() + .removeObject(RemoveObjectArgs.builder().bucket(bucket()).object(path).build()); } @Override @@ -112,12 +148,12 @@ public class MinioServiceImpl implements MinioService { InputStream inputStream = new ByteArrayInputStream(file); PutObjectArgs objectArgs = - PutObjectArgs.builder().bucket(c.getBucket()).object(savePath).stream( + PutObjectArgs.builder().bucket(bucket()).object(savePath).stream( inputStream, file.length, -1) .contentType(contentType) .build(); - client.putObject(objectArgs); + getMinioClient().putObject(objectArgs); return url(savePath); } diff --git a/src/main/java/xyz/playedu/api/types/config/MinioConfig.java b/src/main/java/xyz/playedu/api/types/config/MinioConfig.java new file mode 100644 index 0000000..dcfa4fd --- /dev/null +++ b/src/main/java/xyz/playedu/api/types/config/MinioConfig.java @@ -0,0 +1,27 @@ +/* + * Copyright 2023 杭州白书科技有限公司 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package xyz.playedu.api.types.config; + +import lombok.Data; + +@Data +public class MinioConfig { + private String accessKey; + private String secretKey; + private String bucket; + private String endpoint; + private String domain; +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index af12145..2d059e9 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -47,14 +47,6 @@ spring: await-termination: true thread-name-prefix: "playedu-default-thread" -# Minio -minio: - access-key: "" - secret-key: "" - end-point: "" - bucket: "" - domain: "" - mybatis: mapper-locations: classpath:mapper/*.xml From 8da402255c7780212c7ae7abbe20a3c6e2792a04 Mon Sep 17 00:00:00 2001 From: none Date: Wed, 31 May 2023 09:54:38 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9B=BE=E5=BD=A2?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 12 ++-- .../xyz/playedu/api/config/KaptchaConfig.java | 58 ------------------- .../service/impl/ImageCaptchaServiceImpl.java | 34 +++-------- 3 files changed, 14 insertions(+), 90 deletions(-) delete mode 100644 src/main/java/xyz/playedu/api/config/KaptchaConfig.java diff --git a/pom.xml b/pom.xml index 50bf3a4..61e8723 100644 --- a/pom.xml +++ b/pom.xml @@ -75,13 +75,6 @@ spring-boot-starter-validation - - - com.github.penggle - kaptcha - 2.3.2 - - com.google.code.gson gson @@ -139,6 +132,11 @@ hutool-core 5.8.16 + + cn.hutool + hutool-captcha + 5.8.16 + org.springdoc diff --git a/src/main/java/xyz/playedu/api/config/KaptchaConfig.java b/src/main/java/xyz/playedu/api/config/KaptchaConfig.java deleted file mode 100644 index 786ac31..0000000 --- a/src/main/java/xyz/playedu/api/config/KaptchaConfig.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2023 杭州白书科技有限公司 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package xyz.playedu.api.config; - -import static com.google.code.kaptcha.Constants.*; - -import com.google.code.kaptcha.impl.DefaultKaptcha; -import com.google.code.kaptcha.util.Config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.util.Properties; - -@Configuration -public class KaptchaConfig { - - @Bean(name = "captchaProducer") - public DefaultKaptcha getKaptchaBean() { - DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); - Properties properties = new Properties(); - // 是否边框 - properties.setProperty(KAPTCHA_BORDER, "no"); - // 字符颜色 - properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "red"); - // 干扰线颜色 - properties.setProperty(KAPTCHA_NOISE_COLOR, "red"); - // 字符间距 - properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "5"); - // 图片宽度 - properties.setProperty(KAPTCHA_IMAGE_WIDTH, "120"); - // 图片高度 - properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "50"); - // 字符大小 - properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "40"); - // 字符长度 - properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "4"); - // 字体样式 - properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier"); - - defaultKaptcha.setConfig(new Config(properties)); - - return defaultKaptcha; - } -} diff --git a/src/main/java/xyz/playedu/api/service/impl/ImageCaptchaServiceImpl.java b/src/main/java/xyz/playedu/api/service/impl/ImageCaptchaServiceImpl.java index 662b6de..a912782 100644 --- a/src/main/java/xyz/playedu/api/service/impl/ImageCaptchaServiceImpl.java +++ b/src/main/java/xyz/playedu/api/service/impl/ImageCaptchaServiceImpl.java @@ -15,27 +15,19 @@ */ package xyz.playedu.api.service.impl; -import com.google.code.kaptcha.impl.DefaultKaptcha; - -import jakarta.annotation.Resource; +import cn.hutool.captcha.CaptchaUtil; +import cn.hutool.captcha.LineCaptcha; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import org.springframework.util.FastByteArrayOutputStream; import xyz.playedu.api.service.ImageCaptchaService; import xyz.playedu.api.types.ImageCaptchaResult; -import xyz.playedu.api.util.Base64Util; import xyz.playedu.api.util.HelperUtil; import xyz.playedu.api.util.RedisUtil; -import java.awt.image.BufferedImage; -import java.io.IOException; - -import javax.imageio.ImageIO; - @Slf4j @Service public class ImageCaptchaServiceImpl implements ImageCaptchaService { @@ -46,29 +38,21 @@ public class ImageCaptchaServiceImpl implements ImageCaptchaService { @Value("${playedu.captcha.expire}") private Long ConfigExpire; - @Resource private DefaultKaptcha defaultKaptcha; - @Override - public ImageCaptchaResult generate() throws IOException { + public ImageCaptchaResult generate() { ImageCaptchaResult imageCaptcha = new ImageCaptchaResult(); - BufferedImage image; + + // 生成验证码 + LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(240, 100, 4, 1); // 图形验证码的key[api是无状态的需要key来锁定验证码的值] String randomKey = HelperUtil.randomString(16); imageCaptcha.setKey(randomKey); - - // 生成验证码 - imageCaptcha.setCode(defaultKaptcha.createText()); - image = defaultKaptcha.createImage(imageCaptcha.getCode()); + imageCaptcha.setCode(lineCaptcha.getCode()); + imageCaptcha.setImage("data:image/png;base64," + lineCaptcha.getImageBase64()); // 写入到redis中 - RedisUtil.set(getCacheKey(randomKey), imageCaptcha.getCode(), ConfigExpire); - - FastByteArrayOutputStream os = new FastByteArrayOutputStream(); - ImageIO.write(image, "png", os); - - String base64 = "data:image/png;base64," + Base64Util.encode(os.toByteArray()); - imageCaptcha.setImage(base64); + RedisUtil.set(getCacheKey(imageCaptcha.getKey()), imageCaptcha.getCode(), ConfigExpire); return imageCaptcha; } From 4689073d4f80665feb466d0b2d8f0e242deae600 Mon Sep 17 00:00:00 2001 From: none Date: Wed, 31 May 2023 09:57:31 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E5=85=A8=E5=B1=80=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E6=8D=95=E8=8E=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../playedu/api/controller/ExceptionController.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/xyz/playedu/api/controller/ExceptionController.java b/src/main/java/xyz/playedu/api/controller/ExceptionController.java index 6358dd2..5bc268b 100644 --- a/src/main/java/xyz/playedu/api/controller/ExceptionController.java +++ b/src/main/java/xyz/playedu/api/controller/ExceptionController.java @@ -37,11 +37,11 @@ import java.util.List; @Slf4j public class ExceptionController { - // @ExceptionHandler(Exception.class) - // public JsonResponse exceptionHandler(Exception e) { - // log.error(e.getMessage()); - // return JsonResponse.error("系统错误", 500); - // } + @ExceptionHandler(Exception.class) + public JsonResponse exceptionHandler(Exception e) { + log.error(e.getMessage()); + return JsonResponse.error("系统错误", 500); + } @ExceptionHandler(ServiceException.class) public JsonResponse serviceExceptionHandler(ServiceException e) {