fix: refresh custom placeholders without restart

Closes #5770
This commit is contained in:
jxxghp
2026-05-14 23:04:14 +08:00
parent 9128955bf9
commit 41da9b62c2
2 changed files with 39 additions and 8 deletions

View File

@@ -15,6 +15,17 @@ class CustomizationMatcher(metaclass=Singleton):
self.customization = None
self.custom_separator = None
@staticmethod
def _normalize_customization(customization):
"""
规范化自定义占位符配置,兼容历史字符串与列表两种保存格式。
"""
if isinstance(customization, str):
customization = customization.replace("\n", ";").replace("|", ";").strip(";").split(";")
if not customization:
return []
return list(filter(None, customization))
def match(self, title=None):
"""
:param title: 资源标题或文件名
@@ -22,14 +33,14 @@ class CustomizationMatcher(metaclass=Singleton):
"""
if not title:
return ""
if not self.customization:
# 自定义占位符
customization = self.systemconfig.get(SystemConfigKey.Customization)
if not customization:
return ""
if isinstance(customization, str):
customization = customization.replace("\n", ";").replace("|", ";").strip(";").split(";")
self.customization = "|".join([f"({item})" for item in customization])
# 自定义占位符需要跟随系统配置实时生效,避免单例缓存导致保存后仍沿用旧规则。
customization = self._normalize_customization(
self.systemconfig.get(SystemConfigKey.Customization)
)
if not customization:
self.customization = None
return ""
self.customization = "|".join([f"({item})" for item in customization])
customization_re = re.compile(r"%s" % self.customization)
# 处理重复多次的情况,保留先后顺序(按添加自定义占位符的顺序)