dsh-ustc-campus 0.3.0 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,29 +1,38 @@
1
1
  # 科大校园工作台(`dsh-ustc-campus`)
2
2
 
3
- ## 不要再在学校各个页面东翻西找了,装上这个插件,对 AI 说句话就行
3
+ **One AI for all:一个对话,查办多种校园事务。** 这是面向中国科大同学的非官方校园插件,适配 Windows 桌面端 **DeepSeek Harness(DSH)** 与中国科大 **「词元工坊」**(校方 DSH-based 应用)。不用为每件事分别找系统入口,比如可以直接对 AI 说:
4
4
 
5
- 面向中国科大同学的非官方校园插件,适配 Windows 桌面端 **DeepSeek Harness(DSH)** 与中国科大 **「词元工坊」**(校方 DSH-based 应用)。
5
+ - 「这周我有哪些课和考试?还有什么作业没交?」
6
+ - 「帮我报名这个二课」「帮我约一间研讨室」(提交前会先请你确认)
7
+ - 「今晚东区到西区还有班车吗?」
8
+ - 「去也西书架找找这门课的资料」
6
9
 
7
- 不用记住教务、Blackboard、青春科大还是图书馆各自在哪里——在对话里直接说需求,AI 就能帮你查课表、交作业、约研讨室、报二课、查班车;侧栏「校园」工作台同步提供周历、资讯流与校务速查。
10
+ 登录学校账号后,教务课表、考试、已报名的二课、西区/高新图书馆已确认的预约,以及能读到明确时间的 Blackboard 作业截止点,会自动出现在同一张周历里。还没报名的公开活动可以在「资讯」里手动收藏到日程;待审核或已取消的图书馆预约不会进入周历。
8
11
 
9
12
  ## 安装与卸载
10
13
 
11
14
  在桌面端侧栏进入 **「插件」→「添加插件」**,支持以下三种方式安装,启用后在左侧栏打开 **「校园」** 即可使用:
12
15
 
13
- 1. **npm 包名(最推荐,支持自动检查更新)**
14
- 直接输入包名:
16
+ 1. **GitHub 仓库网址(推荐,直接安装仓库当前版本)**
17
+ 在「添加插件」中粘贴:
15
18
  ```text
16
- dsh-ustc-campus
19
+ https://github.com/TwinJades/dsh-ustc-campus
17
20
  ```
18
- 2. **GitHub 仓库网址**
21
+ 这种方式不用等 npm 新版开放安装或镜像同步。需能访问 GitHub;若 DSH 提示需要运行构建脚本,确认信任本仓库后允许并重试。通过仓库网址安装时,插件页不会自动检查更新。
22
+ 2. **npm 包名(支持检查更新)**
23
+ 在「添加插件」中输入:
19
24
  ```text
20
- https://github.com/TwinJades/dsh-ustc-campus
25
+ dsh-ustc-campus
21
26
  ```
22
- > 需本机能够直接连通 GitHub(或已配置 GitHub 访问代理);通过仓库网址安装时,插件页不会自动检测新版本。
27
+ 新版刚发布时,DSH 的安装安全等待期或 npm 镜像同步延迟可能让你装到旧版。如果想立即装某个已发布的版本,可以在「添加插件」里选 **npm 官方源**,输入 `dsh-ustc-campus@版本号`。
23
28
  3. **本地地址(离线 / 本地开发)**
