feat: 学时历史可打开对应课程
This commit is contained in:
+26
-4
@@ -330,6 +330,31 @@ _HISTORY_ROW_RE = re.compile(
|
||||
)
|
||||
|
||||
|
||||
def _history_course_path(row: dict) -> str:
|
||||
"""学时记录对应的课程页。已有地址直接用,否则按类型拼播放页。"""
|
||||
explicit = str(row.get("url") or row.get("knowledgeUrl") or row.get("targetUrl") or "").strip()
|
||||
if explicit:
|
||||
return explicit
|
||||
knowledge_id = str(row.get("knowledgeId") or row.get("kngId") or row.get("targetId") or "").replace("-", "").lower()
|
||||
if len(knowledge_id) != 32 or any(char not in "0123456789abcdef" for char in knowledge_id):
|
||||
return ""
|
||||
kind = str(row.get("knowledgeType") or row.get("kngType") or row.get("fileType") or "").strip().lower()
|
||||
folder = "document"
|
||||
for needle, name in (
|
||||
("package", "package"),
|
||||
("scorm", "scorm"),
|
||||
("courseknowledge", "scorm"),
|
||||
("video", "video"),
|
||||
("audio", "video"),
|
||||
("xuanyes", "xuanyes"),
|
||||
("xuan", "xuanyes"),
|
||||
):
|
||||
if needle in kind:
|
||||
folder = name
|
||||
break
|
||||
return f"/kng/view/{folder}/{knowledge_id}.html"
|
||||
|
||||
|
||||
def _history_api_item(row: object) -> dict | None:
|
||||
if not isinstance(row, dict):
|
||||
return None
|
||||
@@ -346,10 +371,7 @@ def _history_api_item(row: object) -> dict | None:
|
||||
elif isinstance(raw_minutes, str) and raw_minutes.strip():
|
||||
match = re.search(r"(\d+)", raw_minutes)
|
||||
minutes = int(match.group(1)) if match else None
|
||||
path = str(row.get("url") or row.get("knowledgeUrl") or row.get("targetUrl") or "").strip()
|
||||
knowledge_id = str(row.get("knowledgeId") or row.get("kngId") or "").replace("-", "")
|
||||
if not path and len(knowledge_id) == 32:
|
||||
path = f"/kng/view/document/{knowledge_id}.html"
|
||||
path = _history_course_path(row)
|
||||
if not title and not studied_at:
|
||||
return None
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user