refactor: React 前端重构,新旧平台合并为莞易学

This commit is contained in:
study-tool
2026-10-29 23:50:46 +08:00
parent 35853891c9
commit e8634a6317
62 changed files with 8923 additions and 4623 deletions
+73
View File
@@ -0,0 +1,73 @@
"""全局常量 / 环境变量。
平台地址、默认值只在这里写一份,其它模块 `from study_tool.config import *`。
"""
import os
import re
import shutil
# 包内路径 -> 项目根目录:data / static / des*.js 这些运行时资源都留在仓库根
HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.dirname(os.path.dirname(HERE))
DATA = os.path.join(ROOT, "data")
LOGDIR = os.path.join(DATA, "logs") # 旧版日志目录;只有首次迁移会读它
STATIC_DIR = os.path.join(ROOT, "static")
os.makedirs(LOGDIR, exist_ok=True)
def _find_node():
"""Locate a node.exe: $NODE_BIN > PATH > common install dirs."""
for c in [os.environ.get("NODE_BIN"), shutil.which("node"), shutil.which("node.exe"),
r"D:\Software\devlopSoftware\Node\24.16.0\node.exe",
r"C:\Program Files\nodejs\node.exe",
r"C:\Program Files (x86)\nodejs\node.exe"]:
if c and os.path.exists(c):
return c
return "node"
NODE = _find_node()
DESENC = os.path.join(ROOT, "desenc.js")
UA = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/154.0.0.0 Safari/537.36 Edg/154.0.0.0")
JSPX = "https://jspx.dgjy.net"
TPASS = "https://tyyh.dgjy.net/tpass"
# 表单提交带上来源头,和浏览器一致(该站有 WAF,字段异常会直接 403)
LOGIN_HEADERS = {"Referer": TPASS + "/login", "Origin": "https://tyyh.dgjy.net"}
AUTHORIZE = ("https://tyyh.dgjy.net/tpass/oauth2.0/authorize?client_id=wpxtgl&scope=all"
"&response_type=code&state=random&redirect_uri=https%3A%2F%2Fdj.dgjy.net%2Fhomepage"
"%2Fremote%2Fopenapi%2Fdgwjt%2Flogin%3Furl%3Dhttps%3A%2F%2Fjspx.dgjy.net%2Ftstudy"
"%2Fpassport%2Flogin.action")
EP_STUDY = JSPX + "/train/trainee/courseware-studyTimeUpdate.action"
# 新版培训平台(莞易学/study.dgjy.net)的课程接口。2026 年起的「慕课」课程不再
# 用 jspx 的 tier-tree 页面,而是 Vue SPA + /train/course/front/* 这组 JSON 接口。
TRAIN_AUTHORIZE_PATH = ("/oauth2.0/authorize?client_id=gyx&scope=all&response_type=code"
"&state=random&redirect_uri=https%3A%2F%2Fstudy.dgjy.net%2F%23%2Flogin%2Fback")
STUDY = os.environ.get("STUDY_BASE", "https://study.dgjy.net").rstrip("/")
DEBUG_DIR = os.path.join(DATA, "debug") # 页面快照的兜底目录(正常存 SQLite 的 snapshots 表)
os.makedirs(DEBUG_DIR, exist_ok=True)
HEX32 = re.compile(r"^[0-9A-Fa-f]{32}$")
# OAuth 授权码:tpass 发的是 ST-369516-xxxx-tpass,带连字符,不能只认 [0-9A-Za-z]
CODE_RE = re.compile(r"(?:[?#&]|\b)code=([0-9A-Za-z._\-]{6,128})")
# 「我的课程」的三个板块 -> 各自的 AJAX 列表接口与 courseType
COURSE_SECTIONS = [
("在学课程", "/train/trainee/studyingCourse.action", "studying"),
("助学课程", "/train/assist/assistanceCourse.action", "assistance"),
("督学课程", "/train/inspect/inspectingCourse.action", "inspecting"),
]
# 每个板块的三种状态(页面上是「进行中 / 未开始 / 已结束」三个页签)
PLAN_STATUS = [
("进行中", "TAKING_PLAN"),
("未开始", "NO_BEGAIN_PLAN"),
("已结束", "FINISHED_PLAN"),
]
# 只有这两种状态还能进去学;已结束的只能查看
STUDYABLE_STATUS = {"TAKING_PLAN", "NO_BEGAIN_PLAN"}
class SessionExpired(RuntimeError):
"""站点要求重新登录(cookie 已失效)。"""