mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-11-13 16:57:12 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 24fda9a84e | |||
| 0f43e1cff7 | |||
| 171040b674 | |||
| ab4a72e0ff | |||
| ed15115e44 |
15
CHANGELOG.md
15
CHANGELOG.md
@@ -1,3 +1,18 @@
|
|||||||
|
## [v1.5.1](https://github.com/Charles7c/continew-starter/compare/v1.5.0...v1.5.1) (2024-03-23)
|
||||||
|
|
||||||
|
### ✨ 新特性
|
||||||
|
|
||||||
|
- 【web】FileUploadUtils 新增文件下载方法 ([171040b](https://github.com/Charles7c/continew-starter/commit/171040b674ae18dd6560f1501f7c0d47a1f4b8ba))
|
||||||
|
|
||||||
|
### 🐛 问题修复
|
||||||
|
|
||||||
|
- 【api-doc】修复接口级鉴权配置不生效的问题 ([ab4a72e](https://github.com/Charles7c/continew-starter/commit/ab4a72e0fffe20b492c2250cc997ba3e94794118))
|
||||||
|
|
||||||
|
### 📦 依赖升级
|
||||||
|
|
||||||
|
- 【dependencies】Redisson 3.27.1 => 3.27.2 ([0f43e1c](https://github.com/Charles7c/continew-starter/commit/0f43e1cff7f2fc58273de300acf4432f3a300af4))
|
||||||
|
- 【dependencies】Crane4j 2.6.0 => 2.6.1 ([0f43e1c](https://github.com/Charles7c/continew-starter/commit/0f43e1cff7f2fc58273de300acf4432f3a300af4))
|
||||||
|
|
||||||
## [v1.5.0](https://github.com/Charles7c/continew-starter/compare/v1.4.1...v1.5.0) (2024-03-08)
|
## [v1.5.0](https://github.com/Charles7c/continew-starter/compare/v1.4.1...v1.5.0) (2024-03-08)
|
||||||
|
|
||||||
### 💎 功能优化
|
### 💎 功能优化
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<img src="https://img.shields.io/maven-central/v/top.charles7c.continew/continew-starter.svg?label=Maven%20Central&logo=sonatype&logoColor=FFF" alt="Release" />
|
<img src="https://img.shields.io/maven-central/v/top.charles7c.continew/continew-starter.svg?label=Maven%20Central&logo=sonatype&logoColor=FFF" alt="Release" />
|
||||||
</a>
|
</a>
|
||||||
<a href="https://github.com/Charles7c/continew-starter" target="_blank">
|
<a href="https://github.com/Charles7c/continew-starter" target="_blank">
|
||||||
<img src="https://img.shields.io/badge/RELEASE-v1.5.0-%23ff3f59.svg" alt="Release" />
|
<img src="https://img.shields.io/badge/RELEASE-v1.5.1-%23ff3f59.svg" alt="Release" />
|
||||||
</a>
|
</a>
|
||||||
<a href="https://app.codacy.com/gh/Charles7c/continew-starter/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade" target="_blank">
|
<a href="https://app.codacy.com/gh/Charles7c/continew-starter/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade" target="_blank">
|
||||||
<img src="https://app.codacy.com/project/badge/Grade/90ed633957a9410aa8745f0654827c01" alt="Codacy Badge" />
|
<img src="https://app.codacy.com/project/badge/Grade/90ed633957a9410aa8745f0654827c01" alt="Codacy Badge" />
|
||||||
|
|||||||
@@ -86,28 +86,27 @@ public class SpringDocAutoConfiguration implements WebMvcConfigurer {
|
|||||||
if (null != license) {
|
if (null != license) {
|
||||||
info.license(new License().name(license.getName()).url(license.getUrl()));
|
info.license(new License().name(license.getName()).url(license.getUrl()));
|
||||||
}
|
}
|
||||||
OpenAPI openAPI = new OpenAPI();
|
OpenAPI openApi = new OpenAPI();
|
||||||
openAPI.info(info);
|
openApi.info(info);
|
||||||
Components components = properties.getComponents();
|
Components components = properties.getComponents();
|
||||||
if (null != components) {
|
if (null != components) {
|
||||||
openAPI.components(components);
|
openApi.components(components);
|
||||||
// 鉴权配置
|
// 鉴权配置
|
||||||
Map<String, SecurityScheme> securitySchemeMap = components.getSecuritySchemes();
|
Map<String, SecurityScheme> securitySchemeMap = components.getSecuritySchemes();
|
||||||
if (MapUtil.isNotEmpty(securitySchemeMap)) {
|
if (MapUtil.isNotEmpty(securitySchemeMap)) {
|
||||||
SecurityRequirement securityRequirement = new SecurityRequirement();
|
SecurityRequirement securityRequirement = new SecurityRequirement();
|
||||||
List<String> list = securitySchemeMap.values().stream().map(SecurityScheme::getName).toList();
|
List<String> list = securitySchemeMap.values().stream().map(SecurityScheme::getName).toList();
|
||||||
list.forEach(securityRequirement::addList);
|
list.forEach(securityRequirement::addList);
|
||||||
openAPI.addSecurityItem(securityRequirement);
|
openApi.addSecurityItem(securityRequirement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return openAPI;
|
return openApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局自定义配置(全局添加鉴权参数)
|
* 全局自定义配置(全局添加鉴权参数)
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
|
||||||
public GlobalOpenApiCustomizer globalOpenApiCustomizer(SpringDocExtensionProperties properties) {
|
public GlobalOpenApiCustomizer globalOpenApiCustomizer(SpringDocExtensionProperties properties) {
|
||||||
return openApi -> {
|
return openApi -> {
|
||||||
if (null != openApi.getPaths()) {
|
if (null != openApi.getPaths()) {
|
||||||
|
|||||||
@@ -53,14 +53,14 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- 项目版本号 -->
|
<!-- 项目版本号 -->
|
||||||
<revision>1.5.0</revision>
|
<revision>1.5.1</revision>
|
||||||
<sa-token.version>1.37.0</sa-token.version>
|
<sa-token.version>1.37.0</sa-token.version>
|
||||||
<just-auth.version>1.16.6</just-auth.version>
|
<just-auth.version>1.16.6</just-auth.version>
|
||||||
<mybatis-plus.version>3.5.5</mybatis-plus.version>
|
<mybatis-plus.version>3.5.5</mybatis-plus.version>
|
||||||
<dynamic-datasource.version>4.3.0</dynamic-datasource.version>
|
<dynamic-datasource.version>4.3.0</dynamic-datasource.version>
|
||||||
<p6spy.version>3.9.1</p6spy.version>
|
<p6spy.version>3.9.1</p6spy.version>
|
||||||
<jetcache.version>2.7.5</jetcache.version>
|
<jetcache.version>2.7.5</jetcache.version>
|
||||||
<redisson.version>3.27.1</redisson.version>
|
<redisson.version>3.27.2</redisson.version>
|
||||||
<cosid.version>2.6.6</cosid.version>
|
<cosid.version>2.6.6</cosid.version>
|
||||||
<sms4j.version>3.1.1</sms4j.version>
|
<sms4j.version>3.1.1</sms4j.version>
|
||||||
<aj-captcha.version>1.3.0</aj-captcha.version>
|
<aj-captcha.version>1.3.0</aj-captcha.version>
|
||||||
@@ -69,7 +69,7 @@
|
|||||||
<nashorn.version>15.4</nashorn.version>
|
<nashorn.version>15.4</nashorn.version>
|
||||||
<x-file-storage.version>2.1.0</x-file-storage.version>
|
<x-file-storage.version>2.1.0</x-file-storage.version>
|
||||||
<aws-s3.version>1.12.675</aws-s3.version>
|
<aws-s3.version>1.12.675</aws-s3.version>
|
||||||
<crane4j.version>2.6.0</crane4j.version>
|
<crane4j.version>2.6.1</crane4j.version>
|
||||||
<knife4j.version>4.5.0</knife4j.version>
|
<knife4j.version>4.5.0</knife4j.version>
|
||||||
<tlog.version>1.5.1</tlog.version>
|
<tlog.version>1.5.1</tlog.version>
|
||||||
<ttl.version>2.14.5</ttl.version>
|
<ttl.version>2.14.5</ttl.version>
|
||||||
|
|||||||
@@ -18,17 +18,23 @@ package top.charles7c.continew.starter.web.util;
|
|||||||
|
|
||||||
import cn.hutool.core.date.DatePattern;
|
import cn.hutool.core.date.DatePattern;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.io.file.FileNameUtil;
|
import cn.hutool.core.io.file.FileNameUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件上传工具类
|
* 文件工具类
|
||||||
*
|
*
|
||||||
* @author Zheng Jie(<a href="https://gitee.com/elunez/eladmin">ELADMIN</a>)
|
* @author Zheng Jie(<a href="https://gitee.com/elunez/eladmin">ELADMIN</a>)
|
||||||
* @author Charles7c
|
* @author Charles7c
|
||||||
@@ -41,7 +47,7 @@ public class FileUploadUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传文件
|
* 上传
|
||||||
*
|
*
|
||||||
* @param multipartFile 源文件对象
|
* @param multipartFile 源文件对象
|
||||||
* @param filePath 文件路径
|
* @param filePath 文件路径
|
||||||
@@ -51,7 +57,6 @@ public class FileUploadUtils {
|
|||||||
public static File upload(MultipartFile multipartFile, String filePath, boolean isKeepOriginalFilename) {
|
public static File upload(MultipartFile multipartFile, String filePath, boolean isKeepOriginalFilename) {
|
||||||
String originalFilename = multipartFile.getOriginalFilename();
|
String originalFilename = multipartFile.getOriginalFilename();
|
||||||
String extensionName = FileNameUtil.extName(originalFilename);
|
String extensionName = FileNameUtil.extName(originalFilename);
|
||||||
|
|
||||||
String fileName;
|
String fileName;
|
||||||
if (isKeepOriginalFilename) {
|
if (isKeepOriginalFilename) {
|
||||||
fileName = "%s-%s.%s".formatted(FileNameUtil.getPrefix(originalFilename), DateUtil.format(LocalDateTime
|
fileName = "%s-%s.%s".formatted(FileNameUtil.getPrefix(originalFilename), DateUtil.format(LocalDateTime
|
||||||
@@ -59,7 +64,6 @@ public class FileUploadUtils {
|
|||||||
} else {
|
} else {
|
||||||
fileName = "%s.%s".formatted(IdUtil.fastSimpleUUID(), extensionName);
|
fileName = "%s.%s".formatted(IdUtil.fastSimpleUUID(), extensionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String pathname = filePath + fileName;
|
String pathname = filePath + fileName;
|
||||||
File dest = new File(pathname).getCanonicalFile();
|
File dest = new File(pathname).getCanonicalFile();
|
||||||
@@ -71,8 +75,35 @@ public class FileUploadUtils {
|
|||||||
multipartFile.transferTo(dest);
|
multipartFile.transferTo(dest);
|
||||||
return dest;
|
return dest;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Upload file occurred an error: {}. fileName: {}.", e.getMessage(), fileName, e);
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载
|
||||||
|
*
|
||||||
|
* @param request 请求对象
|
||||||
|
* @param response 响应对象
|
||||||
|
* @param file 文件
|
||||||
|
* @param autoDelete 下载后自动删除
|
||||||
|
*/
|
||||||
|
public static void download(HttpServletRequest request,
|
||||||
|
HttpServletResponse response,
|
||||||
|
File file,
|
||||||
|
boolean autoDelete) {
|
||||||
|
response.setCharacterEncoding(request.getCharacterEncoding());
|
||||||
|
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||||
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + file.getName());
|
||||||
|
try (FileInputStream fis = new FileInputStream(file)) {
|
||||||
|
IoUtil.copy(fis, response.getOutputStream());
|
||||||
|
response.flushBuffer();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
} finally {
|
||||||
|
if (autoDelete) {
|
||||||
|
file.deleteOnExit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user