Skip to content

Commit 87ac5ae

Browse files
committed
fix(notification): 兼容 Windows 路径格式,推送文案显示番剧名而非完整路径
1 parent 243e093 commit 87ac5ae

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

  • backend/src/module/notification

backend/src/module/notification/base.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,25 @@ def _format_message(self, notify: Notification) -> str:
4848
import re
4949
# If official_title contains a full path like "D:\server\QB\Bangumi\", strip it
5050
title = notify.official_title
51-
if os.sep in title or (os.altsep and os.altsep in title):
52-
# Try to find the bangumi folder name (the folder before "Season X")
53-
# Strip drive letter and base paths
54-
normalized = os.path.normpath(title)
55-
parts = normalized.split(os.sep)
51+
# Check for both Windows (\) and Unix (/) path separators
52+
has_sep = os.sep in title
53+
if os.altsep:
54+
has_sep = has_sep or os.altsep in title
55+
# Also check for Windows backslash explicitly (Docker runs Linux, os.sep="/")
56+
if not has_sep and "\\" in title:
57+
has_sep = True
58+
if has_sep:
59+
# Normalize path: convert backslashes to forward slashes first
60+
normalized = title.replace("\\", "/")
61+
normalized = os.path.normpath(normalized)
62+
parts = normalized.split("/")
5663
# Find the part that looks like a bangumi title (not "Season X")
5764
bangumi_parts = []
5865
for part in parts:
5966
if re.match(r'^Season\s*\d+$', part, re.IGNORECASE):
6067
break
6168
bangumi_parts.append(part)
62-
title = os.sep.join(bangumi_parts) if bangumi_parts else parts[-1]
69+
title = "\\".join(bangumi_parts) if bangumi_parts else parts[-1]
6370
return (
6471
f"{title} 更新啦\n"
6572
f"更新集数: 第{notify.episode}集"

0 commit comments

Comments
 (0)