24
29
  - **离线包**:前往 [GitHub Releases](https://github.com/TwinJades/dsh-ustc-campus/releases) 下载 `.tgz` 压缩包,在添加插件时填入该 `.tgz` 文件的**完整本地路径**。
25
30
  - **本地源码**:克隆仓库并执行 `npm ci && npm run build` 后,填入项目目录的**完整本地路径**。
26
31
 
32
+ **也可以让 AI 帮你装。** 把这句话发给 DeepSeek Harness 里的 AI:
33
+
34
+ > 请从 GitHub 仓库 `https://github.com/TwinJades/dsh-ustc-campus` 安装并启用「科大校园工作台」。如果需要我确认运行构建脚本或重启,请先告诉我。装好后告诉我从哪里打开「校园」。
35
+
27
36
  ### 使用提醒
28
37
 
29
38
  - **非官方声明**:本插件为独立开源项目,**非中国科学技术大学或 DeepSeek 官方产品**。
@@ -42,15 +51,37 @@
42
51
  - **西区 & 高新图书馆**:查空间分类、开放规则与实时占用,支持按时段/房号在对话中确认预约研讨室与取消(高新)。
43
52
  - **校园班车 & 资料检索**:查询东/西/南/北/中/高新/先研院/太湖路班车时刻(内置法定节假日与调休年表),以及「也西书架」公开课程资料索引。
44
53
  - **侧栏 MD3 校园工作台**:
45
- - **日程**:北京时间周视图整合官方课表、考试、已报二课与本地待办/便笺,支持导入本地 `.ics` 课表并存显示。
54
+ - **日程**:北京时间周历,自动同步与排除范围见开头说明。也可导入 `.ics`、新建本地待办和便笺,或在资讯页把尚未报名的活动「收藏到日程」。
46
55
  - **资讯**:聚合 25 个科大官方公开资讯源并融合青春科大报名中二课,支持按活动/通知/分类/来源筛选、分页浏览与自定义 `https://` RSS/JSON 订阅。
47
56
  - **校务**:班车速查、近期考试安排、常用校内系统直达,以及默认隐藏、点击弹窗查看的「成绩与绩点」隐私卡片。
48
57
  - **对话内嵌小卡片**:工具调用期间与结束后会在对话中直接渲染课程、班车、待办、作业提交与预约回执小卡片,可一键跳转校务页或核对官方链接。
49
58
 
59
+ ## 界面截图
60
+
61
+ ### 对话功能介绍
62
+
63
+ ![在 DeepSeek Harness 对话中介绍校园插件能办的事](docs/campus-chat-overview.png)
64
+
65
+ ![询问今天上午有什么活动:对话汇总已报名二课的时间、地点和提醒](docs/campus-chat-today.png)
66
+
67
+ ![询问最近有什么有趣的二课:对话整理活动时间、报名余量和冲突](docs/campus-chat-youth.png)
68
+
69
+ ### 日程
70
+
71
+ ![校园周历:作者的个人课表已遮盖,保留二课活动](docs/campus-schedule-redacted.png)
72
+
73
+ ### 资讯
74
+
75
+ ![校园资讯页:活动、通知和报名中的二课](docs/campus-feed.png)
76
+
77
+ ### 校务
78
+
79
+ ![校务页:校园班车、近期考试与常用系统入口](docs/campus-services.png)
80
+
50
81
  ## 当前局限性说明
51
82
 
52
83
  > [!NOTE]
53
- > 当前上线的是 **Demo 版本**,整体仍有很大进步空间:
84
+ > 当前是 **Demo 版本**,整体仍有很大进步空间:
54
85
  > - **AI 对话查办校务**部分(课表、作业、二课、图书馆、班车、日程)已基本完善并经真账号反复打磨;
55
86
  > - **校园资讯**部分目前体验还不够好(数据源覆盖、展示交互与个性化推荐仍在持续优化中)。
56
87
 
package/dist/client.js CHANGED
@@ -75,7 +75,9 @@ var INTERESTS_STORAGE_KEY = "ustc-campus.interests";
75
75
  var KIND_LABELS = Object.freeze({
76
76
  course: "\u8BFE\u7A0B",
77
77
  exam: "\u8003\u8BD5",
78
+ deadline: "\u4F5C\u4E1A\u622A\u6B62",
78
79
  event: "\u6D3B\u52A8",
80
+ reservation: "\u56FE\u4E66\u9986\u9884\u7EA6",
79
81
  task: "\u5F85\u529E",
80
82
  note: "\u4FBF\u7B3A"
81
83
  });
@@ -377,6 +379,14 @@ var material = `
377
379
  --uc-l-on-warning-container: #2B1700;
378
380
  --uc-d-on-warning-container: #FFDDB6;
379
381
 
382
+ /* Calendar exam palette */
383
+ --uc-l-exam: #705900;
384
+ --uc-d-exam: #FFDA57;
385
+ --uc-l-exam-container: #FFE789;
386
+ --uc-d-exam-container: #554500;
387
+ --uc-l-on-exam-container: #251A00;
388
+ --uc-d-on-exam-container: #FFE789;
389
+
380
390
  /* Surface & Neutral Hierarchy */
381
391
  --uc-l-surface: #F9F9FF;
382
392
  --uc-d-surface: #11131A;
@@ -447,6 +457,9 @@ var material = `
447
457
  --md-sys-color-on-warning: var(--uc-l-on-warning);
448
458
  --md-sys-color-warning-container: var(--uc-l-warning-container);
449
459
  --md-sys-color-on-warning-container: var(--uc-l-on-warning-container);
460
+ --md-sys-color-exam: var(--uc-l-exam);
461
+ --md-sys-color-exam-container: var(--uc-l-exam-container);
462
+ --md-sys-color-on-exam-container: var(--uc-l-on-exam-container);
450
463
  --md-sys-color-surface: var(--uc-l-surface);
451
464
  --md-sys-color-surface-dim: var(--uc-l-surface-dim);
452
465
  --md-sys-color-surface-bright: var(--uc-l-surface-bright);
@@ -547,6 +560,9 @@ var material = `
547
560
  --md-sys-color-on-warning: var(--uc-d-on-warning);
548
561
  --md-sys-color-warning-container: var(--uc-d-warning-container);
549
562
  --md-sys-color-on-warning-container: var(--uc-d-on-warning-container);
563
+ --md-sys-color-exam: var(--uc-d-exam);
564
+ --md-sys-color-exam-container: var(--uc-d-exam-container);
565
+ --md-sys-color-on-exam-container: var(--uc-d-on-exam-container);
550
566
  --md-sys-color-surface: var(--uc-d-surface);
551
567
  --md-sys-color-surface-dim: var(--uc-d-surface-dim);
552
568
  --md-sys-color-surface-bright: var(--uc-d-surface-bright);
@@ -596,6 +612,9 @@ var material = `
596
612
  --md-sys-color-on-warning: light-dark(var(--uc-l-on-warning), var(--uc-d-on-warning));
597
613
  --md-sys-color-warning-container: light-dark(var(--uc-l-warning-container), var(--uc-d-warning-container));
598
614
  --md-sys-color-on-warning-container: light-dark(var(--uc-l-on-warning-container), var(--uc-d-on-warning-container));
615
+ --md-sys-color-exam: light-dark(var(--uc-l-exam), var(--uc-d-exam));
616
+ --md-sys-color-exam-container: light-dark(var(--uc-l-exam-container), var(--uc-d-exam-container));
617
+ --md-sys-color-on-exam-container: light-dark(var(--uc-l-on-exam-container), var(--uc-d-on-exam-container));
599
618
  --md-sys-color-surface: light-dark(var(--uc-l-surface), var(--uc-d-surface));
600
619
  --md-sys-color-surface-dim: light-dark(var(--uc-l-surface-dim), var(--uc-d-surface-dim));
601
620
  --md-sys-color-surface-bright: light-dark(var(--uc-l-surface-bright), var(--uc-d-surface-bright));
@@ -1815,9 +1834,9 @@ dialog.uc-dialog[open]::backdrop {
1815
1834
  }
1816
1835
 
1817
1836
  .uc-event-block[data-kind="exam"] {
1818
- background: var(--md-sys-color-error-container);
1819
- color: var(--md-sys-color-on-error-container);
1820
- border-inline-start-color: var(--md-sys-color-error);
1837
+ background: var(--md-sys-color-exam-container);
1838
+ color: var(--md-sys-color-on-exam-container);
1839
+ border-inline-start-color: var(--md-sys-color-exam);
1821
1840
  }
1822
1841
 
1823
1842
  .uc-event-block[data-kind="event"] {
@@ -1826,6 +1845,41 @@ dialog.uc-dialog[open]::backdrop {
1826
1845
  border-inline-start-color: var(--md-sys-color-tertiary);
1827
1846
  }
1828
1847
 
1848
+ .uc-event-block[data-kind="deadline"] {
1849
+ --uc-point-color: var(--md-sys-color-error);
1850
+ border-inline-start: 0;
1851
+ background: transparent;
1852
+ color: var(--md-sys-color-on-error-container);
1853
+ justify-content: center;
1854
+ min-inline-size: 24px;
1855
+ padding: 0;
1856
+ }
1857
+
1858
+ .uc-event-block[data-kind="deadline"]::before {
1859
+ content: '';
1860
+ position: absolute;
1861
+ inset-inline: 0;
1862
+ top: min(var(--uc-deadline-marker), calc(100% - 2px));
1863
+ border-block-start: 2px solid var(--uc-point-color);
1864
+ }
1865
+
1866
+ .uc-event-block[data-kind="deadline"] .uc-event-title {
1867
+ z-index: 1;
1868
+ align-self: flex-start;
1869
+ max-inline-size: 100%;
1870
+ box-sizing: border-box;
1871
+ padding: 1px 3px;
1872
+ border-radius: var(--md-sys-shape-corner-extra-small);
1873
+ background: var(--md-sys-color-error-container);
1874
+ }
1875
+
1876
+ .uc-event-block[data-kind="deadline"]:focus-visible {
1877
+ outline: 2px solid var(--uc-point-color);
1878
+ outline-offset: -2px;
1879
+ z-index: 3;
1880
+ }
1881
+
1882
+ .uc-event-block[data-kind="reservation"],
1829
1883
  .uc-event-block[data-kind="task"] {
1830
1884
  background: var(--md-sys-color-success-container);
1831
1885
  color: var(--md-sys-color-on-success-container);
@@ -2584,6 +2638,7 @@ var import_react3 = __toESM(require("react"), 1);
2584
2638
  var DAY = 864e5;
2585
2639
  var MINUTE = 6e4;
2586
2640
  var HOUR = 60;
2641
+ var POINT_TARGET = 24;
2587
2642
  function layoutWeek(weekUtc, entries) {
2588
2643
  const first = weekUtc - 8 * HOUR * MINUTE;
2589
2644
  let start = 8 * HOUR, end = 22 * HOUR;
@@ -2596,6 +2651,14 @@ function layoutWeek(weekUtc, entries) {
2596
2651
  if (item.date === date) day.untimed.push(item);
2597
2652
  continue;
2598
2653
  }
2654
+ if (item.kind === "deadline") {
2655
+ if (item.start < midnight || item.start >= next) continue;
2656
+ const point = (item.start - midnight) / MINUTE;
2657
+ const from2 = Math.min(point, 24 * HOUR - POINT_TARGET);
2658
+ start = Math.min(start, Math.floor(from2 / HOUR) * HOUR);
2659
+ day.timed.push({ item, from: from2, through: point, point });
2660
+ continue;
2661
+ }
2599
2662
  const finish = Math.max(item.end ?? item.start, item.start + 1);
2600
2663
  if (item.start >= next || finish <= midnight) continue;
2601
2664
  if (item.allDay) {
@@ -2618,7 +2681,7 @@ function layoutWeek(weekUtc, entries) {
2618
2681
  }
2619
2682
  for (const block of day.timed) {
2620
2683
  if (block.from >= clusterEnd) finishCluster();
2621
- block.visualEnd = Math.min(24 * HOUR, Math.max(block.through, block.from + 24));
2684
+ block.visualEnd = Math.min(24 * HOUR, Math.max(block.through, block.from + POINT_TARGET));
2622
2685
  const free = lanes.findIndex((value) => value <= block.from);
2623
2686
  block.lane = free < 0 ? lanes.length : free;
2624
2687
  lanes[block.lane] = block.visualEnd;
@@ -3289,6 +3352,26 @@ function AgendaView({
3289
3352
  } else if (agenda.youth?.state === "failure") {
3290
3353
  chips.push({ tone: "warning", text: "\u4E8C\u8BFE\u540C\u6B65\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u5237\u65B0" });
3291
3354
  }
3355
+ const assignments = agenda.assignments;
3356
+ if (assignments?.state === "ok" || assignments?.state === "partial") {
3357
+ const count = agenda.entries.filter((entry) => entry.kind === "deadline").length;
3358
+ chips.push({
3359
+ tone: assignments.complete ? "secondary" : "warning",
3360
+ text: `\u672C\u5468 BB \u4F5C\u4E1A\u622A\u6B62\uFF1A${count} \u9879${assignments.complete ? "" : "\uFF08\u90E8\u5206\uFF09"}`
3361
+ });
3362
+ } else if (assignments?.state === "unavailable" || assignments?.state === "not_connected" && agenda.school?.state === "connected" && !agenda.syncing) {
3363
+ chips.push({ tone: "warning", text: "\u6682\u65F6\u65E0\u6CD5\u540C\u6B65 BB \u4F5C\u4E1A\uFF0C\u8BF7\u7A0D\u540E\u5237\u65B0" });
3364
+ }
3365
+ const reservations = agenda.reservations;
3366
+ if (reservations?.count) {
3367
+ const count = agenda.entries.filter((entry) => entry.kind === "reservation").length;
3368
+ chips.push({
3369
+ tone: reservations.complete ? "tertiary" : "warning",
3370
+ text: `\u672C\u5468\u56FE\u4E66\u9986\u9884\u7EA6\uFF1A${count} \u9879${reservations.complete ? "" : "\uFF08\u90E8\u5206\uFF09"}`
3371
+ });
3372
+ } else if (reservations && !reservations.complete && !agenda.syncing && agenda.school?.state === "connected") {
3373
+ chips.push({ tone: "warning", text: "\u56FE\u4E66\u9986\u9884\u7EA6\u672A\u540C\u6B65\u5B8C\u6574\uFF0C\u8BF7\u7A0D\u540E\u5237\u65B0" });
3374
+ }
3292
3375
  if (agenda.truncated) {
3293
3376
  chips.push({ tone: "warning", text: "\u90E8\u5206\u65E5\u7A0B\u672A\u5B8C\u6574\u5C55\u5F00" });
3294
3377
  }
@@ -3300,15 +3383,15 @@ function AgendaView({
3300
3383
  const mfa = schoolStatus?.reason === "mfa";
3301
3384
  return {
3302
3385
  tone: mfa ? "warning" : "info",
3303
- text: mfa ? "\u5B66\u6821\u8D26\u53F7\u9700\u8981\u672C\u4EBA\u9A8C\u8BC1\uFF0C\u8BF7\u5728\u5B66\u6821\u6D4F\u89C8\u5668\u5B8C\u6210\u9A8C\u8BC1\u3002" : "\u6B63\u5728\u540E\u53F0\u767B\u5F55\u5B66\u6821\u8D26\u53F7\u5E76\u540C\u6B65\u8BFE\u8868\u2026",
3386
+ text: mfa ? "\u5B66\u6821\u8D26\u53F7\u9700\u8981\u672C\u4EBA\u9A8C\u8BC1\uFF0C\u8BF7\u5728\u5B66\u6821\u6D4F\u89C8\u5668\u5B8C\u6210\u9A8C\u8BC1\u3002" : "\u6B63\u5728\u540E\u53F0\u767B\u5F55\u5B66\u6821\u8D26\u53F7\u5E76\u540C\u6B65\u65E5\u7A0B\u2026",
3304
3387
  actionLabel: mfa ? "\u5904\u7406\u9A8C\u8BC1" : "\u67E5\u770B\u72B6\u6001"
3305
3388
  };
3306
3389
  }
3307
3390
  if (st === "expired") {
3308
- return { tone: "error", text: "\u5B66\u6821\u767B\u5F55\u5DF2\u5931\u6548\uFF0C\u91CD\u65B0\u767B\u5F55\u540E\u53EF\u540C\u6B65\u6559\u52A1\u8BFE\u8868\u3001\u8003\u8BD5\u4E0E\u4E8C\u8BFE\u3002", actionLabel: "\u91CD\u65B0\u767B\u5F55" };
3391
+ return { tone: "error", text: "\u5B66\u6821\u767B\u5F55\u5DF2\u5931\u6548\uFF0C\u91CD\u65B0\u767B\u5F55\u540E\u53EF\u6062\u590D\u65E5\u7A0B\u540C\u6B65\u3002", actionLabel: "\u91CD\u65B0\u767B\u5F55" };
3309
3392
  }
3310
3393
  if (st === "signed_out") {
3311
- return { tone: "info", text: "\u767B\u5F55\u5B66\u6821\u8D26\u53F7\u540E\u53EF\u81EA\u52A8\u540C\u6B65\u5B98\u65B9\u6559\u52A1\u8BFE\u8868\u3001\u8003\u8BD5\u5B89\u6392\u4E0E\u4E8C\u8BFE\u62A5\u540D\u3002", actionLabel: "\u767B\u5F55\u5B66\u6821\u8D26\u53F7" };
3394
+ return { tone: "info", text: "\u767B\u5F55\u5B66\u6821\u8D26\u53F7\u540E\u81EA\u52A8\u540C\u6B65\u8BFE\u8868\u3001\u8003\u8BD5\u3001\u5DF2\u62A5\u540D\u4E8C\u8BFE\u3001\u56FE\u4E66\u9986\u9884\u7EA6\u548C BB \u4F5C\u4E1A\u622A\u6B62\u65F6\u95F4\u3002", actionLabel: "\u767B\u5F55\u5B66\u6821\u8D26\u53F7" };
3312
3395
  }
3313
3396
  return null;
3314
3397
  }, [agenda?.school?.state, schoolStatus]);
@@ -3469,7 +3552,9 @@ function AgendaView({
3469
3552
  day.timed.map((block) => {
3470
3553
  const item = block.item;
3471
3554
  const itemDate = item.start == null ? item.date : shIsoDate(item.start);
3555
+ const deadline = item.kind === "deadline";
3472
3556
  const clock = shClock(item.start);
3557
+ const label = deadline ? `${clock} \u622A\u6B62 \xB7 ${item.title}` : item.title;
3473
3558
  return /* @__PURE__ */ import_react3.default.createElement(
3474
3559
  "button",
3475
3560
  {
@@ -3478,10 +3563,12 @@ function AgendaView({
3478
3563
  className: "uc-event-block",
3479
3564
  "data-kind": item.kind,
3480
3565
  "data-done": item.done ? "true" : void 0,
3481
- title: [item.title, clock, item.location].filter(Boolean).join(" \xB7 "),
3566
+ "aria-label": deadline ? [label, itemDate, item.courseTitle].filter(Boolean).join(" \xB7 ") : void 0,
3567
+ title: deadline ? [label, item.courseTitle].filter(Boolean).join(" \xB7 ") : [item.title, clock, item.location].filter(Boolean).join(" \xB7 "),
3482
3568
  style: {
3483
3569
  top: block.from - weekLayout.start,
3484
- height: Math.max(22, block.visualEnd - block.from),
3570
+ height: deadline ? 24 : Math.max(22, block.visualEnd - block.from),
3571
+ ...deadline && { "--uc-deadline-marker": `${block.point - block.from}px` },
3485
3572
  insetInlineStart: `${block.lane / block.lanes * 100}%`,
3486
3573
  width: `calc(${100 / block.lanes}% - 3px)`
3487
3574
  },
@@ -3490,8 +3577,8 @@ function AgendaView({
3490
3577
  setDetailTarget({ item, date: itemDate });
3491
3578
  }
3492
3579
  },
3493
- /* @__PURE__ */ import_react3.default.createElement("span", { className: "uc-event-title" }, item.title),
3494
- /* @__PURE__ */ import_react3.default.createElement("span", { className: "uc-event-meta uc-tabular" }, [clock, item.location].filter(Boolean).join(" \xB7 "))
3580
+ /* @__PURE__ */ import_react3.default.createElement("span", { className: "uc-event-title" }, label),
3581
+ deadline ? null : /* @__PURE__ */ import_react3.default.createElement("span", { className: "uc-event-meta uc-tabular" }, [clock, item.location].filter(Boolean).join(" \xB7 "))
3495
3582
  );
3496
3583
  })
3497
3584
  );
@@ -3611,7 +3698,7 @@ function ItemDetailDialog({ target, onClose, onEdit, onRequestRemove }) {
3611
3698
  item.school ? "\u9690\u85CF\u8FD9\u4E00\u6B21" : "\u79FB\u9664"
3612
3699
  ), item.personal ? /* @__PURE__ */ import_react3.default.createElement(MdButton, { variant: "outlined", onClick: () => onEdit(item) }, "\u7F16\u8F91") : null, /* @__PURE__ */ import_react3.default.createElement(MdButton, { variant: "tonal", onClick: onClose }, "\u5173\u95ED")) : null
3613
3700
  },
3614
- item ? removedView ? /* @__PURE__ */ import_react3.default.createElement("p", { className: "uc-muted", style: { margin: 0 } }, "\u5DF2\u4ECE\u672C\u5730\u65E5\u5386\u79FB\u9664\u3002\u5B66\u6821\u6216\u539F\u59CB\u5BFC\u5165\u6587\u4EF6\u672A\u66F4\u6539\u3002") : /* @__PURE__ */ import_react3.default.createElement("div", { style: { display: "flex", flexDirection: "column", gap: 10 } }, /* @__PURE__ */ import_react3.default.createElement("div", { className: "uc-chip-row" }, /* @__PURE__ */ import_react3.default.createElement(MdBadge, { tone: "primary" }, KIND_LABELS[item.kind] ?? "\u4E8B\u9879"), item.source ? /* @__PURE__ */ import_react3.default.createElement(MdBadge, { tone: "neutral" }, item.source) : null, item.done ? /* @__PURE__ */ import_react3.default.createElement(MdBadge, { tone: "success" }, "\u5DF2\u5B8C\u6210") : null), date || when ? /* @__PURE__ */ import_react3.default.createElement("div", { className: "uc-tabular", style: { fontSize: "var(--md-sys-typescale-body-medium-size)" } }, [date, when].filter(Boolean).join(" \xB7 ")) : null, item.location ? /* @__PURE__ */ import_react3.default.createElement("div", { className: "uc-muted" }, "\u5730\u70B9\uFF1A", item.location) : null, item.notes ? /* @__PURE__ */ import_react3.default.createElement("div", { className: "uc-surface-card", style: { whiteSpace: "pre-wrap", overflowWrap: "anywhere" } }, item.notes) : null, item.url ? /* @__PURE__ */ import_react3.default.createElement("div", null, /* @__PURE__ */ import_react3.default.createElement(SafeLink, { href: item.url }, "\u67E5\u770B\u6765\u6E90\u8BE6\u60C5")) : null) : null
3701
+ item ? removedView ? /* @__PURE__ */ import_react3.default.createElement("p", { className: "uc-muted", style: { margin: 0 } }, "\u5DF2\u4ECE\u672C\u5730\u65E5\u5386\u79FB\u9664\u3002\u5B66\u6821\u6216\u539F\u59CB\u5BFC\u5165\u6587\u4EF6\u672A\u66F4\u6539\u3002") : /* @__PURE__ */ import_react3.default.createElement("div", { style: { display: "flex", flexDirection: "column", gap: 10 } }, /* @__PURE__ */ import_react3.default.createElement("div", { className: "uc-chip-row" }, /* @__PURE__ */ import_react3.default.createElement(MdBadge, { tone: "primary" }, KIND_LABELS[item.kind] ?? "\u4E8B\u9879"), item.source ? /* @__PURE__ */ import_react3.default.createElement(MdBadge, { tone: "neutral" }, item.source) : null, item.done ? /* @__PURE__ */ import_react3.default.createElement(MdBadge, { tone: "success" }, "\u5DF2\u5B8C\u6210") : null), date || when ? /* @__PURE__ */ import_react3.default.createElement("div", { className: "uc-tabular", style: { fontSize: "var(--md-sys-typescale-body-medium-size)" } }, [date, when].filter(Boolean).join(" \xB7 ")) : null, item.courseTitle ? /* @__PURE__ */ import_react3.default.createElement("div", { className: "uc-muted" }, "\u8BFE\u7A0B\uFF1A", item.courseTitle) : null, item.location ? /* @__PURE__ */ import_react3.default.createElement("div", { className: "uc-muted" }, "\u5730\u70B9\uFF1A", item.location) : null, item.notes ? /* @__PURE__ */ import_react3.default.createElement("div", { className: "uc-surface-card", style: { whiteSpace: "pre-wrap", overflowWrap: "anywhere" } }, item.notes) : null, item.url ? /* @__PURE__ */ import_react3.default.createElement("div", null, /* @__PURE__ */ import_react3.default.createElement(SafeLink, { href: item.url }, item.kind === "deadline" ? "\u6253\u5F00 Blackboard" : "\u67E5\u770B\u6765\u6E90\u8BE6\u60C5")) : null) : null
3615
3702
  );
3616
3703
  }
3617
3704
  function RemoveConfirmDialog({ target, onClose, onRemoved }) {
@@ -5955,6 +6042,10 @@ function ReceiptToolCard(props) {
5955
6042
  const parsed = parseToolCallProps(props);
5956
6043
  const { phase, toolName, data, rawText, isError, errorText } = parsed;
5957
6044
  const isLoading = phase === "preparing" || phase === "start";
6045
+ const syncedPlan = !isError && !isLoading && data?.state === "verified" && (toolName === "campus_submit_youth_action" || toolName === "campus_submit_library_booking" || toolName === "campus_submit_hs_library") ? data.plan?.planId ?? data.planId : null;
6046
+ (0, import_react9.useEffect)(() => {
6047
+ if (syncedPlan) triggerAgendaRefresh();
6048
+ }, [syncedPlan]);
5958
6049
  if (isLoading && !data) {
5959
6050
  return /* @__PURE__ */ import_react9.default.createElement(
5960
6051
  CardShell,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ustc-campus",
3
- "version": "0.3.0",
3
+ "version": "0.3.3",
4
4
  "license": "AGPL-3.0-only",
5
5
  "description": "非官方科大校园工作台:在 DeepSeek Harness 中查询课表、作业、二课、图书馆与校园班车",
6
6
  "homepage": "https://github.com/TwinJades/dsh-ustc-campus#readme",
@@ -1,11 +1,14 @@
1
1
  import { join } from 'node:path';
2
2
  import { createSnapshotCache } from './snapshot-cache.mjs';
3
3
  import { localTime, YOUTH_SERVICE } from './youth.mjs';
4
+ import { DAY } from './calendar.mjs';
4
5
 
5
6
  const HOUR = 60 * 60_000;
6
7
  const RECOVERY_RETRY_MS = 60_000;
7
8
  const AGES = { timetable: 6 * HOUR, exams: 2 * HOUR, enrolled: HOUR / 2 };
8
9
  const AGENDA_KEYS = Object.keys(AGES);
10
+ const ASSIGNMENT_AGE = HOUR / 2;
11
+ const RESERVATION_AGE = 5 * 60_000;
9
12
  const EMPTY = { state: 'not_connected', complete: false, entries: [] };
10
13
  const NO_FEED = { extraItems: [], extraSources: [] };
11
14
  const usable = result => result?.state === 'ok' || result?.state === 'empty';
@@ -14,6 +17,16 @@ const TRANSIENT_STATES = new Set(['pending', 'not_connected', 'expired', 'signed
14
17
  const shouldBackoff = value => !TRANSIENT_STATES.has(value?.state);
15
18
  const inRange = (entry, from, through) => entry.date >= from && entry.date <= through;
16
19
 
20
+ function* westWeeks(from, through) {
21
+ const day = Date.parse(`${from}T00:00:00Z`);
22
+ const first = day - ((new Date(day).getUTCDay() + 6) % 7) * DAY;
23
+ const last = Date.parse(`${through}T00:00:00Z`);
24
+ for (let week = first; week <= last; week += 7 * DAY) {
25
+ const monday = new Date(week).toISOString().slice(0, 10);
26
+ yield { key: `library-west:${monday}`, from: monday, through: new Date(week + 6 * DAY).toISOString().slice(0, 10) };
27
+ }
28
+ }
29
+
17
30
  function toFeed(act) {
18
31
  const start = localTime(act.holdStart);
19
32
  const end = localTime(act.holdEnd);
@@ -31,7 +44,7 @@ function toFeed(act) {
31
44
  };
32
45
  }
33
46
 
34
- export function createAccountData({ dir, school, youth, createExams, now = Date.now }) {
47
+ export function createAccountData({ dir, school, youth, bb, libraryBooking, hsLibrary, createExams, now = Date.now }) {
35
48
  const cache = createSnapshotCache(join(dir, 'school-cache.json'), { now });
36
49
  if (!school.ownsCachedData()) cache.clear();
37
50
  const exams = createExams(cache);
@@ -41,6 +54,7 @@ export function createAccountData({ dir, school, youth, createExams, now = Date.
41
54
  let recoveryFailedAt = -Infinity;
42
55
  let titledSnapshot;
43
56
  let titles = [];
57
+ const supplementStatus = new Map();
44
58
  let lastSchoolState = school.status().state;
45
59
 
46
60
  function timetable(force) {
@@ -54,6 +68,41 @@ export function createAccountData({ dir, school, youth, createExams, now = Date.
54
68
  const refreshYouth = force => cache.refresh('enrolled', () => youth.read(), {
55
69
  maxAge: AGES.enrolled, force, accept: value => usableEnrollment(value, cache.get('enrolled')?.value), backoff: shouldBackoff
56
70
  });
71
+ function refreshSupplement(source, force) {
72
+ const { key, load, maxAge } = source;
73
+ return cache.refresh(key, async () => {
74
+ const owner = epoch;
75
+ let snapshot;
76
+ try { snapshot = await load(); }
77
+ catch (error) {
78
+ const disconnected = ['SCHOOL_NOT_CONNECTED', 'authentication_required'].includes(error?.code);
79
+ snapshot = { ...EMPTY, state: disconnected ? 'not_connected' : 'unavailable' };
80
+ }
81
+ if (owner === epoch) {
82
+ supplementStatus.delete(key);
83
+ if (supplementStatus.size >= 64) supplementStatus.delete(supplementStatus.keys().next().value);
84
+ supplementStatus.set(key, { state: snapshot.state, complete: snapshot.complete });
85
+ }
86
+ return snapshot;
87
+ }, { maxAge, force, accept: value => value?.complete || ((usable(value) || value?.state === 'partial')
88
+ && (key !== 'assignments' || !cache.get(key)?.value.complete)) });
89
+ }
90
+
91
+ const assignmentsSource = bb && { key: 'assignments', load: bb.agenda, maxAge: ASSIGNMENT_AGE };
92
+ const hsSource = hsLibrary && { key: 'library-hs', load: () => hsLibrary.agenda({}), maxAge: RESERVATION_AGE };
93
+ const westSource = window => ({ key: window.key, load: () => libraryBooking.agenda(window), maxAge: RESERVATION_AGE });
94
+
95
+ function refreshAfterWrite(key, load) {
96
+ const owner = epoch;
97
+ const pending = cache.syncing(key) && load(false);
98
+ const refresh = () => owner === epoch && !closed && load(true);
99
+ void (pending ? pending.then(refresh, refresh) : refresh()).catch(() => {});
100
+ }
101
+
102
+ function refreshReservations(campus, date) {
103
+ const source = campus === 'hs' ? hsSource : westSource(westWeeks(date, date).next().value);
104
+ refreshAfterWrite(source.key, force => refreshSupplement(source, force));
105
+ }
57
106
 
58
107
  function restoreSession() {
59
108
  if (restoring) return restoring;
@@ -80,18 +129,6 @@ export function createAccountData({ dir, school, youth, createExams, now = Date.
80
129
  if (cache.due('enrolled', AGES.enrolled)) refreshYouth(false).catch(() => {});
81
130
  }
82
131
 
83
- function revalidate(status) {
84
- if (status === 'connected') {
85
- refreshDue();
86
- } else if (!restoring && now() - recoveryFailedAt >= RECOVERY_RETRY_MS
87
- && AGENDA_KEYS.some(key => cache.due(key, AGES[key]))) {
88
- const owner = epoch;
89
- void restoreSession().then(connected => {
90
- if (connected && owner === epoch && !closed && school.status().state === 'connected') refreshDue();
91
- });
92
- }
93
- }
94
-
95
132
  async function timetableFor(data) {
96
133
  const owner = epoch;
97
134
  const cached = school.ownsCachedData() && cache.get('timetable')?.value;
@@ -111,14 +148,28 @@ export function createAccountData({ dir, school, youth, createExams, now = Date.
111
148
  lastSchoolState = status;
112
149
  const force = data.refresh === true;
113
150
  let syncing = false;
151
+ const reservationSources = [...(hsSource ? [hsSource] : []),
152
+ ...(libraryBooking ? Array.from(westWeeks(from, through), westSource) : [])];
153
+ const supplements = assignmentsSource ? [assignmentsSource, ...reservationSources] : reservationSources;
154
+ const reads = [];
155
+ function syncSupplements() {
156
+ for (const source of supplements) {
157
+ if (force) reads.push(refreshSupplement(source, true));
158
+ else if (cache.due(source.key, source.maxAge)) void refreshSupplement(source, false);
159
+ }
160
+ }
114
161
  if (!closed && status !== 'pending' && (force || !hit)) {
115
162
  if (status === 'connected' || (force && owned) || (await school.credentialStatus()).enabled) {
116
163
  if (owner === epoch) {
117
164
  const liveReady = typeof school.isLive === 'function' ? school.isLive() : status === 'connected';
118
165
  if (status !== 'connected' || (!hit && !liveReady)) {
119
166
  const schoolData = await timetable(force);
120
- rows = [schoolData, ...(owner === epoch && schoolData?.state === 'ok' ? await Promise.all([refreshExams(force), refreshYouth(force)]) : [])];
167
+ if (owner === epoch && (schoolData?.state === 'ok' || school.status().state === 'connected')) {
168
+ syncSupplements();
169
+ rows = [schoolData, ...await Promise.all([refreshExams(force), refreshYouth(force)])];
170
+ } else rows = [schoolData];
121
171
  } else {
172
+ syncSupplements();
122
173
  rows = await Promise.all([timetable(force), refreshExams(force), refreshYouth(force)]);
123
174
  }
124
175
  if (owner === epoch && owned) rows = AGENDA_KEYS.map((key, i) => {
@@ -129,22 +180,54 @@ export function createAccountData({ dir, school, youth, createExams, now = Date.
129
180
  }
130
181
  }
131
182
  } else if (!closed && hit) {
132
- if (status !== 'pending') revalidate(status);
183
+ const refreshAll = () => {
184
+ refreshDue();
185
+ syncSupplements();
186
+ };
187
+ if (status === 'connected') refreshAll();
188
+ else if (status !== 'pending' && (restoring || (now() - recoveryFailedAt >= RECOVERY_RETRY_MS
189
+ && (AGENDA_KEYS.some(key => cache.due(key, AGES[key]))
190
+ || supplements.some(({ key, maxAge }) => cache.due(key, maxAge)))))) {
191
+ void restoreSession().then(connected => {
192
+ if (connected && owner === epoch && !closed && school.status().state === 'connected') {
193
+ if (lastSchoolState !== 'connected') cache.clearFailures();
194
+ lastSchoolState = 'connected';
195
+ refreshAll();
196
+ }
197
+ });
198
+ }
133
199
  syncing = Boolean(restoring) || AGENDA_KEYS.some(key => cache.syncing(key));
134
200
  }
135
201
 
136
- if (owner !== epoch || closed) rows = [];
202
+ if (force) await Promise.all(reads);
203
+ const current = owner === epoch && !closed;
204
+ if (!current) rows = [];
205
+ syncing ||= current && (Boolean(restoring) || supplements.some(source => cache.syncing(source.key)));
206
+ const visible = current && school.ownsCachedData();
207
+ function supplemental(source) {
208
+ if (!visible || !source) return EMPTY;
209
+ const cached = cache.get(source.key)?.value ?? EMPTY;
210
+ const last = supplementStatus.get(source.key);
211
+ return last ? { ...last, entries: cached.entries } : cached;
212
+ }
137
213
  const [schoolData, exam = EMPTY, enrolled = EMPTY] = rows;
138
214
  const course = schoolData && school.sliceAgenda(schoolData, { from, through });
139
215
  const examRows = exam.entries.filter(entry => inRange(entry, from, through));
140
216
  const youthRows = enrolled.entries.filter(entry => inRange(entry, from, through));
217
+ const assignments = supplemental(assignmentsSource);
218
+ const deadlines = assignments.entries.filter(entry => inRange(entry, from, through));
219
+ const bookings = reservationSources.map(supplemental);
220
+ const reservationRows = bookings.flatMap(snapshot => snapshot.entries.filter(entry => inRange(entry, from, through)));
141
221
  return {
142
222
  school: { state: course?.state ?? school.status().state, complete: course?.complete ?? false },
143
223
  exams: { state: usable(exam) ? examRows.length ? 'ok' : 'empty' : exam.state, complete: exam.complete },
144
224
  youth: { state: enrolled.state, complete: enrolled.complete, verifiedCount: youthRows.length },
145
- schoolEntries: [...(course?.entries ?? []), ...examRows, ...youthRows],
146
- stale: owner === epoch && hit && !force,
147
- syncing: owner === epoch && syncing,
225
+ assignments: { state: deadlines.length ? 'ok' : usable(assignments) ? assignments.complete ? 'empty' : 'partial' : assignments.state,
226
+ complete: assignments.complete },
227
+ reservations: { count: reservationRows.length, complete: bookings.every(snapshot => snapshot.complete) },
228
+ schoolEntries: [...(course?.entries ?? []), ...examRows, ...youthRows, ...deadlines, ...reservationRows],
229
+ stale: current && !force && (hit || syncing),
230
+ syncing: current && syncing,
148
231
  cachedAt: school.ownsCachedData() ? cache.get('timetable')?.at ?? null : null
149
232
  };
150
233
  }
@@ -175,13 +258,15 @@ export function createAccountData({ dir, school, youth, createExams, now = Date.
175
258
  }, { maxAge: 5 * 60_000, force, accept: Boolean });
176
259
  }
177
260
 
178
- return { cache, exams, agenda, timetableFor, courseTitles, feed, refreshFeed,
261
+ return { cache, exams, agenda, timetableFor, courseTitles, feed, refreshFeed, refreshReservations,
262
+ refreshEnrollment: () => refreshAfterWrite('enrolled', refreshYouth),
179
263
  invalidate() {
180
264
  epoch++;
181
265
  restoring = undefined;
182
266
  recoveryFailedAt = -Infinity;
183
267
  lastSchoolState = 'signed_out';
184
268
  titledSnapshot = undefined;
269
+ supplementStatus.clear();
185
270
  titles = [];
186
271
  cache.clear();
187
272
  },
package/src/bb.mjs CHANGED
@@ -25,6 +25,7 @@ import { join } from 'node:path';
25
25
  import { DatabaseSync } from 'node:sqlite';
26
26
  import { load } from 'cheerio';
27
27
  import { mapLimited } from './concurrency.mjs';
28
+ import { shanghaiEpoch } from './public-fetch.mjs';
28
29
 
29
30
  export const BB_ORIGIN = 'https://www.bb.ustc.edu.cn';
30
31
  export const BB_PORTAL_PATH = '/webapps/portal/execute/tabs/tabAction?tab_tab_group_id=_1_1';
@@ -65,6 +66,7 @@ const APPROVAL_LEASE_MS = 120_000; // Longer than the conversation approval time
65
66
  const REQUEST_TIMEOUT_MS = 12_000;
66
67
  const REVIEW_TIMEOUT_MS = 8_000;
67
68
  const HISTORY_TIMEOUT_MS = 30_000;
69
+ const AGENDA_SCAN_MS = 18_000;
68
70
  const MAX_REDIRECTS = 5;
69
71
  const SENSITIVE_QUERY = ['nonce', 'csrf', 'session', 'password', 'ticket', 'token'];
70
72
  const PHASE_RANK = new Map(BB_PHASES.map((phase, index) => [phase, index]));
@@ -200,17 +202,19 @@ function requestContext(context) {
200
202
  }
201
203
 
202
204
 
203
- async function fetchPage(context, rawUrl, { timeout = REQUEST_TIMEOUT_MS } = {}) {
205
+ async function fetchPage(context, rawUrl, { timeout = REQUEST_TIMEOUT_MS, stopAt = Infinity } = {}) {
204
206
  const request = requestContext(context);
205
207
  let url = safeUrl(rawUrl);
206
208
  for (let redirects = 0; redirects <= MAX_REDIRECTS; redirects += 1) {
209
+ const remaining = Math.ceil(stopAt - performance.now());
210
+ requireValue(remaining > 0, 'BB 读取超时,请稍后重试。', 'upstream_error');
207
211
  assertReadablePath(url);
208
212
  let response;
209
213
  try {
210
214
  response = await request.get(url.href, {
211
215
  maxRedirects: 0,
212
216
  failOnStatusCode: false,
213
- timeout
217
+ timeout: Math.min(timeout, remaining)
214
218
  });
215
219
  } catch (error) {
216
220
  const message = error && /timeout/i.test(String(error.message))
@@ -360,7 +364,7 @@ function parseAssignments(html, courseId) {
360
364
  return assignments;
361
365
  }
362
366
 
363
- async function listAssignmentsInternal(context, courseId, maxPages, limit, checkStatus = false) {
367
+ async function listAssignmentsInternal(context, courseId, maxPages, limit, checkStatus = false, stopAt = Infinity) {
364
368
  requireValue(typeof courseId === 'string' && ID.test(courseId), '请使用有效的 BB 课程 ID。');
365
369
  requireValue(Number.isSafeInteger(maxPages) && maxPages >= 1 && maxPages <= 15,
366
370
  'maxPages 必须为 1–15 的整数。');
@@ -368,7 +372,7 @@ async function listAssignmentsInternal(context, courseId, maxPages, limit, check
368
372
  'limit 必须为 1–50 的整数。');
369
373
  requireValue(typeof checkStatus === 'boolean', 'checkStatus 必须为布尔值。');
370
374
  const launcher = `/webapps/blackboard/execute/launcher?type=Course&id=${encodeURIComponent(courseId)}`;
371
- const entry = await fetchPage(context, launcher);
375
+ const entry = await fetchPage(context, launcher, { stopAt });
372
376
  const queue = [];
373
377
  for (const path of parseMenuLinks(entry.text, courseId)) {
374
378
  const url = safeUrl(path);
@@ -385,7 +389,7 @@ async function listAssignmentsInternal(context, courseId, maxPages, limit, check
385
389
  const path = queue.shift();
386
390
  if (visited.has(path)) continue;
387
391
  visited.add(path);
388
- const page = await fetchPage(context, path);
392
+ const page = await fetchPage(context, path, { stopAt });
389
393
  for (const item of parseAssignments(page.text, courseId)) {
390
394
  if (identifiers.has(item.contentId)) continue;
391
395
  identifiers.add(item.contentId);
@@ -447,7 +451,7 @@ async function listAssignmentsInternal(context, courseId, maxPages, limit, check
447
451
  courseId,
448
452
  assignments: listed,
449
453
  pagesChecked: visited.size,
450
- truncated: queue.length > 0 || assignments.length > limit,
454
+ truncated: queue.some(path => !visited.has(path)) || assignments.length === limit,
451
455
  statusChecked: checkStatus,
452
456
  attemptsOpened: false,
453
457
  scope: 'reachable_course_content_pages',
@@ -473,8 +477,10 @@ function reviewUrl(entry, courseId, contentId) {
473
477
  return url.href;
474
478
  }
475
479
 
480
+ const DEADLINE_PATTERN = /\b(20\d{2})(?:年\s*|[-/.])(\d{1,2})(?:月\s*|[-/.])(\d{1,2})日?(?:\s*(?:星期[一二三四五六日天]|[((](?:星期|周)?[一二三四五六日天][))]))?\s*(?:T\s*)?(上午|下午)?\s*(\d{1,2})[::](\d{2})(?!\d)(?!\s*(?::\d{2}\s*)?(?:Z\b|[+-]\d{2}:?\d{2}))/;
481
+
476
482
  function deadline(text) {
477
- const match = /(20\d{2})年\s*(\d{1,2})月\s*(\d{1,2})日(?:\s*星期\S)?\s*(上午|下午)?\s*(\d{1,2})[::](\d{2})/.exec(String(text ?? ''));
483
+ const match = DEADLINE_PATTERN.exec(String(text ?? ''));
478
484
  if (!match) return null;
479
485
  const year = Number(match[1]);
480
486
  const month = Number(match[2]);
@@ -485,11 +491,7 @@ function deadline(text) {
485
491
  if (hour < 1 || hour > 12) return null;
486
492
  hour = (hour % 12) + (match[4] === '下午' ? 12 : 0);
487
493
  }
488
- if (hour > 23 || minute > 59) return null;
489
- const check = new Date(Date.UTC(year, month - 1, day, hour, minute));
490
- if (check.getUTCFullYear() !== year || check.getUTCMonth() !== month - 1
491
- || check.getUTCDate() !== day || check.getUTCHours() !== hour
492
- || check.getUTCMinutes() !== minute) return null;
494
+ if (shanghaiEpoch(year, month, day, hour, minute) === null) return null;
493
495
  const pad = (value) => String(value).padStart(2, '0');
494
496
  return `${year}-${pad(month)}-${pad(day)}T${pad(hour)}:${pad(minute)}:00+08:00`;
495
497
  }
@@ -603,6 +605,67 @@ function parseReview(html, { includeAttachmentNames = false, assignment = null }
603
605
  return next;
604
606
  }
605
607
 
608
+ async function readAssignmentAgenda(context) {
609
+ const stopAt = performance.now() + AGENDA_SCAN_MS;
610
+ const portal = await fetchPage(context, BB_PORTAL_PATH, { stopAt });
611
+ const courses = parseCourses(portal.text);
612
+ if (!courses.length) return { state: 'unavailable', complete: false, entries: [] };
613
+
614
+ const listings = await mapLimited(courses, 4, course =>
615
+ listAssignmentsInternal(context, course.courseId, 15, 50, false, stopAt));
616
+ let complete = true;
617
+ let listed = false;
618
+ const entries = [];
619
+ const missing = [];
620
+ function add(assignment, course, dueAt, url) {
621
+ const start = Date.parse(dueAt);
622
+ entries.push({
623
+ id: `bb_${course.courseId}:${assignment.contentId}`, kind: 'deadline',
624
+ title: assignment.title, courseTitle: course.title, source: 'Blackboard',
625
+ date: dueAt.slice(0, 10), start, end: start, url
626
+ });
627
+ }
628
+ for (const [i, listing] of listings.entries()) {
629
+ if (listing.status === 'rejected') {
630
+ if (listing.reason?.code === 'authentication_required') throw listing.reason;
631
+ complete = false;
632
+ continue;
633
+ }
634
+ listed = true;
635
+ complete &&= !listing.value.truncated;
636
+ const course = courses[i];
637
+ for (const assignment of listing.value.assignments) {
638
+ let url;
639
+ try { url = reviewUrl(assignment, course.courseId, assignment.contentId); }
640
+ catch (error) { if (!(error instanceof BbError)) throw error; }
641
+ let dueAt;
642
+ for (const line of assignment.dueText) {
643
+ if (!/截止|到期|提交时限|最后提交|\bdue\b|\bdeadline\b/i.test(line)) continue;
644
+ const first = DEADLINE_PATTERN.exec(line);
645
+ // Two timed dates can describe an opening and a deadline. Prefer the labelled detail field.
646
+ if (!first || DEADLINE_PATTERN.test(line.slice(first.index + first[0].length))) continue;
647
+ dueAt = deadline(first[0]);
648
+ if (dueAt) break;
649
+ }
650
+ if (dueAt) add(assignment, course, dueAt, url ?? new URL(course.path, BB_ORIGIN).href);
651
+ else if (url) missing.push({ assignment, course, url });
652
+ else complete = false;
653
+ }
654
+ }
655
+ const details = await mapLimited(missing, 4, async ({ assignment, course, url }) => {
656
+ const page = await fetchPage(context, url, { timeout: REVIEW_TIMEOUT_MS, stopAt });
657
+ const { dueAt } = parseReview(page.text, { assignment });
658
+ if (dueAt) add(assignment, course, dueAt, url);
659
+ });
660
+ for (const detail of details) {
661
+ if (detail.status === 'fulfilled') continue;
662
+ if (detail.reason?.code === 'authentication_required') throw detail.reason;
663
+ complete = false;
664
+ }
665
+ return { state: entries.length ? 'ok' : complete ? 'empty' : listed ? 'partial' : 'unavailable', complete,
666
+ entries: entries.sort((a, b) => a.start - b.start || a.id.localeCompare(b.id)) };
667
+ }
668
+
606
669
  function formValues($, form, name) {
607
670
  return form.find('input[name]')
608
671
  .filter((_, node) => $(node).attr('name') === name)
@@ -1243,6 +1306,10 @@ export function createBb({ withSchoolContext, dataDir, connectReadSession } = {}
1243
1306
  };
1244
1307
 
1245
1308
  const api = {
1309
+ agenda() {
1310
+ return run(readAssignmentAgenda, true);
1311
+ },
1312
+
1246
1313
  async listCourses({ keyword = '', term = '' } = {}) {
1247
1314
  boundedText(keyword, 200, '课程关键字');
1248
1315
  requireValue(!term || /^20\d{2}(?:FA|SP|SU|WI)$/.test(term),
package/src/host.mjs CHANGED
@@ -58,13 +58,13 @@ export function apply(ctx) {
58
58
  const bbActions=createBbActions({bb});
59
59
  const youth = createYouth({withSchoolContext:school.withSchoolContext});
60
60
  const youthActions = createYouthActions({withSchoolContext:school.withSchoolContext});
61
- const personal = createAccountData({ dir, school, youth,
61
+ const libraryBooking = createLibraryBooking({withSchoolContext:school.withSchoolContext,dataDir:dir});
62
+ const hsLibrary = createHsLibrary({withSchoolContext:school.withSchoolContext});
63
+ const personal = createAccountData({ dir, school, youth, bb, libraryBooking, hsLibrary,
62
64
  createExams: cache => createExams({ withSchoolContext: school.withSchoolContext, cache }) });
63
65
  const { exams } = personal;
64
66
  const grades = createGrades({withSchoolContext:school.withSchoolContext, cache:personal.cache});
65
67
  const librarySpaces = createLibrarySpaces({withSchoolContext:school.withSchoolContext});
66
- const libraryBooking = createLibraryBooking({withSchoolContext:school.withSchoolContext,dataDir:dir});
67
- const hsLibrary = createHsLibrary({withSchoolContext:school.withSchoolContext});
68
68
  const transit = createCampusTransit({ dir });
69
69
  const libraryApprovals = new Map();
70
70
  let accountSignal = new AbortController();
@@ -105,6 +105,7 @@ export function apply(ctx) {
105
105
  const approval=libraryApprovals.get(planId);
106
106
  if(approval?.busy) return {state:'busy',planId,message:'正在处理此预约,请勿重复提交。'};
107
107
  const result=await readBooking(()=>libraryBooking.status({planId}));
108
+ if (result.state === 'verified' && result.plan?.date) personal.refreshReservations('west', result.plan.date);
108
109
  if(result.state!=='ready') return result;
109
110
  if(!approval || libraryApprovals.get(planId)!==approval || approval.expiry<=Date.now()) {
110
111
  return {state:'expired',planId,message:'预约草稿已失效,没有提交。请重新核对时段。'};
@@ -139,11 +140,20 @@ export function apply(ctx) {
139
140
  return {state:decision,planId,requestSent:false,message:approval.message};
140
141
  }
141
142
  try {
142
- return await libraryBooking.confirm({planId,digest:approval.digest,authorized:true},approvalSignal);
143
+ const result = await libraryBooking.confirm({planId,digest:approval.digest,authorized:true},approvalSignal);
144
+ if (result.state === 'verified' && !approvalSignal.aborted) personal.refreshReservations('west', p.date);
145
+ return result;
143
146
  } finally { libraryApprovals.delete(planId); }
144
147
  } finally { approval.busy=false; }
145
148
  }
146
149
 
150
+ async function refreshOnVerified(operation, refresh) {
151
+ const epoch = accountEpoch;
152
+ const result = await operation;
153
+ if (epoch === accountEpoch && result.state === 'verified') refresh();
154
+ return result;
155
+ }
156
+
147
157
  async function dispatchOwner(op,data) {
148
158
  if(op==='agenda-local') return campus.agenda(data);
149
159
  if(op==='agenda') {
@@ -153,11 +163,12 @@ export function apply(ctx) {
153
163
  if (epoch !== accountEpoch) {
154
164
  const unavailable = { state: 'not_connected', complete: false };
155
165
  return { ...campus.agenda(data), school: { state: school.status().state, complete: false },
156
- exams: unavailable, youth: { ...unavailable, verifiedCount: 0 }, stale: false, syncing: false, cachedAt: null };
166
+ exams: unavailable, assignments: unavailable, reservations: { count: 0, complete: false },
167
+ youth: { ...unavailable, verifiedCount: 0 }, stale: false, syncing: false, cachedAt: null };
157
168
  }
158
169
  return { ...campus.agenda(data, { schoolEntries }), ...metadata };
159
170
  }
160
- if(op==='item-mutate' && data.action==='remove' && typeof data.id==='string' && /^(?:school|youth)_/.test(data.id)) {
171
+ if(op==='item-mutate' && data.action==='remove' && typeof data.id==='string' && /^(?:school|youth|bb|library)_/.test(data.id)) {
161
172
  const epoch = accountEpoch;
162
173
  localMidnight(data.date);
163
174
  const { schoolEntries } = await personal.agenda({ from: data.date, through: data.date });
@@ -218,15 +229,17 @@ export function apply(ctx) {
218
229
  reservations: hsLibrary.reservations,
219
230
  prepareBooking: hsLibrary.prepareBooking,
220
231
  prepareCancel: hsLibrary.prepareCancel,
221
- status: hsLibrary.status,
222
- confirm: (data, approve, signal) => hsLibrary.confirm(data, approve, AbortSignal.any([signal, accountSignal.signal]))
232
+ status: data => refreshOnVerified(hsLibrary.status(data), () => personal.refreshReservations('hs')),
233
+ confirm: (data, approve, signal) => refreshOnVerified(
234
+ hsLibrary.confirm(data, approve, AbortSignal.any([signal, accountSignal.signal])), () => personal.refreshReservations('hs'))
223
235
  });
224
236
  ctx.provide('ustcYouth', youth);
225
237
  ctx.provide('ustcYouthActions', {
226
238
  prepareEnroll: youthActions.prepareEnroll,
227
239
  prepareCancel: youthActions.prepareCancel,
228
- status: youthActions.status,
229
- confirm: (data, approve, signal) => youthActions.confirm(data, approve, AbortSignal.any([signal, accountSignal.signal]))
240
+ status: data => refreshOnVerified(youthActions.status(data), personal.refreshEnrollment),
241
+ confirm: (data, approve, signal) => refreshOnVerified(
242
+ youthActions.confirm(data, approve, AbortSignal.any([signal, accountSignal.signal])), personal.refreshEnrollment)
230
243
  });
231
244
  ctx.provide('ustcExams', exams);
232
245
  ctx.provide('ustcTransit', transit);
@@ -827,6 +827,46 @@ export function createHsLibrary({
827
827
  };
828
828
  }
829
829
 
830
+ async function agenda({ from, through }) {
831
+ const res = await runWithContext(async context => {
832
+ const opts = { timeout };
833
+ const session = await ensureHsSession(context, opts);
834
+ if (session.kind !== 'ok') return session;
835
+ const pageSize = 50;
836
+ const entries = new Map();
837
+ let complete = true;
838
+ for (let pageNum = 1; pageNum <= 5; pageNum++) {
839
+ const hist = await hsGet(context, '/desktopAppointment/getAppointmentHistory', { pageSize, pageNum }, opts);
840
+ if (hist.kind !== 'ok' || !Array.isArray(hist.content?.userRecordsList)) {
841
+ if (pageNum === 1) return { kind: hist.kind === 'not_connected' ? hist.kind : 'failure' };
842
+ complete = false;
843
+ break;
844
+ }
845
+ const rows = hist.content.userRecordsList;
846
+ for (const raw of rows) {
847
+ const item = mapHistoryItem(raw);
848
+ if (!item || !ACTIVE_BOOKING_STATES.has(item.stateCode) || item.stateCode === 12) continue;
849
+ if (!isValidDate(item.date)) { complete = false; continue; }
850
+ if ((from && item.date < from) || (through && item.date > through)) continue;
851
+ if (hhmmMinutes(item.startTime) === null || hhmmMinutes(item.endTime) === null || item.endTime <= item.startTime) {
852
+ complete = false;
853
+ continue;
854
+ }
855
+ const id = `library_hs_${item.appointmentId}`;
856
+ entries.set(id, { id, kind: 'reservation', title: item.resourceName || '高新园区图书馆预约', date: item.date,
857
+ startTime: item.startTime, endTime: item.endTime, source: CAMPUS, location: item.partitionName,
858
+ url: HS_LIBRARY_RESULT_LINK.url });
859
+ }
860
+ const total = nonNegativeInt(hist.content.total);
861
+ if (total === null ? rows.length < pageSize : pageNum * pageSize >= total) break;
862
+ if (rows.length < pageSize || pageNum === 5) { complete = false; break; }
863
+ }
864
+ return { kind: 'ok', complete, entries: [...entries.values()] };
865
+ });
866
+ if (res.kind !== 'ok') return { state: res.kind, complete: false, entries: [] };
867
+ return { state: res.entries.length ? 'ok' : 'empty', complete: res.complete, entries: res.entries };
868
+ }
869
+
830
870
  function validateSlotAgainstRules(rules, date, startTime, endTime) {
831
871
  if (rules.bookableDates.length > 0 && !rules.bookableDates.includes(date)) {
832
872
  return { ok: false, state: 'not_bookable', message: '所选日期不在当前可预约日期范围内。' };
@@ -1428,6 +1468,7 @@ export function createHsLibrary({
1428
1468
  categories,
1429
1469
  availability,
1430
1470
  reservations,
1471
+ agenda,
1431
1472
  prepareBooking,
1432
1473
  prepareCancel,
1433
1474
  confirm,
@@ -103,6 +103,7 @@ import {
103
103
  statusOf
104
104
  } from './library-spaces.mjs';
105
105
  import { LIBRARY_RESULT_LINK } from './result-links.mjs';
106
+ import { shDate } from './calendar.mjs';
106
107
 
107
108
  const CAMPUS = '西区图书馆';
108
109
  const TIME_ZONE = 'Asia/Shanghai';
@@ -599,10 +600,10 @@ async function locateRoom(context, kindId, devId, date) {
599
600
  return { kind: 'not_found' };
600
601
  }
601
602
 
602
- function mineUrl(date, page) {
603
+ function mineUrl(from, through, page) {
603
604
  const url = new URL(MINE_PATH, ORIGIN);
604
- url.searchParams.set('beginDate', date);
605
- url.searchParams.set('endDate', date);
605
+ url.searchParams.set('beginDate', from);
606
+ url.searchParams.set('endDate', through);
606
607
  url.searchParams.set('needStatus', '0');
607
608
  url.searchParams.set('page', String(page));
608
609
  url.searchParams.set('pageNum', String(MINE_PAGE_SIZE));
@@ -611,12 +612,12 @@ function mineUrl(date, page) {
611
612
  return officialUrl(url.pathname + url.search);
612
613
  }
613
614
 
614
- async function readMineAll(context, date) {
615
+ async function readMineAll(context, from, through = from) {
615
616
  const rows = [];
616
617
  const seen = new Set();
617
618
  let total = null;
618
619
  for (let page = 1; page <= MAX_MINE_PAGES; page += 1) {
619
- const result = await getEnvelope(context, mineUrl(date, page));
620
+ const result = await getEnvelope(context, mineUrl(from, through, page));
620
621
  if (result.kind !== 'ok') return result;
621
622
  const data = result.envelope.data;
622
623
  if (!Array.isArray(data)) return { kind: 'failure' };
@@ -1398,6 +1399,33 @@ export function createLibraryBooking({ withSchoolContext, now = () => Date.now()
1398
1399
  );
1399
1400
  },
1400
1401
 
1402
+ agenda({ from, through }) {
1403
+ return scoped(async context => {
1404
+ const session = await openBookingSession(context);
1405
+ if (session.kind !== 'ok') return { state: upstreamState(session.kind), complete: false, entries: [] };
1406
+ const mine = await readMineAll(context, from, through);
1407
+ if (mine.kind !== 'ok') return { state: upstreamState(mine.kind), complete: false, entries: [] };
1408
+ const entries = [];
1409
+ let complete = true;
1410
+ for (const raw of mine.rows) {
1411
+ const item = publicReservation(raw);
1412
+ const status = Number(item.status);
1413
+ // The official history distinguishes approval, payment and participant confirmation from booking success.
1414
+ if (!(status & (1 | 2 | 4 | 32 | 64 | 1024 | 2048)) || status & (8 | 16 | 128 | 256 | 512 | 8192)) continue;
1415
+ const start = parseTimestamp(item.begin);
1416
+ const end = parseTimestamp(item.end);
1417
+ if (start === null || end === null || end <= start) { complete = false; continue; }
1418
+ const date = shDate(start);
1419
+ if (date < from || date > through) continue;
1420
+ const room = item.resources.map(device => device.devName || device.roomName).filter(Boolean).join(' / ');
1421
+ entries.push({ id: `library_west_${item.id}`, kind: 'reservation', title: room || '西区图书馆预约',
1422
+ date, start, end, source: CAMPUS, location: item.resources[0]?.labName ?? '', url: LIBRARY_RESULT_LINK.url });
1423
+ }
1424
+ return { state: entries.length ? 'ok' : 'empty', complete, entries };
1425
+ }, state => ({ state, complete: false, entries: [] }),
1426
+ result => Array.isArray(result?.entries));
1427
+ },
1428
+
1401
1429
  async reservations({date}={}) {
1402
1430
  if(!parseDate(date)) return unresolvedResult('invalid',[],{reason:'date',message:'请选择有效日期。'});
1403
1431
  return scoped(async context=>{
package/src/material.mjs CHANGED
@@ -66,6 +66,14 @@ export const material = `
66
66
  --uc-l-on-warning-container: #2B1700;
67
67
  --uc-d-on-warning-container: #FFDDB6;
68
68
 
69
+ /* Calendar exam palette */
70
+ --uc-l-exam: #705900;
71
+ --uc-d-exam: #FFDA57;
72
+ --uc-l-exam-container: #FFE789;
73
+ --uc-d-exam-container: #554500;
74
+ --uc-l-on-exam-container: #251A00;
75
+ --uc-d-on-exam-container: #FFE789;
76
+
69
77
  /* Surface & Neutral Hierarchy */
70
78
  --uc-l-surface: #F9F9FF;
71
79
  --uc-d-surface: #11131A;
@@ -136,6 +144,9 @@ export const material = `
136
144
  --md-sys-color-on-warning: var(--uc-l-on-warning);
137
145
  --md-sys-color-warning-container: var(--uc-l-warning-container);
138
146
  --md-sys-color-on-warning-container: var(--uc-l-on-warning-container);
147
+ --md-sys-color-exam: var(--uc-l-exam);
148
+ --md-sys-color-exam-container: var(--uc-l-exam-container);
149
+ --md-sys-color-on-exam-container: var(--uc-l-on-exam-container);
139
150
  --md-sys-color-surface: var(--uc-l-surface);
140
151
  --md-sys-color-surface-dim: var(--uc-l-surface-dim);
141
152
  --md-sys-color-surface-bright: var(--uc-l-surface-bright);
@@ -236,6 +247,9 @@ export const material = `
236
247
  --md-sys-color-on-warning: var(--uc-d-on-warning);
237
248
  --md-sys-color-warning-container: var(--uc-d-warning-container);
238
249
  --md-sys-color-on-warning-container: var(--uc-d-on-warning-container);
250
+ --md-sys-color-exam: var(--uc-d-exam);
251
+ --md-sys-color-exam-container: var(--uc-d-exam-container);
252
+ --md-sys-color-on-exam-container: var(--uc-d-on-exam-container);
239
253
  --md-sys-color-surface: var(--uc-d-surface);
240
254
  --md-sys-color-surface-dim: var(--uc-d-surface-dim);
241
255
  --md-sys-color-surface-bright: var(--uc-d-surface-bright);
@@ -285,6 +299,9 @@ export const material = `
285
299
  --md-sys-color-on-warning: light-dark(var(--uc-l-on-warning), var(--uc-d-on-warning));
286
300
  --md-sys-color-warning-container: light-dark(var(--uc-l-warning-container), var(--uc-d-warning-container));
287
301
  --md-sys-color-on-warning-container: light-dark(var(--uc-l-on-warning-container), var(--uc-d-on-warning-container));
302
+ --md-sys-color-exam: light-dark(var(--uc-l-exam), var(--uc-d-exam));
303
+ --md-sys-color-exam-container: light-dark(var(--uc-l-exam-container), var(--uc-d-exam-container));
304
+ --md-sys-color-on-exam-container: light-dark(var(--uc-l-on-exam-container), var(--uc-d-on-exam-container));
288
305
  --md-sys-color-surface: light-dark(var(--uc-l-surface), var(--uc-d-surface));
289
306
  --md-sys-color-surface-dim: light-dark(var(--uc-l-surface-dim), var(--uc-d-surface-dim));
290
307
  --md-sys-color-surface-bright: light-dark(var(--uc-l-surface-bright), var(--uc-d-surface-bright));
@@ -1504,9 +1521,9 @@ dialog.uc-dialog[open]::backdrop {
1504
1521
  }
1505
1522
 
1506
1523
  .uc-event-block[data-kind="exam"] {
1507
- background: var(--md-sys-color-error-container);
1508
- color: var(--md-sys-color-on-error-container);
1509
- border-inline-start-color: var(--md-sys-color-error);
1524
+ background: var(--md-sys-color-exam-container);
1525
+ color: var(--md-sys-color-on-exam-container);
1526
+ border-inline-start-color: var(--md-sys-color-exam);
1510
1527
  }
1511
1528
 
1512
1529
  .uc-event-block[data-kind="event"] {
@@ -1515,6 +1532,41 @@ dialog.uc-dialog[open]::backdrop {
1515
1532
  border-inline-start-color: var(--md-sys-color-tertiary);
1516
1533
  }
1517
1534
 
1535
+ .uc-event-block[data-kind="deadline"] {
1536
+ --uc-point-color: var(--md-sys-color-error);
1537
+ border-inline-start: 0;
1538
+ background: transparent;
1539
+ color: var(--md-sys-color-on-error-container);
1540
+ justify-content: center;
1541
+ min-inline-size: 24px;
1542
+ padding: 0;
1543
+ }
1544
+
1545
+ .uc-event-block[data-kind="deadline"]::before {
1546
+ content: '';
1547
+ position: absolute;
1548
+ inset-inline: 0;
1549
+ top: min(var(--uc-deadline-marker), calc(100% - 2px));
1550
+ border-block-start: 2px solid var(--uc-point-color);
1551
+ }
1552
+
1553
+ .uc-event-block[data-kind="deadline"] .uc-event-title {
1554
+ z-index: 1;
1555
+ align-self: flex-start;
1556
+ max-inline-size: 100%;
1557
+ box-sizing: border-box;
1558
+ padding: 1px 3px;
1559
+ border-radius: var(--md-sys-shape-corner-extra-small);
1560
+ background: var(--md-sys-color-error-container);
1561
+ }
1562
+
1563
+ .uc-event-block[data-kind="deadline"]:focus-visible {
1564
+ outline: 2px solid var(--uc-point-color);
1565
+ outline-offset: -2px;
1566
+ z-index: 3;
1567
+ }
1568
+
1569
+ .uc-event-block[data-kind="reservation"],
1518
1570
  .uc-event-block[data-kind="task"] {
1519
1571
  background: var(--md-sys-color-success-container);
1520
1572
  color: var(--md-sys-color-on-success-container);
package/src/state.mjs CHANGED
@@ -14,6 +14,7 @@ const MAX_SCHOOL_ENTRIES = 2000;
14
14
  const FEED_SNAPSHOT_LIMIT = 12;
15
15
  const NO_EXTRA_ITEMS = [];
16
16
  const localKinds = new Set(['course', 'exam']);
17
+ const schoolKinds = new Set(['exam', 'event', 'deadline', 'reservation']);
17
18
  const readLabels = { schedule: '课表', saved: '收藏', items: '日程', recommender: '推荐偏好', 'custom-feeds': '自定义订阅' };
18
19
  export class CampusInputError extends Error {}
19
20
  function clockMinutes(value) {
@@ -133,7 +134,7 @@ export function openCampus(dir, { now = Date.now, fetch = globalThis.fetch } = {
133
134
  if (!source || /^https?:\/\//i.test(source)) source = '学校教务';
134
135
  entries.push({
135
136
  id,
136
- kind: item.kind === 'exam' ? 'exam' : item.kind === 'event' ? 'event' : 'course',
137
+ kind: schoolKinds.has(item.kind) ? item.kind : 'course',
137
138
  title,
138
139
  date,
139
140
  start,
@@ -141,6 +142,8 @@ export function openCampus(dir, { now = Date.now, fetch = globalThis.fetch } = {
141
142
  allDay: item.allDay === true || (startClock == null && !Number.isFinite(item.start)),
142
143
  location,
143
144
  source,
145
+ ...(item.kind === 'deadline' && { courseTitle: sanitizeText(item.courseTitle, 300) }),
146
+ ...(item.url && { url: item.url }),
144
147
  school: true,
145
148
  external: true,
146
149
  });
@@ -166,10 +169,15 @@ export function openCampus(dir, { now = Date.now, fetch = globalThis.fetch } = {
166
169
  truncated: report.truncated, warnings: issues });
167
170
  if (issues.length || report.truncated) warnings.push(`${item.label}:${report.truncated ? '未完整展开' : '有日历警告'}${issues.length ? `(${issues[0]})` : ''}`);
168
171
  }
172
+ const trustedEntries = trusted && typeof trusted === 'object' ? trusted.schoolEntries : undefined;
173
+ const enrolledIds = new Set();
174
+ if (Array.isArray(trustedEntries)) for (const entry of trustedEntries) {
175
+ if (typeof entry?.id === 'string' && entry.id.startsWith('youth_')) enrolledIds.add(entry.id);
176
+ }
169
177
  for (const item of Object.values(saved)) {
178
+ if (item.activitySource === 'youth-enrolling' && enrolledIds.has(`youth_${item.id.slice('youth-enrolling:'.length)}`)) continue;
170
179
  if (item.start != null ? item.start < end && Math.max(item.end ?? item.start, item.start + 1) > start : item.date >= from && item.date <= through) entries.push({ ...item, saved: true });
171
180
  }
172
- const trustedEntries = trusted && typeof trusted === 'object' ? trusted.schoolEntries : undefined;
173
181
  entries.push(...schoolEntryList(trustedEntries, { from, through, hidden, warnings }));
174
182
  const personal = localItems.entriesIn(from, through);
175
183
  entries.push(...personal.entries);
@@ -1,4 +1,5 @@
1
1
  const DAY = 86_400_000, MINUTE = 60_000, HOUR = 60;
2
+ const POINT_TARGET = 24;
2
3
 
3
4
  export function layoutWeek(weekUtc, entries) {
4
5
  const first = weekUtc - 8 * HOUR * MINUTE;
@@ -12,6 +13,14 @@ export function layoutWeek(weekUtc, entries) {
12
13
  if (item.date === date) day.untimed.push(item);
13
14
  continue;
14
15
  }
16
+ if (item.kind === 'deadline') {
17
+ if (item.start < midnight || item.start >= next) continue;
18
+ const point = (item.start - midnight) / MINUTE;
19
+ const from = Math.min(point, 24 * HOUR - POINT_TARGET);
20
+ start = Math.min(start, Math.floor(from / HOUR) * HOUR);
21
+ day.timed.push({ item, from, through: point, point });
22
+ continue;
23
+ }
15
24
  const finish = Math.max(item.end ?? item.start, item.start + 1);
16
25
  if (item.start >= next || finish <= midnight) continue;
17
26
  if (item.allDay) { day.untimed.push(item); continue; }
@@ -30,7 +39,7 @@ export function layoutWeek(weekUtc, entries) {
30
39
  for (const block of day.timed) {
31
40
  if (block.from >= clusterEnd) finishCluster();
32
41
  // Short entries get a readable hit target without obscuring adjacent entries.
33
- block.visualEnd = Math.min(24 * HOUR, Math.max(block.through, block.from + 24));
42
+ block.visualEnd = Math.min(24 * HOUR, Math.max(block.through, block.from + POINT_TARGET));
34
43
  const free = lanes.findIndex(value => value <= block.from);
35
44
  block.lane = free < 0 ? lanes.length : free;
36
45
  lanes[block.lane] = block.visualEnd;
package/src/youth.mjs CHANGED
@@ -13,10 +13,9 @@
13
13
  * - `https://young.ustc.edu.cn/login/sc-wisdom-group-learning/` is the
14
14
  * registered CAS service used by the platform's own login page;
15
15
  * - `cas/client/checkSsoLogin` exchanges a CAS ticket over GET;
16
- * - `item/scParticipateItem/list` is the enrolled list, filtered by the
17
- * token on the server side;
18
- * - `item/scItem/queryById` confirms the viewer's enrollment when the
19
- * listing does not carry an explicit registration flag.
16
+ * - `item/scParticipateItem/list?queryCatelog=0` is the signed-in user's
17
+ * «已参与项目» list; membership comes from that list, not its rows' flags;
18
+ * - `item/scItem/queryById` can supply missing event times.
20
19
  * The names and envelope were cross-checked against pyustc v1.2.1 and the
21
20
  * platform's own browser bundle; no upstream source is copied here.
22
21
  *
@@ -27,7 +26,7 @@
27
26
  * The returned object has exactly three fields: `{ state, entries, complete }`.
28
27
  * `state` is one of `ok`, `empty`, `not_connected` or `failure`. A row is
29
28
  * returned only when its upstream ID, title and both times are present and
30
- * unambiguous; anything else is dropped and marks `complete` false.
29
+ * unambiguous; undated rows are not scheduled.
31
30
  */
32
31
 
33
32
  import { createCipheriv } from 'node:crypto';
@@ -548,6 +547,11 @@ function registration(record) {
548
547
  }
549
548
  }
550
549
 
550
+ function activeParticipation(record) {
551
+ return String(record.examineStatus) !== '-3'
552
+ && ![record.itemStatus_dictText, record.applyStatus_dictText].some(label => /已取消|取消报名|已终止/.test(label ?? ''));
553
+ }
554
+
551
555
  function enrolledRow(record) {
552
556
  if (!record || typeof record !== 'object' || Array.isArray(record)) return null;
553
557
 
@@ -555,7 +559,7 @@ function enrolledRow(record) {
555
559
  const title = cleanText(record.itemName ?? record.title, 200);
556
560
  if (!id || !title) return null;
557
561
 
558
- if (registration(record) === false || String(record.itemCategory) === '1') return null;
562
+ if (String(record.itemCategory) === '1' || !activeParticipation(record)) return null;
559
563
 
560
564
  const start = localTime(record.st ?? record.startTime);
561
565
  const end = localTime(record.et ?? record.endTime);
@@ -678,7 +682,7 @@ export async function readEnrolled({
678
682
  const id = cleanId(record?.id ?? record?.itemId);
679
683
  if (!id || seen.has(id)) { complete = false; continue; }
680
684
  seen.add(id);
681
- if (registration(record) === false || String(record.itemCategory) === '1') continue;
685
+ if (String(record.itemCategory) === '1' || !activeParticipation(record)) continue;
682
686
  const start = localTime(record.st ?? record.startTime);
683
687
  if (start && ((from && start.date < from) || (through && start.date > through))) continue;
684
688
  const row = enrolledRow(record);
@@ -779,7 +783,7 @@ function deriveCheckInInfo(record) {
779
783
  };
780
784
  }
781
785
 
782
- function mapActivitySummary(record) {
786
+ function mapActivitySummary(record, ownParticipation = false) {
783
787
  if (!record || typeof record !== 'object' || Array.isArray(record)) return null;
784
788
  const id = cleanId(record.id ?? record.itemId);
785
789
  const title = cleanText(record.itemName ?? record.title, 200);
@@ -814,7 +818,7 @@ function mapActivitySummary(record) {
814
818
  remainingSlots: enrolledCount !== null && capacity !== null && capacity > 0
815
819
  ? Math.max(0, capacity - enrolledCount)
816
820
  : null,
817
- registered: registration(record),
821
+ registered: ownParticipation ? activeParticipation(record) : registration(record),
818
822
  isSeries,
819
823
  marathon: Number(record.marathon) === 1,
820
824
  needSignInfo: String(record.needSignInfo) === '1'
@@ -891,7 +895,8 @@ async function listActivityPage(context, session, normalizedMode, kw, pageNo, si
891
895
  if (!records || records.length > MAX_RESPONSE_ROWS) {
892
896
  return { state: 'failure', mode: normalizedMode, items: [], message: '暂时无法读取青春科大活动列表,请稍后重试。', untrustedContent: true };
893
897
  }
894
- const items = records.map(mapActivitySummary).filter(Boolean).slice(0, size);
898
+ const ownParticipation = normalizedMode === 'enrolled';
899
+ const items = records.map(record => mapActivitySummary(record, ownParticipation)).filter(Boolean).slice(0, size);
895
900
  return {
896
901
  state: items.length > 0 ? 'ok' : 'empty',
897
902
  mode: normalizedMode,