fix: 智慧教育网站更新后 ParseJsUrl 无法匹配新的 chunk URL 结构
ci/woodpecker/tag/build Pipeline was successful

网站将 chunk-vendors 改为了 chunk-libs/chunk-elementUI,
且首页组件被合并到多模块组合 chunk 中。
更新正则:匹配 chunk-libs 或 chunk-elementUI 的 URL,
提取 base 路径和 hash,构造新的组合 chunk 文件 URL。
This commit is contained in:
becomer
2026-08-09 21:56:58 +08:00
parent f4c2b8de4c
commit 27d83f193f
+10 -5
View File
@@ -166,13 +166,18 @@ func (c *Course) Refresh(ctx context.Context, c2 model.Course, ch model.Chapter,
}
func ParseJsUrl(str string) string {
// <script defer src="https://cdnbasic.scbdc.edu.cn/%E7%9C%81%E7%BA%A7%E8%B5%84%E6%BA%90/hd/chunk-vendors.5e79f5ce155849.js">
re := regexp.MustCompile(`https://[^"'\s]+chunk-vendors[^"'\s]+\.js`)
match := re.FindString(str)
if match == "" {
// 网站已更新,chunk-vendors 不再存在。
// 现在从 HTML 中找到任一 chunk-*.js 的 URL,提取其 base 路径和 hash,
// 然后构造包含 src_views_home_index_vue 的组合 chunk 文件 URL。
re := regexp.MustCompile(`(https://[^"'\s]+/)chunk-(?:libs|elementUI)\.([0-9a-f]+)\.js`)
match := re.FindStringSubmatch(str)
if len(match) < 3 {
return ""
}
return strings.Replace(match, "chunk-vendors", "src_views_home_index_vue", 1)
basePath := match[1]
hash := match[2]
// 用已知的组合 chunk 名称拼出 URL:该 chunk 同时包含首页和 CourseList 组件
return basePath + "src_views_home_index_vue-src_views_noPermission_index_vue-src_views_components_CourseList_vue." + hash + ".js"
}
func (c *Course) GetCourseProcees(ctx context.Context, courseId string) (finished string, total string) {
post, err := c.Client.R().SetHeader("X-Token", c.Token).SetBody(map[string]any{