Skip to content

Commit

Permalink
fix: not fond for video subtitle (#565)
Browse files Browse the repository at this point in the history
* fix: not fond for video subtitle.

* docs: update CHANGELOG.MD
  • Loading branch information
GuoHao authored Jun 15, 2024
1 parent 6198023 commit 0be9d2f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
## 问题修复

- 主题相关的模板引擎初始化问题
- 视频文件名带有中括号等特殊字符的,sql的like匹配不到字幕

# 0.12.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import run.ikaros.api.store.enums.AttachmentRelationType;
import run.ikaros.server.core.attachment.event.AttachmentReferenceSaveEvent;
import run.ikaros.server.core.attachment.event.EpisodeAttachmentUpdateEvent;
import run.ikaros.server.infra.utils.SqlUtils;
import run.ikaros.server.store.entity.AttachmentEntity;
import run.ikaros.server.store.entity.AttachmentReferenceEntity;
import run.ikaros.server.store.entity.AttachmentRelationEntity;
Expand Down Expand Up @@ -86,7 +87,8 @@ private Flux<VideoSubtitle> findAllAttachmentSubtitles(AttachmentEntity attachme
String attachmentName = attachmentEntity.getName();
String postfix = FileUtils.parseFilePostfix(attachmentName);
attachmentName = attachmentName.substring(0, attachmentName.indexOf(postfix));
return attachmentRepository.findAllByTypeAndNameLike(File, attachmentName + "%")
return attachmentRepository.findAllByTypeAndNameLike(File,
SqlUtils.escapeLikeSpecialChars(attachmentName) + "%")
.filter(entity -> entity.getName().endsWith("ass"))
.map(entity -> VideoSubtitle.builder()
.masterAttachmentId(attachmentEntity.getId())
Expand Down
42 changes: 42 additions & 0 deletions server/src/main/java/run/ikaros/server/infra/utils/SqlUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package run.ikaros.server.infra.utils;

public class SqlUtils {

/**
* 转义所有可能的特殊字符的函数.
*/
public static String escapeLikeSpecialChars(String input) {
if (input == null) {
return null;
}
return input.replaceAll("([\\\\_%\\[\\]])", "\\\\$1")
.replace("-", "\\-")
.replace("!", "\\!")
.replace("'", "''")
.replace("`", "\\`")
.replace("\"", "\\\"")
.replace("*", "\\*")
.replace("(", "\\(")
.replace(")", "\\)")
.replace("{", "\\{")
.replace("}", "\\}")
.replace("<", "\\<")
.replace(">", "\\>")
.replace("#", "\\#")
.replace("&", "\\&")
.replace("|", "\\|")
.replace("^", "\\^")
.replace("~", "\\~")
.replace("$", "\\$")
.replace("?", "\\?")
.replace("+", "\\+")
.replace(";", "\\;")
.replace(":", "\\:")
.replace("@", "\\@")
.replace("/", "\\/")
.replace("=", "\\=")
.replace(",", "\\,")
.replace(".", "\\.")
.replace(" ", "\\ ");
}
}

0 comments on commit 0be9d2f

Please sign in to comment.