diff --git a/pom.xml b/pom.xml index f60d524..e1b7524 100644 --- a/pom.xml +++ b/pom.xml @@ -2,23 +2,26 @@ 4.0.0 + im.zhaojun + zfile + 4.1.5 + zfile + jar + 一个在线的文件浏览系统 + org.springframework.boot spring-boot-starter-parent - 2.6.8 + 2.7.12 - im.zhaojun - zfile - 4.1.4 - zfile - war - 一个在线的文件浏览系统 - 1.8 1.5.3.Final + 2.0 + 2.14.1 + 3.41.2.2 @@ -52,9 +55,9 @@ - mysql - mysql-connector-java - 8.0.31 + com.mysql + mysql-connector-j + 8.0.33 runtime @@ -82,12 +85,12 @@ com.amazonaws aws-java-sdk-s3 - 1.12.406 + 1.12.463 com.qiniu qiniu-java-sdk - 7.12.0 + 7.12.1 com.jcraft @@ -105,7 +108,7 @@ cn.dev33 sa-token-spring-boot-starter - 1.33.0 + 1.34.0.temp1 @@ -121,7 +124,7 @@ cn.hutool hutool-all - 5.8.10 + 5.8.18 org.projectlombok @@ -143,9 +146,9 @@ okhttp - com.alibaba - fastjson - 1.2.83_noneautotype + com.alibaba.fastjson2 + fastjson2 + 2.0.29 com.google.guava @@ -175,7 +178,7 @@ org.json json - 20200518 + 20230227 org.apache.httpcomponents @@ -191,6 +194,19 @@ org.springframework.retry spring-retry + + + + commons-fileupload + commons-fileupload + 1.5 + + + + com.alibaba + dns-cache-manipulator + 1.8.1 + diff --git a/src/main/java/im/zhaojun/zfile/core/config/SaTokenConfigure.java b/src/main/java/im/zhaojun/zfile/core/config/SaTokenConfigure.java index 48a79e5..e18f1db 100644 --- a/src/main/java/im/zhaojun/zfile/core/config/SaTokenConfigure.java +++ b/src/main/java/im/zhaojun/zfile/core/config/SaTokenConfigure.java @@ -1 +1 @@ -package im.zhaojun.zfile.core.config; import cn.dev33.satoken.interceptor.SaRouteInterceptor; import cn.dev33.satoken.router.SaRouter; import cn.dev33.satoken.stp.StpUtil; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** * SaToken 权限配置, 配置管理员才能访问管理员功能. * * @author zhaojun */ @Configuration public class SaTokenConfigure implements WebMvcConfigurer { /** * 注册权限校验拦截器, 拦截所有 /admin/** 请求, 但登陆相关的接口不需要认证. * @param registry * 拦截器注册器 */ @Override public void addInterceptors(InterceptorRegistry registry) { // 注册路由拦截器,自定义验证规则 registry.addInterceptor(new SaRouteInterceptor((req, res, handler) -> { // 根据路由划分模块,不同模块不同鉴权 SaRouter.match("/admin/**", StpUtil::checkLogin); // 忽略所有登陆相关接口 })).addPathPatterns("/**").excludePathPatterns("/admin/login", "/admin/login/**", "/admin"); } } \ No newline at end of file +package im.zhaojun.zfile.core.config; import cn.dev33.satoken.interceptor.SaInterceptor; import cn.dev33.satoken.router.SaRouter; import cn.dev33.satoken.stp.StpUtil; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** * SaToken 权限配置, 配置管理员才能访问管理员功能. * * @author zhaojun */ @Configuration public class SaTokenConfigure implements WebMvcConfigurer { /** * 注册权限校验拦截器, 拦截所有 /admin/** 请求, 但登陆相关的接口不需要认证. * @param registry * 拦截器注册器 */ @Override public void addInterceptors(InterceptorRegistry registry) { // 注册路由拦截器,自定义验证规则 registry.addInterceptor(new SaInterceptor(handle -> { // 根据路由划分模块,不同模块不同鉴权 SaRouter.match("/admin/**", StpUtil::checkLogin); // 忽略所有登陆相关接口 })).addPathPatterns("/**").excludePathPatterns("/admin/login", "/admin/login/**", "/admin"); } } \ No newline at end of file diff --git a/src/main/java/im/zhaojun/zfile/core/exception/handler/GlobalExceptionHandler.java b/src/main/java/im/zhaojun/zfile/core/exception/handler/GlobalExceptionHandler.java index 189cdac..5f82d0c 100644 --- a/src/main/java/im/zhaojun/zfile/core/exception/handler/GlobalExceptionHandler.java +++ b/src/main/java/im/zhaojun/zfile/core/exception/handler/GlobalExceptionHandler.java @@ -1 +1 @@ -package im.zhaojun.zfile.core.exception.handler; import cn.dev33.satoken.exception.NotLoginException; import cn.hutool.core.io.IORuntimeException; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import im.zhaojun.zfile.core.exception.*; import im.zhaojun.zfile.core.exception.file.init.InitializeStorageSourceException; import im.zhaojun.zfile.core.exception.file.operator.DisableProxyDownloadException; import im.zhaojun.zfile.core.exception.file.operator.StorageSourceFileOperatorException; import im.zhaojun.zfile.core.util.AjaxJson; import im.zhaojun.zfile.core.util.RequestHolder; import im.zhaojun.zfile.core.util.StringUtils; import im.zhaojun.zfile.module.config.service.SystemConfigService; import lombok.extern.slf4j.Slf4j; import org.apache.catalina.connector.ClientAbortException; import org.springframework.core.annotation.Order; import org.springframework.http.HttpStatus; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.validation.BindException; import org.springframework.validation.BindingResult; import org.springframework.validation.FieldError; import org.springframework.web.HttpMediaTypeNotAcceptableException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Optional; /** * 全局异常处理 * * @author zhaojun */ @ControllerAdvice @Slf4j @Order(1) public class GlobalExceptionHandler { @Resource private SystemConfigService systemConfigService; /** * 存储源文件操作相关异常处理 */ @ExceptionHandler(value = StorageSourceException.class) @ResponseBody @ResponseStatus public AjaxJson storageSourceException(StorageSourceException e) { log.error("存储源 {} 出现异常", e.getStorageId(), e); return AjaxJson.getError(e.getResultMessage()); } /** * 存储源初始化相关异常处理 */ @ExceptionHandler(value = InitializeStorageSourceException.class) @ResponseBody @ResponseStatus public AjaxJson initializeException(InitializeStorageSourceException e) { log.error("初始化存储源 {} 失败", e.getStorageId(), e); return AjaxJson.getError(e.getResultMessage()); } /** * 存储源文件操作相关异常处理 */ @ExceptionHandler(value = StorageSourceFileOperatorException.class) @ResponseBody @ResponseStatus public AjaxJson storageSourceFileOperatorException(StorageSourceFileOperatorException e) { log.error("存储源 {} 文件操作异常", e.getStorageId(), e); return AjaxJson.getError(e.getResultMessage()); } @ExceptionHandler({ZFileRuntimeException.class}) @ResponseBody @ResponseStatus public AjaxJson getFileInfoException(ZFileRuntimeException e) { if (e.getCause() != null) { log.error("ZFileRuntimeException", e); } return AjaxJson.getError(e.getMessage()); } @ExceptionHandler({InvalidShortLinkException.class}) @ResponseBody @ResponseStatus(HttpStatus.NOT_FOUND) public AjaxJson getFileInfoException(InvalidShortLinkException e) { return AjaxJson.getError(e.getMessage()); } @ExceptionHandler({IllegalDownloadLinkException.class}) @ResponseBody @ResponseStatus(HttpStatus.FORBIDDEN) public AjaxJson getFileInfoException(IllegalDownloadLinkException e) { return AjaxJson.getError(e.getMessage()); } @ExceptionHandler({LoginVerifyException.class}) @ResponseBody @ResponseStatus(HttpStatus.FORBIDDEN) public AjaxJson loginVerifyException(LoginVerifyException e) { return AjaxJson.getError(e.getMessage()); } @ExceptionHandler(value = {MethodArgumentNotValidException.class, BindException.class}) @ResponseBody public AjaxJson> handleValidException(Exception e) { BindingResult bindingResult = null; if (e instanceof MethodArgumentNotValidException) { bindingResult = ((MethodArgumentNotValidException) e).getBindingResult(); } else if (e instanceof BindException) { bindingResult = ((BindException) e).getBindingResult(); } Map errorMap = new HashMap<>(16); Optional.ofNullable(bindingResult) .map(BindingResult::getFieldErrors) .ifPresent(fieldErrors -> { for (FieldError fieldError : fieldErrors) { errorMap.put(fieldError.getField(), fieldError.getDefaultMessage()); } }); return new AjaxJson<>(400, "非法参数 !", errorMap); } @ExceptionHandler({FileNotFoundException.class}) @ResponseBody @ResponseStatus(HttpStatus.NOT_FOUND) public AjaxJson fileNotFound() { return AjaxJson.getError("文件不存在"); } /** * 密码校验异常 */ @ExceptionHandler({PasswordVerifyException.class}) @ResponseBody @ResponseStatus public AjaxJson passwordVerifyException(PasswordVerifyException ex) { return AjaxJson.get(ex.getCode(), ex.getMessage()); } /** * 初始化时自动设置 cors 异常 */ @ExceptionHandler({StorageSourceAutoConfigCorsException.class}) @ResponseBody @ResponseStatus public AjaxJson autoConfigCorsException(StorageSourceAutoConfigCorsException ex) { log.error("跨域配置失败, 存储源初始化信息 {}, 异常信息: ", JSON.toJSON(ex.getIStorageParam()), ex); return AjaxJson.getError(ex.getMessage()); } @ExceptionHandler({StorageSourceNotSupportProxyUploadException.class}) @ResponseBody @ResponseStatus(HttpStatus.BAD_REQUEST) public AjaxJson storageSourceNotSupportProxyUploadException(StorageSourceNotSupportProxyUploadException e) { return AjaxJson.getError("非法操作, 当前存储源不支持此方式上传."); } @ExceptionHandler(value = DisableProxyDownloadException.class) @ResponseBody @ResponseStatus(HttpStatus.BAD_REQUEST) public AjaxJson disableProxyDownloadException(DisableProxyDownloadException e) { return AjaxJson.getError(e.getResultMessage()); } @ExceptionHandler({HttpMessageNotReadableException.class}) @ResponseBody @ResponseStatus(HttpStatus.BAD_REQUEST) public AjaxJson handlerHttpMessageNotReadableException(HttpMessageNotReadableException e) { return AjaxJson.getBadRequestError("请求参数不合法"); } /** * 捕获 ClientAbortException 异常, 不做任何处理, 防止出现大量堆栈日志输出, 此异常不影响功能. */ @ExceptionHandler({HttpMediaTypeNotAcceptableException.class, ClientAbortException.class}) @ResponseBody @ResponseStatus public void clientAbortException() { // if (log.isDebugEnabled()) { // log.debug("出现了断开异常:", ex); // } } /** * 捕获 IORuntimeException 异常, 如果 cause 是 ClientAbortException, 不做任何处理, 防止出现大量堆栈日志输出, 此异常不影响功能. */ @ExceptionHandler({ IORuntimeException.class }) @ResponseBody @ResponseStatus public void ioRuntimeException(IORuntimeException e) { if (e.getCause() instanceof ClientAbortException) { // log.info("捕获 ClientAbortException 异常, 不做任何处理, 防止出现大量堆栈日志输出, 此异常不影响功能."); return; } log.error(e.getMessage(), e); } @ExceptionHandler @ResponseBody @ResponseStatus public AjaxJson extraExceptionHandler(Exception e) { log.error(e.getMessage(), e); if (e.getClass() == Exception.class) { return AjaxJson.getError("系统异常, 请联系管理员"); } else { return AjaxJson.getError(e.getMessage()); } } /** * 登录异常拦截器 */ @ExceptionHandler(NotLoginException.class) @ResponseStatus(HttpStatus.UNAUTHORIZED) @ResponseBody public AjaxJson handlerNotLoginException(NotLoginException e) { HttpServletRequest request = RequestHolder.getRequest(); String axiosRequest = request.getHeader("axios-request"); if (StrUtil.isNotEmpty(axiosRequest)){ return AjaxJson.getNotLogin(); } try { String domain = systemConfigService.getRealFrontDomain(); String loginUrl = StringUtils.removeDuplicateSlashes(domain + "/login"); RequestHolder.getResponse().sendRedirect(loginUrl); } catch (IOException ex) { throw new RuntimeException(ex); } return null; } } \ No newline at end of file +package im.zhaojun.zfile.core.exception.handler; import cn.dev33.satoken.exception.NotLoginException; import cn.hutool.core.io.IORuntimeException; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson2.JSON; import im.zhaojun.zfile.core.exception.*; import im.zhaojun.zfile.core.exception.file.init.InitializeStorageSourceException; import im.zhaojun.zfile.core.exception.file.operator.DisableProxyDownloadException; import im.zhaojun.zfile.core.exception.file.operator.StorageSourceFileOperatorException; import im.zhaojun.zfile.core.util.AjaxJson; import im.zhaojun.zfile.core.util.RequestHolder; import im.zhaojun.zfile.core.util.StringUtils; import im.zhaojun.zfile.module.config.service.SystemConfigService; import lombok.extern.slf4j.Slf4j; import org.apache.catalina.connector.ClientAbortException; import org.springframework.core.annotation.Order; import org.springframework.http.HttpStatus; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.validation.BindException; import org.springframework.validation.BindingResult; import org.springframework.validation.FieldError; import org.springframework.web.HttpMediaTypeNotAcceptableException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Optional; /** * 全局异常处理 * * @author zhaojun */ @ControllerAdvice @Slf4j @Order(1) public class GlobalExceptionHandler { @Resource private SystemConfigService systemConfigService; /** * 存储源文件操作相关异常处理 */ @ExceptionHandler(value = StorageSourceException.class) @ResponseBody @ResponseStatus public AjaxJson storageSourceException(StorageSourceException e) { log.error("存储源 {} 出现异常", e.getStorageId(), e); return AjaxJson.getError(e.getResultMessage()); } /** * 存储源初始化相关异常处理 */ @ExceptionHandler(value = InitializeStorageSourceException.class) @ResponseBody @ResponseStatus public AjaxJson initializeException(InitializeStorageSourceException e) { log.error("初始化存储源 {} 失败", e.getStorageId(), e); return AjaxJson.getError(e.getResultMessage()); } /** * 存储源文件操作相关异常处理 */ @ExceptionHandler(value = StorageSourceFileOperatorException.class) @ResponseBody @ResponseStatus public AjaxJson storageSourceFileOperatorException(StorageSourceFileOperatorException e) { log.error("存储源 {} 文件操作异常", e.getStorageId(), e); return AjaxJson.getError(e.getResultMessage()); } @ExceptionHandler({ZFileRuntimeException.class}) @ResponseBody @ResponseStatus public AjaxJson getFileInfoException(ZFileRuntimeException e) { if (e.getCause() != null) { log.error("ZFileRuntimeException", e); } return AjaxJson.getError(e.getMessage()); } @ExceptionHandler({InvalidShortLinkException.class}) @ResponseBody @ResponseStatus(HttpStatus.NOT_FOUND) public AjaxJson getFileInfoException(InvalidShortLinkException e) { return AjaxJson.getError(e.getMessage()); } @ExceptionHandler({IllegalDownloadLinkException.class}) @ResponseBody @ResponseStatus(HttpStatus.FORBIDDEN) public AjaxJson getFileInfoException(IllegalDownloadLinkException e) { return AjaxJson.getError(e.getMessage()); } @ExceptionHandler({LoginVerifyException.class}) @ResponseBody @ResponseStatus(HttpStatus.FORBIDDEN) public AjaxJson loginVerifyException(LoginVerifyException e) { return AjaxJson.getError(e.getMessage()); } @ExceptionHandler(value = {MethodArgumentNotValidException.class, BindException.class}) @ResponseBody public AjaxJson> handleValidException(Exception e) { BindingResult bindingResult = null; if (e instanceof MethodArgumentNotValidException) { bindingResult = ((MethodArgumentNotValidException) e).getBindingResult(); } else if (e instanceof BindException) { bindingResult = ((BindException) e).getBindingResult(); } Map errorMap = new HashMap<>(16); Optional.ofNullable(bindingResult) .map(BindingResult::getFieldErrors) .ifPresent(fieldErrors -> { for (FieldError fieldError : fieldErrors) { errorMap.put(fieldError.getField(), fieldError.getDefaultMessage()); } }); return new AjaxJson<>(400, "非法参数 !", errorMap); } @ExceptionHandler({FileNotFoundException.class}) @ResponseBody @ResponseStatus(HttpStatus.NOT_FOUND) public AjaxJson fileNotFound() { return AjaxJson.getError("文件不存在"); } /** * 密码校验异常 */ @ExceptionHandler({PasswordVerifyException.class}) @ResponseBody @ResponseStatus public AjaxJson passwordVerifyException(PasswordVerifyException ex) { return AjaxJson.get(ex.getCode(), ex.getMessage()); } /** * 初始化时自动设置 cors 异常 */ @ExceptionHandler({StorageSourceAutoConfigCorsException.class}) @ResponseBody @ResponseStatus public AjaxJson autoConfigCorsException(StorageSourceAutoConfigCorsException ex) { log.error("跨域配置失败, 存储源初始化信息 {}, 异常信息: ", JSON.toJSON(ex.getIStorageParam()), ex); return AjaxJson.getError(ex.getMessage()); } @ExceptionHandler({StorageSourceNotSupportProxyUploadException.class}) @ResponseBody @ResponseStatus(HttpStatus.BAD_REQUEST) public AjaxJson storageSourceNotSupportProxyUploadException(StorageSourceNotSupportProxyUploadException e) { return AjaxJson.getError("非法操作, 当前存储源不支持此方式上传."); } @ExceptionHandler(value = DisableProxyDownloadException.class) @ResponseBody @ResponseStatus(HttpStatus.BAD_REQUEST) public AjaxJson disableProxyDownloadException(DisableProxyDownloadException e) { return AjaxJson.getError(e.getResultMessage()); } @ExceptionHandler({HttpMessageNotReadableException.class}) @ResponseBody @ResponseStatus(HttpStatus.BAD_REQUEST) public AjaxJson handlerHttpMessageNotReadableException(HttpMessageNotReadableException e) { return AjaxJson.getBadRequestError("请求参数不合法"); } /** * 捕获 ClientAbortException 异常, 不做任何处理, 防止出现大量堆栈日志输出, 此异常不影响功能. */ @ExceptionHandler({HttpMediaTypeNotAcceptableException.class, ClientAbortException.class}) @ResponseBody @ResponseStatus public void clientAbortException() { // if (log.isDebugEnabled()) { // log.debug("出现了断开异常:", ex); // } } /** * 捕获 IORuntimeException 异常, 如果 cause 是 ClientAbortException, 不做任何处理, 防止出现大量堆栈日志输出, 此异常不影响功能. */ @ExceptionHandler({ IORuntimeException.class }) @ResponseBody @ResponseStatus public void ioRuntimeException(IORuntimeException e) { if (e.getCause() instanceof ClientAbortException) { // log.info("捕获 ClientAbortException 异常, 不做任何处理, 防止出现大量堆栈日志输出, 此异常不影响功能."); return; } log.error(e.getMessage(), e); } @ExceptionHandler @ResponseBody @ResponseStatus public AjaxJson extraExceptionHandler(Exception e) { log.error(e.getMessage(), e); if (e.getClass() == Exception.class) { return AjaxJson.getError("系统异常, 请联系管理员"); } else { return AjaxJson.getError(e.getMessage()); } } /** * 登录异常拦截器 */ @ExceptionHandler(NotLoginException.class) @ResponseStatus(HttpStatus.UNAUTHORIZED) @ResponseBody public AjaxJson handlerNotLoginException(NotLoginException e) { HttpServletRequest request = RequestHolder.getRequest(); String axiosRequest = request.getHeader("axios-request"); if (StrUtil.isNotEmpty(axiosRequest)){ return AjaxJson.getNotLogin(); } try { String domain = systemConfigService.getRealFrontDomain(); String loginUrl = StringUtils.removeDuplicateSlashes(domain + "/login"); RequestHolder.getResponse().sendRedirect(loginUrl); } catch (IOException ex) { throw new RuntimeException(ex); } return null; } } \ No newline at end of file diff --git a/src/main/java/im/zhaojun/zfile/core/httpclient/logging/HttpLoggingInterceptor.java b/src/main/java/im/zhaojun/zfile/core/httpclient/logging/HttpLoggingInterceptor.java index a84b66c..866259d 100644 --- a/src/main/java/im/zhaojun/zfile/core/httpclient/logging/HttpLoggingInterceptor.java +++ b/src/main/java/im/zhaojun/zfile/core/httpclient/logging/HttpLoggingInterceptor.java @@ -118,7 +118,7 @@ public final class HttpLoggingInterceptor implements Interceptor { void log(String message); /** A {@link Logger} defaults output appropriate for the current platform. */ - Logger DEFAULT = message -> Platform.get().log(INFO, message, null); + Logger DEFAULT = message -> Platform.get().log(message, INFO, null); Logger DEBUG = log::debug; Logger TRACE = log::trace; diff --git a/src/main/java/im/zhaojun/zfile/module/link/service/ShortLinkService.java b/src/main/java/im/zhaojun/zfile/module/link/service/ShortLinkService.java index fd18b8b..f802342 100644 --- a/src/main/java/im/zhaojun/zfile/module/link/service/ShortLinkService.java +++ b/src/main/java/im/zhaojun/zfile/module/link/service/ShortLinkService.java @@ -5,7 +5,7 @@ import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.RandomUtil; -import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson2.JSONArray; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import im.zhaojun.zfile.core.exception.file.InvalidStorageSourceException; diff --git a/src/main/java/im/zhaojun/zfile/module/storage/controller/callback/GoogleDriveCallbackController.java b/src/main/java/im/zhaojun/zfile/module/storage/controller/callback/GoogleDriveCallbackController.java index f6aac5d..16ccf58 100644 --- a/src/main/java/im/zhaojun/zfile/module/storage/controller/callback/GoogleDriveCallbackController.java +++ b/src/main/java/im/zhaojun/zfile/module/storage/controller/callback/GoogleDriveCallbackController.java @@ -2,7 +2,7 @@ package im.zhaojun.zfile.module.storage.controller.callback; import cn.hutool.core.codec.Base64; import cn.hutool.core.util.StrUtil; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import im.zhaojun.zfile.module.storage.model.dto.OAuth2TokenDTO; import io.swagger.annotations.Api; diff --git a/src/main/java/im/zhaojun/zfile/module/storage/controller/helper/GoogleDriveHelperController.java b/src/main/java/im/zhaojun/zfile/module/storage/controller/helper/GoogleDriveHelperController.java index feaff0f..974c026 100644 --- a/src/main/java/im/zhaojun/zfile/module/storage/controller/helper/GoogleDriveHelperController.java +++ b/src/main/java/im/zhaojun/zfile/module/storage/controller/helper/GoogleDriveHelperController.java @@ -3,9 +3,9 @@ package im.zhaojun.zfile.module.storage.controller.helper; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import im.zhaojun.zfile.module.storage.model.request.GetGoogleDriveListRequest; import im.zhaojun.zfile.module.storage.model.result.GoogleDriveInfoResult; diff --git a/src/main/java/im/zhaojun/zfile/module/storage/controller/helper/SharePointHelperController.java b/src/main/java/im/zhaojun/zfile/module/storage/controller/helper/SharePointHelperController.java index f8058fe..f20340e 100644 --- a/src/main/java/im/zhaojun/zfile/module/storage/controller/helper/SharePointHelperController.java +++ b/src/main/java/im/zhaojun/zfile/module/storage/controller/helper/SharePointHelperController.java @@ -4,8 +4,8 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpUtil; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import im.zhaojun.zfile.module.storage.model.request.SharePointSearchSitesRequest; import im.zhaojun.zfile.module.storage.model.request.SharePointSiteListsRequest; diff --git a/src/main/java/im/zhaojun/zfile/module/storage/service/impl/DogeCloudServiceImpl.java b/src/main/java/im/zhaojun/zfile/module/storage/service/impl/DogeCloudServiceImpl.java index 6b5d2a7..012d518 100644 --- a/src/main/java/im/zhaojun/zfile/module/storage/service/impl/DogeCloudServiceImpl.java +++ b/src/main/java/im/zhaojun/zfile/module/storage/service/impl/DogeCloudServiceImpl.java @@ -4,9 +4,10 @@ import cn.hutool.crypto.SecureUtil; import cn.hutool.http.Header; import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpUtil; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; +import com.amazonaws.auth.AWSCredentials; +import com.amazonaws.auth.AWSCredentialsProvider; import com.amazonaws.auth.BasicSessionCredentials; import com.amazonaws.client.builder.AwsClientBuilder; import com.amazonaws.services.s3.AmazonS3ClientBuilder; diff --git a/src/main/java/im/zhaojun/zfile/module/storage/service/impl/GoogleDriveServiceImpl.java b/src/main/java/im/zhaojun/zfile/module/storage/service/impl/GoogleDriveServiceImpl.java index 2e7cc2d..f08da3c 100644 --- a/src/main/java/im/zhaojun/zfile/module/storage/service/impl/GoogleDriveServiceImpl.java +++ b/src/main/java/im/zhaojun/zfile/module/storage/service/impl/GoogleDriveServiceImpl.java @@ -10,9 +10,9 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; import im.zhaojun.zfile.core.exception.StorageSourceRefreshTokenException; import im.zhaojun.zfile.core.exception.http.HttpResponseStatusErrorException; import im.zhaojun.zfile.core.util.RequestHolder; diff --git a/src/main/java/im/zhaojun/zfile/module/storage/service/impl/UpYunServiceImpl.java b/src/main/java/im/zhaojun/zfile/module/storage/service/impl/UpYunServiceImpl.java index dc78332..1410713 100644 --- a/src/main/java/im/zhaojun/zfile/module/storage/service/impl/UpYunServiceImpl.java +++ b/src/main/java/im/zhaojun/zfile/module/storage/service/impl/UpYunServiceImpl.java @@ -5,7 +5,7 @@ import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.crypto.SecureUtil; import com.UpYun; -import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson2.JSON; import com.upyun.Params; import com.upyun.UpException; import com.upyun.UpYunUtils; diff --git a/src/main/java/springfox/documentation/swagger2/web/Swagger2ControllerWebFlux.java b/src/main/java/springfox/documentation/swagger2/web/Swagger2ControllerWebFlux.java new file mode 100644 index 0000000..b7c697a --- /dev/null +++ b/src/main/java/springfox/documentation/swagger2/web/Swagger2ControllerWebFlux.java @@ -0,0 +1,106 @@ +/* + * + * Copyright 2017-2018 the original author or authors. + * + * 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 springfox.documentation.swagger2.web; + +import io.swagger.models.Swagger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.context.annotation.Conditional; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.plugin.core.PluginRegistry; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.util.HtmlUtils; +import springfox.documentation.annotations.ApiIgnore; +import springfox.documentation.service.Documentation; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.DocumentationCache; +import springfox.documentation.spring.web.OnReactiveWebApplication; +import springfox.documentation.spring.web.json.Json; +import springfox.documentation.spring.web.json.JsonSerializer; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.mappers.ServiceModelToSwagger2Mapper; + +import java.util.List; +import java.util.Optional; + +import static org.springframework.util.MimeTypeUtils.*; +import static springfox.documentation.swagger2.web.Swagger2ControllerWebMvc.*; + +@RestController +@ApiIgnore +@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE) +@RequestMapping(SWAGGER2_SPECIFICATION_PATH) +@Conditional({OnReactiveWebApplication.class}) +public class Swagger2ControllerWebFlux { + + private static final Logger LOGGER = LoggerFactory.getLogger(Swagger2ControllerWebFlux.class); + private static final String HAL_MEDIA_TYPE = "application/hal+json"; + + private final DocumentationCache documentationCache; + private final ServiceModelToSwagger2Mapper mapper; + private final JsonSerializer jsonSerializer; + private final PluginRegistry transformations; + + @Autowired + public Swagger2ControllerWebFlux( + DocumentationCache documentationCache, + ServiceModelToSwagger2Mapper mapper, + JsonSerializer jsonSerializer, + @Qualifier("webFluxSwaggerTransformationFilterRegistry") + PluginRegistry transformations) { + this.documentationCache = documentationCache; + this.mapper = mapper; + this.jsonSerializer = jsonSerializer; + this.transformations = transformations; + } + + @RequestMapping( + method = RequestMethod.GET, + produces = {APPLICATION_JSON_VALUE, HAL_MEDIA_TYPE}) + @ResponseBody + public ResponseEntity getDocumentation( + @RequestParam(value = "group", required = false) String swaggerGroup, + ServerHttpRequest request) { + + String groupName = Optional.ofNullable(swaggerGroup).orElse(Docket.DEFAULT_GROUP_NAME); + Documentation documentation = documentationCache.documentationByGroup(groupName); + if (documentation == null) { + LOGGER.warn("Unable to find specification for group {}", HtmlUtils.htmlEscape(groupName)); + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + Swagger swagger = mapper.mapDocumentation(documentation); + SwaggerTransformationContext context + = new SwaggerTransformationContext<>(swagger, request); + List filters = transformations.getPluginsFor(DocumentationType.SWAGGER_2); + for (WebFluxSwaggerTransformationFilter each : filters) { + context = context.next(each.transform(context)); + } + return new ResponseEntity<>(jsonSerializer.toJson(context.getSpecification()), HttpStatus.OK); + } +} \ No newline at end of file diff --git a/src/main/java/springfox/documentation/swagger2/web/Swagger2ControllerWebMvc.java b/src/main/java/springfox/documentation/swagger2/web/Swagger2ControllerWebMvc.java new file mode 100644 index 0000000..155bc28 --- /dev/null +++ b/src/main/java/springfox/documentation/swagger2/web/Swagger2ControllerWebMvc.java @@ -0,0 +1,110 @@ +/* + * + * Copyright 2017-2018 the original author or authors. + * + * 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 springfox.documentation.swagger2.web; + +import io.swagger.models.Swagger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.context.annotation.Conditional; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.plugin.core.PluginRegistry; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.util.HtmlUtils; +import springfox.documentation.annotations.ApiIgnore; +import springfox.documentation.service.Documentation; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.DocumentationCache; +import springfox.documentation.spring.web.OnServletBasedWebApplication; +import springfox.documentation.spring.web.json.Json; +import springfox.documentation.spring.web.json.JsonSerializer; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.mappers.ServiceModelToSwagger2Mapper; + +import javax.servlet.http.HttpServletRequest; + +import java.util.List; + +import static java.util.Optional.*; +import static org.springframework.util.MimeTypeUtils.*; +import static springfox.documentation.swagger2.web.Swagger2ControllerWebMvc.*; + +@ApiIgnore +@RestController +@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) +@RequestMapping(SWAGGER2_SPECIFICATION_PATH) +@Conditional(OnServletBasedWebApplication.class) +@Order(Ordered.HIGHEST_PRECEDENCE) +public class Swagger2ControllerWebMvc { + public static final String SWAGGER2_SPECIFICATION_PATH + = "${springfox.documentation.swagger.v2.path:/v2/api-docs}"; + + private static final Logger LOGGER = LoggerFactory.getLogger(Swagger2ControllerWebMvc.class); + private static final String HAL_MEDIA_TYPE = "application/hal+json"; + private final DocumentationCache documentationCache; + private final ServiceModelToSwagger2Mapper mapper; + private final JsonSerializer jsonSerializer; + private final PluginRegistry transformations; + + @Autowired + public Swagger2ControllerWebMvc( + DocumentationCache documentationCache, + ServiceModelToSwagger2Mapper mapper, + JsonSerializer jsonSerializer, + @Qualifier("webMvcSwaggerTransformationFilterRegistry") + PluginRegistry transformations) { + this.documentationCache = documentationCache; + this.mapper = mapper; + this.jsonSerializer = jsonSerializer; + this.transformations = transformations; + } + + @RequestMapping( + method = RequestMethod.GET, + produces = {APPLICATION_JSON_VALUE, HAL_MEDIA_TYPE}) + public ResponseEntity getDocumentation( + @RequestParam(value = "group", required = false) String swaggerGroup, + HttpServletRequest servletRequest) { + + String groupName = ofNullable(swaggerGroup).orElse(Docket.DEFAULT_GROUP_NAME); + Documentation documentation = documentationCache.documentationByGroup(groupName); + if (documentation == null) { + LOGGER.warn("Unable to find specification for group {}", HtmlUtils.htmlEscape(groupName)); + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + Swagger swagger = mapper.mapDocumentation(documentation); + SwaggerTransformationContext context + = new SwaggerTransformationContext<>(swagger, servletRequest); + List filters = transformations.getPluginsFor(DocumentationType.SWAGGER_2); + for (WebMvcSwaggerTransformationFilter each : filters) { + context = context.next(each.transform(context)); + } + return new ResponseEntity<>(jsonSerializer.toJson(context.getSpecification()), HttpStatus.OK); + } + +} \ No newline at end of file