chuvsu-js 5.4.1 → 5.5.1
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 +33 -3
- package/dist/common/http.d.ts +3 -1
- package/dist/common/http.js +9 -2
- package/dist/{tt/utils → common}/lesson-type.d.ts +4 -2
- package/dist/{tt/utils → common}/lesson-type.js +17 -2
- package/dist/core.d.ts +13 -5
- package/dist/core.js +7 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lk/client.d.ts +23 -1
- package/dist/lk/client.js +95 -0
- package/dist/lk/parse/grade-value.d.ts +4 -0
- package/dist/lk/parse/grade-value.js +16 -0
- package/dist/lk/parse/portfolio-content.d.ts +10 -0
- package/dist/lk/parse/portfolio-content.js +116 -0
- package/dist/lk/parse/portfolio-grades.d.ts +8 -0
- package/dist/lk/parse/portfolio-grades.js +41 -0
- package/dist/lk/parse/portfolio-performance.d.ts +2 -0
- package/dist/lk/parse/portfolio-performance.js +44 -0
- package/dist/lk/parse/portfolio.d.ts +6 -0
- package/dist/lk/parse/portfolio.js +64 -0
- package/dist/lk/parse/webinar-lesson.d.ts +7 -0
- package/dist/lk/parse/webinar-lesson.js +28 -0
- package/dist/lk/parse/webinars.d.ts +3 -0
- package/dist/lk/parse/webinars.js +67 -0
- package/dist/lk/portfolio-types.d.ts +113 -0
- package/dist/lk/portfolio-types.js +1 -0
- package/dist/lk/types.d.ts +29 -0
- package/dist/{tt → lk}/webinars.d.ts +3 -1
- package/dist/lk/webinars.js +48 -0
- package/dist/parsers.d.ts +3 -1
- package/dist/parsers.js +3 -1
- package/dist/tt/client.d.ts +1 -11
- package/dist/tt/client.js +1 -45
- package/dist/tt/domain/types.d.ts +1 -1
- package/dist/tt/observations.js +2 -1
- package/dist/tt/parse/index.d.ts +0 -1
- package/dist/tt/parse/index.js +0 -1
- package/dist/tt/types.d.ts +0 -21
- package/dist/tt/utils/index.d.ts +0 -1
- package/dist/tt/utils/index.js +0 -1
- package/dist/webinar/client.d.ts +52 -0
- package/dist/webinar/client.js +184 -0
- package/dist/webinar/ddp.d.ts +31 -0
- package/dist/webinar/ddp.js +208 -0
- package/dist/webinar/events.d.ts +6 -0
- package/dist/webinar/events.js +38 -0
- package/dist/webinar/gateway.d.ts +30 -0
- package/dist/webinar/gateway.js +114 -0
- package/dist/webinar/media-protocol.d.ts +9 -0
- package/dist/webinar/media-protocol.js +24 -0
- package/dist/webinar/media-types.d.ts +10 -0
- package/dist/webinar/media-types.js +1 -0
- package/dist/webinar/media.d.ts +21 -0
- package/dist/webinar/media.js +76 -0
- package/dist/webinar/parse.d.ts +14 -0
- package/dist/webinar/parse.js +113 -0
- package/dist/webinar/playback.d.ts +32 -0
- package/dist/webinar/playback.js +188 -0
- package/dist/webinar/socket.d.ts +3 -0
- package/dist/webinar/socket.js +18 -0
- package/dist/webinar/state.d.ts +4 -0
- package/dist/webinar/state.js +98 -0
- package/dist/webinar/types.d.ts +148 -0
- package/dist/webinar/types.js +12 -0
- package/docs/student-portal.md +151 -0
- package/docs/testing.md +13 -0
- package/docs/v5-migration.md +25 -2
- package/docs/webinar.md +145 -0
- package/package.json +2 -2
- package/dist/tt/parse/webinars.d.ts +0 -2
- package/dist/tt/parse/webinars.js +0 -97
- package/dist/tt/webinars.js +0 -39
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { parseHtml, text } from "../../common/parse.js";
|
|
2
|
+
import { ParseError } from "../../common/types.js";
|
|
3
|
+
import { displayedText, parsePortfolioContent, resolvePortfolioUrl } from "./portfolio-content.js";
|
|
4
|
+
import { parsePortfolioControlWeeks, parsePortfolioGrades } from "./portfolio-grades.js";
|
|
5
|
+
import { parsePortfolioPerformance } from "./portfolio-performance.js";
|
|
6
|
+
const BASE = "https://lk.chuvsu.ru";
|
|
7
|
+
/** Only the portfolio landing route or index.php?id=N can be discovered. */
|
|
8
|
+
export function parsePortfolioUrl(html) {
|
|
9
|
+
const doc = parseHtml(html);
|
|
10
|
+
for (const element of doc.querySelectorAll("a[href],button[onclick]")) {
|
|
11
|
+
const raw = element.getAttribute("href") ?? element.getAttribute("onclick")
|
|
12
|
+
?.match(/window\.open\(\s*['"]([^'"]+)['"]/u)?.[1];
|
|
13
|
+
const value = resolvePortfolioUrl(raw ?? null, `${BASE}/student/`);
|
|
14
|
+
if (!value)
|
|
15
|
+
continue;
|
|
16
|
+
const url = new URL(value);
|
|
17
|
+
if (url.origin !== BASE || !["/portfolio", "/portfolio/", "/portfolio/index.php"].includes(url.pathname))
|
|
18
|
+
continue;
|
|
19
|
+
if ([...url.searchParams.keys()].some((key) => key !== "id"))
|
|
20
|
+
continue;
|
|
21
|
+
const id = url.searchParams.get("id");
|
|
22
|
+
if (id !== null && !/^[1-9]\d*$/u.test(id))
|
|
23
|
+
continue;
|
|
24
|
+
return url.href;
|
|
25
|
+
}
|
|
26
|
+
throw new ParseError("LK home response has no portfolio link");
|
|
27
|
+
}
|
|
28
|
+
export function parsePortfolio(html, opts) {
|
|
29
|
+
const doc = parseHtml(html);
|
|
30
|
+
const fullName = text(doc.querySelector(".port_name"));
|
|
31
|
+
if (!fullName)
|
|
32
|
+
throw new ParseError("LK portfolio response has no student identity");
|
|
33
|
+
const photo = doc.querySelector('.port_pic[src]');
|
|
34
|
+
const photoUrl = resolvePortfolioUrl(photo?.getAttribute("src") ?? null, `${BASE}/portfolio/`);
|
|
35
|
+
const photoId = photoUrl ? new URL(photoUrl).searchParams.get("id") : null;
|
|
36
|
+
const requestedId = opts?.url ? new URL(opts.url).searchParams.get("id") : null;
|
|
37
|
+
const rawId = photoId ?? requestedId;
|
|
38
|
+
if (!rawId || !/^[1-9]\d*$/u.test(rawId) || !Number.isSafeInteger(Number(rawId))) {
|
|
39
|
+
throw new ParseError("LK portfolio response has no valid student ID");
|
|
40
|
+
}
|
|
41
|
+
if (requestedId && photoId && requestedId !== photoId) {
|
|
42
|
+
throw new ParseError("LK portfolio student ID differs from requested ID");
|
|
43
|
+
}
|
|
44
|
+
const url = `${BASE}/portfolio/index.php?id=${rawId}`;
|
|
45
|
+
const fields = {};
|
|
46
|
+
for (const label of doc.querySelectorAll(".port_param")) {
|
|
47
|
+
fields[text(label).replace(/:\s*$/u, "")] = label.nextElementSibling ? displayedText(label.nextElementSibling) : "";
|
|
48
|
+
}
|
|
49
|
+
const panels = [...doc.querySelectorAll('[role="tabpanel"]')].filter((panel) => !panel.parentElement?.closest('[role="tabpanel"]'));
|
|
50
|
+
if (!panels.length)
|
|
51
|
+
throw new ParseError("LK portfolio response has no sections");
|
|
52
|
+
const anchors = [...doc.querySelectorAll('a[href^="#"]')];
|
|
53
|
+
const titleFor = (panel) => text(anchors.find((anchor) => anchor.getAttribute("href") === `#${panel.id}`) ?? panel.querySelector("h2"));
|
|
54
|
+
const gradesPanel = panels.find((panel) => titleFor(panel) === "Зачетная книжка");
|
|
55
|
+
const controlsPanel = panels.find((panel) => titleFor(panel) === "Контрольные недели");
|
|
56
|
+
const performancePanel = panels.find((panel) => titleFor(panel) === "Текущая успеваемость");
|
|
57
|
+
return {
|
|
58
|
+
id: Number(rawId), url, student: { fullName, photoUrl, fields },
|
|
59
|
+
grades: gradesPanel ? parsePortfolioGrades(gradesPanel) : [],
|
|
60
|
+
controlWeeks: controlsPanel ? parsePortfolioControlWeeks(controlsPanel) : [],
|
|
61
|
+
performance: performancePanel ? parsePortfolioPerformance(performancePanel, url) : [],
|
|
62
|
+
sections: panels.map((panel) => ({ title: titleFor(panel), content: parsePortfolioContent(panel, url) })),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FLEXIBLE_LESSON_TYPE_RE_I, SUBGROUP_RE } from "../../tt/parse/patterns.js";
|
|
2
|
+
const GROUP_CODE_RE = /[A-ZА-ЯЁ]{1,}(?:-[A-ZА-ЯЁa-zа-яё0-9]+)+(?:\s*ин)?/u;
|
|
3
|
+
export function splitWebinarLesson(raw) {
|
|
4
|
+
const typeMatches = [...raw.matchAll(new RegExp(FLEXIBLE_LESSON_TYPE_RE_I, "gi"))];
|
|
5
|
+
const typeMatch = typeMatches.at(-1);
|
|
6
|
+
if (!typeMatch || typeMatch.index == null) {
|
|
7
|
+
return {
|
|
8
|
+
subject: raw,
|
|
9
|
+
type: "",
|
|
10
|
+
teacherRaw: "",
|
|
11
|
+
groupsRaw: "",
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const subject = raw.slice(0, typeMatch.index).trim();
|
|
15
|
+
const type = typeMatch[1].replace(/\.$/, "").toLowerCase();
|
|
16
|
+
const rest = raw.slice(typeMatch.index + typeMatch[0].length).trim();
|
|
17
|
+
const groupMatch = rest.match(GROUP_CODE_RE);
|
|
18
|
+
const teacherRaw = groupMatch?.index == null ? rest : rest.slice(0, groupMatch.index).trim();
|
|
19
|
+
const groupsRaw = groupMatch?.index == null ? "" : rest.slice(groupMatch.index).trim();
|
|
20
|
+
const subgroupMatch = raw.match(SUBGROUP_RE);
|
|
21
|
+
return {
|
|
22
|
+
subject,
|
|
23
|
+
type,
|
|
24
|
+
teacherRaw,
|
|
25
|
+
groupsRaw,
|
|
26
|
+
subgroup: subgroupMatch ? parseInt(subgroupMatch[1]) : undefined,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { parseHtml, parseTeacher, parseTime, text } from "../../common/parse.js";
|
|
2
|
+
import { ParseError } from "../../common/types.js";
|
|
3
|
+
import { isLocalDate } from "../../tt/utils/date.js";
|
|
4
|
+
import { parseLessonType } from "../../common/lesson-type.js";
|
|
5
|
+
import { parseGroupsString } from "../../tt/parse/groups.js";
|
|
6
|
+
import { splitWebinarLesson } from "./webinar-lesson.js";
|
|
7
|
+
function dateValue(value) {
|
|
8
|
+
return value && isLocalDate(value) ? value : undefined;
|
|
9
|
+
}
|
|
10
|
+
function timeValue(value) {
|
|
11
|
+
return value.match(/\b(?:[01]\d|2[0-3]):[0-5]\d\b/u)?.[0];
|
|
12
|
+
}
|
|
13
|
+
export function parseWebinarPage(html) {
|
|
14
|
+
const doc = parseHtml(html);
|
|
15
|
+
const select = doc.querySelector('select[name="day"]');
|
|
16
|
+
if (!select && !doc.querySelector("table.webtable")) {
|
|
17
|
+
throw new ParseError("LK response has no webinar page");
|
|
18
|
+
}
|
|
19
|
+
const scriptDate = html.match(/\$\(['"]#day['"]\)\.val\(['"]([^'"]+)['"]\)/u)?.[1];
|
|
20
|
+
const date = dateValue(scriptDate) ?? dateValue(select?.querySelector("option[selected]")?.getAttribute("value")) ?? dateValue(select?.querySelector("option")?.getAttribute("value"));
|
|
21
|
+
const availableDates = [...(select?.querySelectorAll("option") ?? [])]
|
|
22
|
+
.map((option) => dateValue(option.getAttribute("value")))
|
|
23
|
+
.filter((value) => value !== undefined);
|
|
24
|
+
const webinars = [];
|
|
25
|
+
for (const table of doc.querySelectorAll("table.webtable")) {
|
|
26
|
+
const heading = text(table.parentElement?.querySelector("h3") ?? null);
|
|
27
|
+
const scheduled = /по расписанию/iu.test(heading);
|
|
28
|
+
for (const row of table.querySelectorAll("tbody > tr")) {
|
|
29
|
+
const cells = [...row.children];
|
|
30
|
+
if (cells.length < 6)
|
|
31
|
+
continue;
|
|
32
|
+
const start = timeValue(text(cells[0]));
|
|
33
|
+
const end = timeValue(text(cells[1]));
|
|
34
|
+
if (!start || !end)
|
|
35
|
+
continue;
|
|
36
|
+
const raw = text(cells[3]);
|
|
37
|
+
const lesson = splitWebinarLesson(raw);
|
|
38
|
+
const button = cells[5].querySelector('[onclick*="jointo"]');
|
|
39
|
+
const id = button?.getAttribute("onclick")?.match(/jointo\(\s*['"]?(\d+)['"]?\s*\)/u)?.[1] ?? null;
|
|
40
|
+
const server = cells[5].cloneNode(true);
|
|
41
|
+
for (const control of server.querySelectorAll("button"))
|
|
42
|
+
control.remove();
|
|
43
|
+
const slot = text(cells[0]).match(/\((\d+)\)/u)?.[1];
|
|
44
|
+
webinars.push({
|
|
45
|
+
id,
|
|
46
|
+
scheduled,
|
|
47
|
+
scheduledDate: date,
|
|
48
|
+
slotNumber: slot ? Number(slot) : undefined,
|
|
49
|
+
time: { start: parseTime(start), end: parseTime(end) },
|
|
50
|
+
subject: lesson.subject,
|
|
51
|
+
type: parseLessonType(lesson.type),
|
|
52
|
+
teacher: parseTeacher(lesson.teacherRaw),
|
|
53
|
+
groups: parseGroupsString(lesson.groupsRaw),
|
|
54
|
+
subgroup: lesson.subgroup,
|
|
55
|
+
title: text(cells[2]),
|
|
56
|
+
raw,
|
|
57
|
+
server: text(server),
|
|
58
|
+
completedAt: text(cells[4]) || null,
|
|
59
|
+
joinAvailable: id !== null && !button?.hasAttribute("disabled"),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return { date, availableDates: [...new Set(availableDates)], webinars };
|
|
64
|
+
}
|
|
65
|
+
export function parseWebinars(html) {
|
|
66
|
+
return parseWebinarPage(html).webinars;
|
|
67
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { LessonType } from "../common/lesson-type.js";
|
|
2
|
+
export type PortfolioGradeValue = number | boolean | null;
|
|
3
|
+
/** Displayed content only; scripts and profile-changing controls are excluded. */
|
|
4
|
+
export interface PortfolioLink {
|
|
5
|
+
text: string;
|
|
6
|
+
url: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
content?: PortfolioContent[];
|
|
9
|
+
}
|
|
10
|
+
export interface PortfolioCell {
|
|
11
|
+
text: string;
|
|
12
|
+
header: boolean;
|
|
13
|
+
colspan: number;
|
|
14
|
+
rowspan: number;
|
|
15
|
+
links: PortfolioLink[];
|
|
16
|
+
/** Tooltips often contain department names or grade details. */
|
|
17
|
+
notes: string[];
|
|
18
|
+
content: PortfolioContent[];
|
|
19
|
+
}
|
|
20
|
+
export interface PortfolioTable {
|
|
21
|
+
rows: PortfolioCell[][];
|
|
22
|
+
}
|
|
23
|
+
export type PortfolioContent = {
|
|
24
|
+
kind: "text";
|
|
25
|
+
text: string;
|
|
26
|
+
} | {
|
|
27
|
+
kind: "heading";
|
|
28
|
+
level: number;
|
|
29
|
+
text: string;
|
|
30
|
+
} | {
|
|
31
|
+
kind: "link";
|
|
32
|
+
link: PortfolioLink;
|
|
33
|
+
} | {
|
|
34
|
+
kind: "image";
|
|
35
|
+
url: string;
|
|
36
|
+
alt: string;
|
|
37
|
+
title?: string;
|
|
38
|
+
} | {
|
|
39
|
+
kind: "table";
|
|
40
|
+
table: PortfolioTable;
|
|
41
|
+
} | {
|
|
42
|
+
kind: "group";
|
|
43
|
+
label?: string;
|
|
44
|
+
content: PortfolioContent[];
|
|
45
|
+
};
|
|
46
|
+
export interface PortfolioSection {
|
|
47
|
+
title: string;
|
|
48
|
+
content: PortfolioContent[];
|
|
49
|
+
}
|
|
50
|
+
/** Referral metadata is parsed only. No order is submitted. */
|
|
51
|
+
export interface PortfolioReferral {
|
|
52
|
+
semester: number;
|
|
53
|
+
disciplineId: number;
|
|
54
|
+
lessonTypeId: number;
|
|
55
|
+
type: number;
|
|
56
|
+
key: number;
|
|
57
|
+
code: string;
|
|
58
|
+
}
|
|
59
|
+
export interface PortfolioGrade {
|
|
60
|
+
semester: number;
|
|
61
|
+
code: string;
|
|
62
|
+
subject: string;
|
|
63
|
+
assessment: LessonType;
|
|
64
|
+
/** Numeric grade, credit result, or null when no recognized grade is reported. */
|
|
65
|
+
grade: PortfolioGradeValue;
|
|
66
|
+
notes: string[];
|
|
67
|
+
referral?: PortfolioReferral;
|
|
68
|
+
}
|
|
69
|
+
export interface PortfolioControlWeek {
|
|
70
|
+
semester: number;
|
|
71
|
+
subject: string;
|
|
72
|
+
grades: (number | null)[];
|
|
73
|
+
}
|
|
74
|
+
export interface PortfolioAttendance {
|
|
75
|
+
month: string;
|
|
76
|
+
day: number;
|
|
77
|
+
slotNumber: number;
|
|
78
|
+
type: LessonType;
|
|
79
|
+
subgroup?: number;
|
|
80
|
+
/** Preserve +, Н, numeric grades and empty cells without reinterpretation. */
|
|
81
|
+
mark: string;
|
|
82
|
+
notes: string[];
|
|
83
|
+
}
|
|
84
|
+
export interface PortfolioActivity {
|
|
85
|
+
title: string;
|
|
86
|
+
value: string;
|
|
87
|
+
notes: string[];
|
|
88
|
+
links: PortfolioLink[];
|
|
89
|
+
content: PortfolioContent[];
|
|
90
|
+
}
|
|
91
|
+
export interface PortfolioPerformance {
|
|
92
|
+
subject: string;
|
|
93
|
+
attendance: PortfolioAttendance[];
|
|
94
|
+
activities: {
|
|
95
|
+
teacher: string;
|
|
96
|
+
items: PortfolioActivity[];
|
|
97
|
+
}[];
|
|
98
|
+
}
|
|
99
|
+
export interface StudentPortfolio {
|
|
100
|
+
id: number;
|
|
101
|
+
url: string;
|
|
102
|
+
student: {
|
|
103
|
+
fullName: string;
|
|
104
|
+
photoUrl?: string;
|
|
105
|
+
/** All displayed identity fields keyed by their original LK labels. */
|
|
106
|
+
fields: Record<string, string>;
|
|
107
|
+
};
|
|
108
|
+
grades: PortfolioGrade[];
|
|
109
|
+
controlWeeks: PortfolioControlWeek[];
|
|
110
|
+
performance: PortfolioPerformance[];
|
|
111
|
+
/** All tabs, including achievements, interests, practices, coursework and thesis. */
|
|
112
|
+
sections: PortfolioSection[];
|
|
113
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/lk/types.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { LocalDate, Teacher, TimeRange } from "../common/types.js";
|
|
1
2
|
import type { BlobAdapter, CacheAdapter } from "../common/cache.js";
|
|
3
|
+
import type { LessonType } from "../common/lesson-type.js";
|
|
2
4
|
export interface StudentProfile {
|
|
3
5
|
lastName: string;
|
|
4
6
|
firstName: string;
|
|
@@ -18,9 +20,36 @@ export interface StudentPortalCacheConfig {
|
|
|
18
20
|
profile?: number;
|
|
19
21
|
profilePhoto?: number;
|
|
20
22
|
timetableGroupId?: number;
|
|
23
|
+
webinars?: number;
|
|
24
|
+
portfolio?: number;
|
|
21
25
|
}
|
|
22
26
|
export interface StudentPortalClientOptions {
|
|
23
27
|
cache?: number | StudentPortalCacheConfig;
|
|
24
28
|
cacheAdapter?: CacheAdapter;
|
|
25
29
|
blobAdapter?: BlobAdapter;
|
|
26
30
|
}
|
|
31
|
+
/** A row from LK's personal webinar page, including unavailable meetings. */
|
|
32
|
+
export interface Webinar {
|
|
33
|
+
/** Null when LK does not expose a join button. Never a timetable ID. */
|
|
34
|
+
id: string | null;
|
|
35
|
+
scheduled: boolean;
|
|
36
|
+
scheduledDate?: LocalDate;
|
|
37
|
+
slotNumber?: number;
|
|
38
|
+
time: TimeRange;
|
|
39
|
+
subject: string;
|
|
40
|
+
type: LessonType;
|
|
41
|
+
teacher: Teacher;
|
|
42
|
+
groups: string[];
|
|
43
|
+
subgroup?: number;
|
|
44
|
+
title: string;
|
|
45
|
+
raw: string;
|
|
46
|
+
server: string;
|
|
47
|
+
completedAt: string | null;
|
|
48
|
+
joinAvailable: boolean;
|
|
49
|
+
}
|
|
50
|
+
export interface WebinarPage {
|
|
51
|
+
/** Selected date reported by LK; never inferred from the machine timezone. */
|
|
52
|
+
date?: LocalDate;
|
|
53
|
+
availableDates: LocalDate[];
|
|
54
|
+
webinars: Webinar[];
|
|
55
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { LessonOccurrence } from "
|
|
1
|
+
import type { LessonOccurrence } from "../tt/domain/types.js";
|
|
2
2
|
import type { Webinar } from "./types.js";
|
|
3
3
|
export type LessonWithWebinar = LessonOccurrence & {
|
|
4
4
|
webinar?: Webinar;
|
|
5
5
|
};
|
|
6
6
|
export declare function findWebinar(lesson: LessonOccurrence, webinars: Webinar[]): Webinar | undefined;
|
|
7
|
+
/** Match scheduled date, slot (time when unavailable), and known group/subgroup. */
|
|
8
|
+
export declare function findWebinars(lesson: LessonOccurrence, webinars: Webinar[]): Webinar[];
|
|
7
9
|
export declare function attachWebinars(lessons: LessonOccurrence[], webinars: Webinar[]): LessonWithWebinar[];
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
function normalize(value) {
|
|
2
|
+
return value
|
|
3
|
+
.toLocaleLowerCase("ru-RU")
|
|
4
|
+
.replace(/ё/gu, "е")
|
|
5
|
+
.replace(/\s+/gu, " ")
|
|
6
|
+
.trim();
|
|
7
|
+
}
|
|
8
|
+
export function findWebinar(lesson, webinars) {
|
|
9
|
+
const matches = findWebinars(lesson, webinars);
|
|
10
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
11
|
+
}
|
|
12
|
+
/** Match scheduled date, slot (time when unavailable), and known group/subgroup. */
|
|
13
|
+
export function findWebinars(lesson, webinars) {
|
|
14
|
+
if (lesson.status === "cancelled")
|
|
15
|
+
return [];
|
|
16
|
+
return webinars.filter((webinar) => {
|
|
17
|
+
if (!webinar.scheduled)
|
|
18
|
+
return false;
|
|
19
|
+
if (webinar.scheduledDate !== lesson.scheduledDate)
|
|
20
|
+
return false;
|
|
21
|
+
if (webinar.slotNumber != null && lesson.slotNumber != null) {
|
|
22
|
+
if (webinar.slotNumber !== lesson.slotNumber)
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
else if (!lesson.time ||
|
|
26
|
+
webinar.time.start.hours !== lesson.time.start.hours ||
|
|
27
|
+
webinar.time.start.minutes !== lesson.time.start.minutes ||
|
|
28
|
+
webinar.time.end.hours !== lesson.time.end.hours ||
|
|
29
|
+
webinar.time.end.minutes !== lesson.time.end.minutes) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const groups = lesson.groups.values;
|
|
33
|
+
const attendance = webinar.groups.length
|
|
34
|
+
? groups.filter((entry) => webinar.groups.some((group) => normalize(group) === normalize(entry.group.name)))
|
|
35
|
+
: groups;
|
|
36
|
+
if (groups.length && !attendance.length)
|
|
37
|
+
return false;
|
|
38
|
+
if (webinar.subgroup != null && attendance.length && !attendance.some((entry) => entry.subgroup == null || entry.subgroup === webinar.subgroup))
|
|
39
|
+
return false;
|
|
40
|
+
return true;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export function attachWebinars(lessons, webinars) {
|
|
44
|
+
return lessons.map((lesson) => {
|
|
45
|
+
const webinar = findWebinar(lesson, webinars);
|
|
46
|
+
return webinar ? { ...lesson, webinar } : lesson;
|
|
47
|
+
});
|
|
48
|
+
}
|
package/dist/parsers.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export { parseAcademicYearFromPage, parseAvailablePeriodsFromPage, parseRoomButtons, parseRoomSchedule, parseRoomInfo, parseRoomName, parseFacultyButtons, parseGroupSchedule, parseGroupName, parseGroupButtons, parseGroupsString, parsePeriodFromPage, parseTeacherButtons, parseTeacherSchedule, parseTeacherInfo,
|
|
1
|
+
export { parseAcademicYearFromPage, parseAvailablePeriodsFromPage, parseRoomButtons, parseRoomSchedule, parseRoomInfo, parseRoomName, parseFacultyButtons, parseGroupSchedule, parseGroupName, parseGroupButtons, parseGroupsString, parsePeriodFromPage, parseTeacherButtons, parseTeacherSchedule, parseTeacherInfo, } from "./tt/parse/index.js";
|
|
2
2
|
export { createScheduleSourceSnapshot } from "./tt/observations.js";
|
|
3
3
|
export type { ParsedScheduleDay, ParsedLesson, ParsedScheduleBlock, } from "./tt/types.js";
|
|
4
|
+
export { parseWebinars, parseWebinarPage } from "./lk/parse/webinars.js";
|
|
5
|
+
export { parsePortfolio, parsePortfolioUrl } from "./lk/parse/portfolio.js";
|
package/dist/parsers.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export { parseAcademicYearFromPage, parseAvailablePeriodsFromPage, parseRoomButtons, parseRoomSchedule, parseRoomInfo, parseRoomName, parseFacultyButtons, parseGroupSchedule, parseGroupName, parseGroupButtons, parseGroupsString, parsePeriodFromPage, parseTeacherButtons, parseTeacherSchedule, parseTeacherInfo,
|
|
1
|
+
export { parseAcademicYearFromPage, parseAvailablePeriodsFromPage, parseRoomButtons, parseRoomSchedule, parseRoomInfo, parseRoomName, parseFacultyButtons, parseGroupSchedule, parseGroupName, parseGroupButtons, parseGroupsString, parsePeriodFromPage, parseTeacherButtons, parseTeacherSchedule, parseTeacherInfo, } from "./tt/parse/index.js";
|
|
2
2
|
export { createScheduleSourceSnapshot } from "./tt/observations.js";
|
|
3
|
+
export { parseWebinars, parseWebinarPage } from "./lk/parse/webinars.js";
|
|
4
|
+
export { parsePortfolio, parsePortfolioUrl } from "./lk/parse/portfolio.js";
|
package/dist/tt/client.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { CacheEntry } from "../common/cache.js";
|
|
|
2
2
|
import { Schedule } from "./domain/schedule.js";
|
|
3
3
|
import { TimetableRepository } from "./domain/repository.js";
|
|
4
4
|
import type { GroupRef, RoomRef, ScheduleOwner, TeacherRef, TimetableRepositorySnapshot } from "./domain/types.js";
|
|
5
|
-
import type { Room, RoomInfo, Faculty, Group, TeacherInfo, TimetableClientOptions, CacheConfig, DirectoryPreloadOptions, EntityResolutionStrategy, GetScheduleOptions
|
|
5
|
+
import type { Room, RoomInfo, Faculty, Group, TeacherInfo, TimetableClientOptions, CacheConfig, DirectoryPreloadOptions, EntityResolutionStrategy, GetScheduleOptions } from "./types.js";
|
|
6
6
|
export declare class TimetableClient {
|
|
7
7
|
private http;
|
|
8
8
|
private educationLevel;
|
|
@@ -48,16 +48,6 @@ export declare class TimetableClient {
|
|
|
48
48
|
private fetchOwnerSchedule;
|
|
49
49
|
getSchedule(owner: ScheduleOwner, options?: GetScheduleOptions): Promise<Schedule>;
|
|
50
50
|
getGroupSchedule(groupId: number, options?: GetScheduleOptions): Promise<Schedule>;
|
|
51
|
-
getWebinars(opts?: {
|
|
52
|
-
date?: Date;
|
|
53
|
-
facultyId?: number;
|
|
54
|
-
}): Promise<Webinar[]>;
|
|
55
|
-
getWebinarJoinUrl(opts: {
|
|
56
|
-
webinarId: string | number;
|
|
57
|
-
idType?: number;
|
|
58
|
-
email: string;
|
|
59
|
-
password: string;
|
|
60
|
-
}): Promise<string>;
|
|
61
51
|
getFaculties(): Promise<Faculty[]>;
|
|
62
52
|
getFacultyGroups(facultyId: number): Promise<Group[]>;
|
|
63
53
|
searchGroups(name: string): Promise<GroupRef[]>;
|
package/dist/tt/client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HttpClient, } from "../common/http.js";
|
|
2
2
|
import { HybridCache } from "../common/cache.js";
|
|
3
3
|
import { AcademicPeriod, AuthError, EducationLevel, ParseError, } from "../common/types.js";
|
|
4
|
-
import { parseAcademicYearFromPage, parseAvailablePeriodsFromPage, parseRoomButtons, parseRoomSchedule, parseRoomInfo, parseRoomName, parseGroupButtons, parseGroupName, parseFacultyButtons, parseTeacherButtons, parseGroupSchedule, parseTeacherSchedule, parseTeacherInfo, parsePeriodFromPage,
|
|
4
|
+
import { parseAcademicYearFromPage, parseAvailablePeriodsFromPage, parseRoomButtons, parseRoomSchedule, parseRoomInfo, parseRoomName, parseGroupButtons, parseGroupName, parseFacultyButtons, parseTeacherButtons, parseGroupSchedule, parseTeacherSchedule, parseTeacherInfo, parsePeriodFromPage, } from "./parse/index.js";
|
|
5
5
|
import { Schedule } from "./domain/schedule.js";
|
|
6
6
|
import { TimetableRepository } from "./domain/repository.js";
|
|
7
7
|
import { createScheduleSourceSnapshot } from "./observations.js";
|
|
@@ -57,15 +57,8 @@ function makeUniformCacheConfig(ttl) {
|
|
|
57
57
|
teacherPhotos: ttl,
|
|
58
58
|
roomInfo: ttl,
|
|
59
59
|
roomImages: ttl,
|
|
60
|
-
webinars: ttl,
|
|
61
60
|
};
|
|
62
61
|
}
|
|
63
|
-
function formatDate(date) {
|
|
64
|
-
const year = date.getFullYear();
|
|
65
|
-
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
66
|
-
const day = String(date.getDate()).padStart(2, "0");
|
|
67
|
-
return `${year}-${month}-${day}`;
|
|
68
|
-
}
|
|
69
62
|
export class TimetableClient {
|
|
70
63
|
http = new HttpClient();
|
|
71
64
|
educationLevel;
|
|
@@ -400,43 +393,6 @@ export class TimetableClient {
|
|
|
400
393
|
group: this._repository.directory.resolveGroup({ id: groupId, name: "" }),
|
|
401
394
|
}, options);
|
|
402
395
|
}
|
|
403
|
-
async getWebinars(opts) {
|
|
404
|
-
const date = opts?.date ?? new Date();
|
|
405
|
-
const facultyId = opts?.facultyId ?? 0;
|
|
406
|
-
const cacheKey = `${formatDate(date)}:${facultyId}:${this.pertt}`;
|
|
407
|
-
const cached = await this.cache?.get("webinars", cacheKey);
|
|
408
|
-
if (cached)
|
|
409
|
-
return cached;
|
|
410
|
-
const { body } = await this.authPost(`${BASE}/webinar`, {
|
|
411
|
-
seldate: formatDate(date),
|
|
412
|
-
selfac: String(facultyId),
|
|
413
|
-
pertt: this.pertt,
|
|
414
|
-
});
|
|
415
|
-
const data = parseWebinars(body);
|
|
416
|
-
await this.cache?.set("webinars", cacheKey, data);
|
|
417
|
-
return data;
|
|
418
|
-
}
|
|
419
|
-
async getWebinarJoinUrl(opts) {
|
|
420
|
-
const { body } = await this.authPost(`${BASE}/webinar/getjoin`, {
|
|
421
|
-
idw: String(opts.webinarId),
|
|
422
|
-
idwt: String(opts.idType ?? 1),
|
|
423
|
-
name: opts.email,
|
|
424
|
-
pass: opts.password,
|
|
425
|
-
auto: "1",
|
|
426
|
-
});
|
|
427
|
-
let parsed;
|
|
428
|
-
try {
|
|
429
|
-
parsed = JSON.parse(body);
|
|
430
|
-
}
|
|
431
|
-
catch {
|
|
432
|
-
throw new AuthError("TT webinar join failed: invalid response");
|
|
433
|
-
}
|
|
434
|
-
const data = parsed;
|
|
435
|
-
if (data.mes !== "SUCCESS" || !data.url?.startsWith("http")) {
|
|
436
|
-
throw new AuthError(data.mes ?? "TT webinar join failed");
|
|
437
|
-
}
|
|
438
|
-
return data.url;
|
|
439
|
-
}
|
|
440
396
|
// --- Search / Discovery ---
|
|
441
397
|
async getFaculties() {
|
|
442
398
|
const cached = await this.cache?.get("faculties", "all");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AcademicPeriod, LocalDate, TimeRange, WeekRange } from "../../common/types.js";
|
|
2
|
-
import type { LessonType } from "
|
|
2
|
+
import type { LessonType } from "../../common/lesson-type.js";
|
|
3
3
|
export type LessonSeriesId = string;
|
|
4
4
|
export type LessonId = string;
|
|
5
5
|
export interface NamedEntityRef {
|
package/dist/tt/observations.js
CHANGED
package/dist/tt/parse/index.d.ts
CHANGED
|
@@ -3,4 +3,3 @@ export { parseAcademicYearFromPage, parseAvailablePeriodsFromPage, parseRoomButt
|
|
|
3
3
|
export { parseGroupSchedule } from "./full-schedule.js";
|
|
4
4
|
export { parseRoomSchedule, parseRoomInfo, } from "./audience.js";
|
|
5
5
|
export { parseTeacherSchedule, parseTeacherInfo, } from "./teacher.js";
|
|
6
|
-
export { parseWebinars } from "./webinars.js";
|
package/dist/tt/parse/index.js
CHANGED
|
@@ -3,4 +3,3 @@ export { parseAcademicYearFromPage, parseAvailablePeriodsFromPage, parseRoomButt
|
|
|
3
3
|
export { parseGroupSchedule } from "./full-schedule.js";
|
|
4
4
|
export { parseRoomSchedule, parseRoomInfo, } from "./audience.js";
|
|
5
5
|
export { parseTeacherSchedule, parseTeacherInfo, } from "./teacher.js";
|
|
6
|
-
export { parseWebinars } from "./webinars.js";
|
package/dist/tt/types.d.ts
CHANGED
|
@@ -130,26 +130,6 @@ export interface SemesterWeek {
|
|
|
130
130
|
start: Date;
|
|
131
131
|
end: Date;
|
|
132
132
|
}
|
|
133
|
-
export interface Webinar {
|
|
134
|
-
/** Internal tt.chuvsu.ru webinar id used by `/webinar/getjoin`. */
|
|
135
|
-
id: string;
|
|
136
|
-
/** Webinar table type argument (`idwt`) used by `/webinar/getjoin`. */
|
|
137
|
-
idType: number;
|
|
138
|
-
/** True for "Вебинары по расписанию"; false for external webinars. */
|
|
139
|
-
scheduled: boolean;
|
|
140
|
-
scheduledDate?: LocalDate;
|
|
141
|
-
slotNumber?: number;
|
|
142
|
-
time: TimeRange;
|
|
143
|
-
subject: string;
|
|
144
|
-
type: string;
|
|
145
|
-
teacher: Teacher;
|
|
146
|
-
groups: string[];
|
|
147
|
-
subgroup?: number;
|
|
148
|
-
/** Free-form title/topic from the second table column. */
|
|
149
|
-
title: string;
|
|
150
|
-
/** Raw first-column text as rendered by tt.chuvsu.ru. */
|
|
151
|
-
raw: string;
|
|
152
|
-
}
|
|
153
133
|
export interface CacheConfig {
|
|
154
134
|
schedule?: number;
|
|
155
135
|
faculties?: number;
|
|
@@ -161,7 +141,6 @@ export interface CacheConfig {
|
|
|
161
141
|
teacherPhotos?: number;
|
|
162
142
|
roomInfo?: number;
|
|
163
143
|
roomImages?: number;
|
|
164
|
-
webinars?: number;
|
|
165
144
|
}
|
|
166
145
|
export interface TimetableClientOptions {
|
|
167
146
|
educationLevel?: EducationLevel;
|
package/dist/tt/utils/index.d.ts
CHANGED
|
@@ -2,6 +2,5 @@ export { formatLocalDate, getMonday, getWeekdayName, isSameDay, isLocalDate, par
|
|
|
2
2
|
export { getAdjacentSemester, getCurrentPeriod, isSessionPeriod, } from "./period.js";
|
|
3
3
|
export { getSemesterStart, getSemesterWeeks, getWeekNumber, } from "./semester.js";
|
|
4
4
|
export { getStandardScheduleBlocks } from "./time-slots.js";
|
|
5
|
-
export { LessonType, parseLessonType } from "./lesson-type.js";
|
|
6
5
|
export { getCompensatingWorkDays, getEffectiveHolidays, getHolidayTransfers, isHoliday, RUSSIAN_HOLIDAYS, } from "./holidays.js";
|
|
7
6
|
export type { Holiday, HolidayTransfer } from "./holidays.js";
|
package/dist/tt/utils/index.js
CHANGED
|
@@ -2,5 +2,4 @@ export { formatLocalDate, getMonday, getWeekdayName, isSameDay, isLocalDate, par
|
|
|
2
2
|
export { getAdjacentSemester, getCurrentPeriod, isSessionPeriod, } from "./period.js";
|
|
3
3
|
export { getSemesterStart, getSemesterWeeks, getWeekNumber, } from "./semester.js";
|
|
4
4
|
export { getStandardScheduleBlocks } from "./time-slots.js";
|
|
5
|
-
export { LessonType, parseLessonType } from "./lesson-type.js";
|
|
6
5
|
export { getCompensatingWorkDays, getEffectiveHolidays, getHolidayTransfers, isHoliday, RUSSIAN_HOLIDAYS, } from "./holidays.js";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type WebinarClientOptions, type WebinarEvent, type WebinarSession } from "./types.js";
|
|
2
|
+
/** Live participant state and explicit actions; never auto-connects media. */
|
|
3
|
+
export declare class WebinarClient {
|
|
4
|
+
private ddp;
|
|
5
|
+
private session;
|
|
6
|
+
private history;
|
|
7
|
+
private listeners;
|
|
8
|
+
private ready;
|
|
9
|
+
private started;
|
|
10
|
+
constructor(session: WebinarSession, opts?: WebinarClientOptions);
|
|
11
|
+
connect(): Promise<void>;
|
|
12
|
+
private assertConnected;
|
|
13
|
+
getSnapshot(): import("./types.js").WebinarSnapshot;
|
|
14
|
+
getUsers(): import("./types.js").WebinarUser[];
|
|
15
|
+
getPresenter(): import("./types.js").WebinarUser | null;
|
|
16
|
+
getModerators(): import("./types.js").WebinarUser[];
|
|
17
|
+
getChats(): import("./types.js").WebinarChat[];
|
|
18
|
+
getMessages(opts?: {
|
|
19
|
+
chatId?: string;
|
|
20
|
+
}): import("./types.js").WebinarMessage[];
|
|
21
|
+
getPresentations(): import("./types.js").WebinarPresentation[];
|
|
22
|
+
getCurrentPresentation(): import("./types.js").WebinarPresentation | null;
|
|
23
|
+
getMediaStreams(): import("./types.js").WebinarMediaStream[];
|
|
24
|
+
getNotes(): import("./types.js").WebinarNotes | null;
|
|
25
|
+
/** Reads historical pages; live messages arrive through events(). */
|
|
26
|
+
loadMessages(opts?: {
|
|
27
|
+
chatId?: string;
|
|
28
|
+
page?: number;
|
|
29
|
+
}): Promise<import("./types.js").WebinarMessage[]>;
|
|
30
|
+
subscribe(listener: (event: WebinarEvent) => void): () => void;
|
|
31
|
+
events(opts?: {
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
bufferSize?: number;
|
|
34
|
+
}): AsyncGenerator<WebinarEvent, any, any>;
|
|
35
|
+
private emit;
|
|
36
|
+
private assertPermission;
|
|
37
|
+
setRaisedHand(raised: boolean): Promise<void>;
|
|
38
|
+
sendMessage(opts: {
|
|
39
|
+
text: string;
|
|
40
|
+
chatId?: string;
|
|
41
|
+
}): Promise<void>;
|
|
42
|
+
openPrivateChat(opts: {
|
|
43
|
+
userId: string;
|
|
44
|
+
}): Promise<import("./types.js").WebinarChat>;
|
|
45
|
+
sendPrivateMessage(opts: {
|
|
46
|
+
userId: string;
|
|
47
|
+
text: string;
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
setMuted(muted: boolean): Promise<void>;
|
|
50
|
+
/** Closes local transport; does not issue userLeftMeeting or alter other users. */
|
|
51
|
+
close(): void;
|
|
52
|
+
}
|