Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,26 @@ public static String extractCleanBase64(String input) {
return trimmed;
}

/**
* 从 Base64 数据中提取 MIME 类型
* @param base64Data 完整的 Base64 数据(包含 data:image/png;base64, 前缀)
* @return 提取到的 MIME 类型,如 "image/png", "image/svg+xml"
*/
public static String extractContentType(String base64Data) {
if (base64Data == null || !base64Data.startsWith("data:")) {
throw new IllegalArgumentException("Invalid Base64 data format");
}

Pattern pattern = Pattern.compile("^data:([^;]+);");
Matcher matcher = pattern.matcher(base64Data);

if (matcher.find()) {
return matcher.group(1);
}

throw new IllegalArgumentException("Cannot extract content type from Base64 data");
}

/**
* MIME类型转格式
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,13 @@ public void getResource(@RequestParam("data") String data, HttpServletResponse r
String cleanBase64 = ImageThumbnailGenerator.extractCleanBase64(base64Data);
byte[] imageBytes = Base64.getDecoder().decode(cleanBase64);

String detectedType = ImageThumbnailGenerator.detectFormatFromBase64(base64Data);
String fileExtension = detectedType.equals("jpeg") ? "jpg" : detectedType;
String detectedType = ImageThumbnailGenerator.extractContentType(base64Data);
Comment thread
lu-yg marked this conversation as resolved.

String fileName = useOriginal ? resource.getName() : "thumbnail_" + resource.getName();
// URL编码文件名
String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8)
.replace("+", "%20");
response.setContentType("image/" + detectedType);
response.setContentType(detectedType);

// 只使用 filename* 格式,避免中文字符直接出现在header中
response.setHeader("Content-Disposition",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,10 @@ public IPage<Block> findBlocksByConditionPagetion(Map<String, String> request) {
@Override
public List<User> getUsers(List<Block> blocksList) {
Set<String> userSet = new HashSet<>();

List<User> users = new ArrayList<>();
if(blocksList.isEmpty()) {
return users;
}
// 提取 createdBy 列表中的唯一值
blocksList.forEach(item -> {
if (item.getCreatedBy() != null && !userSet.contains(item.getCreatedBy())) {
Expand Down
6 changes: 3 additions & 3 deletions base/src/main/resources/mappers/BlockGroupMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
LEFT JOIN
r_block_group_block rbg ON rbg.block_group_id = bg.id
LEFT JOIN
t_block b ON b.id = rbg.block_id
t_block b ON b.id = rbg.block_id AND b.id IS NOT NULL
<choose>
<when test="blockCreatedBy != null">
AND b.created_by = #{blockCreatedBy}
Expand Down Expand Up @@ -247,7 +247,7 @@
LEFT JOIN
r_block_group_block rbg ON rbg.block_group_id = bg.id
LEFT JOIN
t_block b ON b.id = rbg.block_id
t_block b ON b.id = rbg.block_id AND b.id IS NOT NULL
<choose>
<when test="blockCreatedBy != null">
AND b.created_by = #{blockCreatedBy}
Expand Down Expand Up @@ -314,7 +314,7 @@
LEFT JOIN
r_block_group_block rbg ON rbg.block_group_id = bg.id
LEFT JOIN
t_block b ON b.id = rbg.block_id
t_block b ON b.id = rbg.block_id AND b.id IS NOT NULL
<choose>
<when test="blockCreatedBy != null">
AND b.created_by = #{blockCreatedBy}
Expand Down
Loading