@robertying/thu-learn-lib 0.0.0-stage → 5.0.0
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/LICENSE +21 -0
- package/README.md +324 -2
- package/lib/auth.d.ts +11 -0
- package/lib/auth.d.ts.map +1 -0
- package/lib/auth.js +99 -0
- package/lib/auth.js.map +1 -0
- package/lib/calendar.d.ts +16 -0
- package/lib/calendar.d.ts.map +1 -0
- package/lib/calendar.js +81 -0
- package/lib/calendar.js.map +1 -0
- package/lib/contents.d.ts +9 -0
- package/lib/contents.d.ts.map +1 -0
- package/lib/contents.js +51 -0
- package/lib/contents.js.map +1 -0
- package/lib/courses.d.ts +11 -0
- package/lib/courses.d.ts.map +1 -0
- package/lib/courses.js +94 -0
- package/lib/courses.js.map +1 -0
- package/lib/discussions.d.ts +11 -0
- package/lib/discussions.d.ts.map +1 -0
- package/lib/discussions.js +56 -0
- package/lib/discussions.js.map +1 -0
- package/lib/favorites.d.ts +35 -0
- package/lib/favorites.d.ts.map +1 -0
- package/lib/favorites.js +150 -0
- package/lib/favorites.js.map +1 -0
- package/lib/files.d.ts +13 -0
- package/lib/files.d.ts.map +1 -0
- package/lib/files.js +167 -0
- package/lib/files.js.map +1 -0
- package/lib/homework.d.ts +17 -0
- package/lib/homework.d.ts.map +1 -0
- package/lib/homework.js +194 -0
- package/lib/homework.js.map +1 -0
- package/lib/index.d.ts +134 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +219 -0
- package/lib/index.js.map +1 -0
- package/lib/notices.d.ts +14 -0
- package/lib/notices.d.ts.map +1 -0
- package/lib/notices.js +92 -0
- package/lib/notices.js.map +1 -0
- package/lib/questionnaires.d.ts +7 -0
- package/lib/questionnaires.d.ts.map +1 -0
- package/lib/questionnaires.js +62 -0
- package/lib/questionnaires.js.map +1 -0
- package/lib/request.d.ts +57 -0
- package/lib/request.d.ts.map +1 -0
- package/lib/request.js +197 -0
- package/lib/request.js.map +1 -0
- package/lib/types.d.ts +433 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +98 -0
- package/lib/types.js.map +1 -0
- package/lib/urls.d.ts +78 -0
- package/lib/urls.d.ts.map +1 -0
- package/lib/urls.js +160 -0
- package/lib/urls.js.map +1 -0
- package/lib/user.d.ts +7 -0
- package/lib/user.d.ts.map +1 -0
- package/lib/user.js +22 -0
- package/lib/user.js.map +1 -0
- package/lib/utils.d.ts +16 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +117 -0
- package/lib/utils.js.map +1 -0
- package/package.json +67 -4
- package/src/auth.ts +121 -0
- package/src/calendar.ts +102 -0
- package/src/contents.ts +63 -0
- package/src/courses.ts +111 -0
- package/src/discussions.ts +80 -0
- package/src/favorites.ts +167 -0
- package/src/files.ts +197 -0
- package/src/homework.ts +284 -0
- package/src/index.ts +345 -0
- package/src/notices.ts +115 -0
- package/src/questionnaires.ts +76 -0
- package/src/request.ts +214 -0
- package/src/types.ts +494 -0
- package/src/urls.ts +257 -0
- package/src/user.ts +28 -0
- package/src/utils.ts +125 -0
package/lib/homework.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// Homework (课程作业), excellent homework and homework submission.
|
|
2
|
+
import { Base64 } from 'js-base64';
|
|
3
|
+
import { $, YES } from './request.js';
|
|
4
|
+
import { ContentType, CourseType, FailReason } from './types.js';
|
|
5
|
+
import * as URLS from './urls.js';
|
|
6
|
+
import { GRADE_LEVEL_MAP, decodeHTML, isSelected, trimAndDefine } from './utils.js';
|
|
7
|
+
export async function getHomeworkList(s, courseID, courseType = CourseType.STUDENT, options = {}) {
|
|
8
|
+
if (courseType === CourseType.TEACHER) {
|
|
9
|
+
const json = await (await s.fetchWithToken(URLS.LEARN_HOMEWORK_LIST_TEACHER, {
|
|
10
|
+
method: 'POST',
|
|
11
|
+
body: URLS.LEARN_PAGE_LIST_FORM_DATA(courseID),
|
|
12
|
+
})).json();
|
|
13
|
+
if (json.result !== 'success') {
|
|
14
|
+
return Promise.reject({
|
|
15
|
+
reason: FailReason.INVALID_RESPONSE,
|
|
16
|
+
extra: json,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const result = (json.object?.aaData ?? []);
|
|
20
|
+
return result.map((d) => ({
|
|
21
|
+
id: d.zyid,
|
|
22
|
+
index: d.wz,
|
|
23
|
+
title: decodeHTML(d.bt),
|
|
24
|
+
description: decodeHTML(Base64.decode(d.nr)),
|
|
25
|
+
publisherId: d.fbr,
|
|
26
|
+
publishTime: d.fbsj,
|
|
27
|
+
startTime: d.kssj,
|
|
28
|
+
deadline: d.jzsj,
|
|
29
|
+
lateSubmissionDeadline: d.bjjzsj ?? undefined,
|
|
30
|
+
url: URLS.LEARN_HOMEWORK_DETAIL_TEACHER(courseID, d.zyid),
|
|
31
|
+
completionType: d.zywcfs,
|
|
32
|
+
submissionType: d.zytjfs,
|
|
33
|
+
gradedCount: d.ypys,
|
|
34
|
+
submittedCount: d.yjs,
|
|
35
|
+
unsubmittedCount: d.wjs,
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const [lists, excellentHomeworkListByHomework] = await Promise.all([
|
|
40
|
+
Promise.all(URLS.LEARN_HOMEWORK_LIST_SOURCE.map((source) => getHomeworkListAtUrl(s, courseID, source.url, source.status))),
|
|
41
|
+
// Don't block the whole process if excellent homework list cannot be fetched
|
|
42
|
+
getExcellentHomeworkListByHomework(s, courseID).catch(() => ({})),
|
|
43
|
+
]);
|
|
44
|
+
return Promise.all(lists.flat().map(async (h) => {
|
|
45
|
+
const homework = { ...h, excellentHomeworkList: excellentHomeworkListByHomework[h.baseId] };
|
|
46
|
+
return isSelected(options.details, homework) ? { ...homework, ...(await getHomeworkDetail(s, h)) } : homework;
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function getHomeworkListAtUrl(s, courseID, url, status) {
|
|
51
|
+
const json = await (await s.fetchWithToken(url, {
|
|
52
|
+
method: 'POST',
|
|
53
|
+
body: URLS.LEARN_PAGE_LIST_FORM_DATA(courseID),
|
|
54
|
+
})).json();
|
|
55
|
+
if (json.result !== 'success') {
|
|
56
|
+
return Promise.reject({
|
|
57
|
+
reason: FailReason.INVALID_RESPONSE,
|
|
58
|
+
extra: json,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const result = (json.object?.aaData ?? []);
|
|
62
|
+
return result.map((h) => ({
|
|
63
|
+
id: h.xszyid,
|
|
64
|
+
studentHomeworkId: h.xszyid,
|
|
65
|
+
baseId: h.zyid,
|
|
66
|
+
title: decodeHTML(h.bt),
|
|
67
|
+
url: URLS.LEARN_HOMEWORK_PAGE(h.wlkcid, h.xszyid),
|
|
68
|
+
deadline: h.jzsj,
|
|
69
|
+
lateSubmissionDeadline: h.bjjzsj ? h.bjjzsj : undefined,
|
|
70
|
+
isLateSubmission: h.sfbj === YES,
|
|
71
|
+
completionType: h.zywcfs,
|
|
72
|
+
submissionType: h.zytjfs,
|
|
73
|
+
submitUrl: URLS.LEARN_HOMEWORK_SUBMIT_PAGE(h.wlkcid, h.xszyid),
|
|
74
|
+
submitTime: h.scsj === null ? undefined : h.scsj,
|
|
75
|
+
grade: h.cj === null ? undefined : h.cj,
|
|
76
|
+
gradeLevel: GRADE_LEVEL_MAP.get(h.cj),
|
|
77
|
+
graderName: trimAndDefine(h.jsm),
|
|
78
|
+
gradeContent: trimAndDefine(h.pynr),
|
|
79
|
+
gradeTime: h.pysj === null ? undefined : h.pysj,
|
|
80
|
+
isFavorite: h.sfsc === YES,
|
|
81
|
+
favoriteTime: h.scsj === null || h.sfsc !== YES ? undefined : h.scsj,
|
|
82
|
+
comment: h.bznr ?? undefined,
|
|
83
|
+
...status,
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
async function getExcellentHomeworkListByHomework(s, courseID) {
|
|
87
|
+
const json = await (await s.fetchWithToken(URLS.LEARN_HOMEWORK_LIST_EXCELLENT, {
|
|
88
|
+
method: 'POST',
|
|
89
|
+
body: URLS.LEARN_PAGE_LIST_FORM_DATA(courseID),
|
|
90
|
+
})).json();
|
|
91
|
+
if (json.result !== 'success') {
|
|
92
|
+
return Promise.reject({
|
|
93
|
+
reason: FailReason.INVALID_RESPONSE,
|
|
94
|
+
extra: json,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
const result = (json.object?.aaData ?? []);
|
|
98
|
+
return result
|
|
99
|
+
.map((h) => ({
|
|
100
|
+
id: h.xszyid,
|
|
101
|
+
baseId: h.zyid,
|
|
102
|
+
title: decodeHTML(h.bt),
|
|
103
|
+
url: URLS.LEARN_HOMEWORK_EXCELLENT_PAGE(h.wlkcid, h.xszyid),
|
|
104
|
+
completionType: h.zywcfs,
|
|
105
|
+
author: {
|
|
106
|
+
id: h.cy?.split(' ')?.[0],
|
|
107
|
+
name: h.cy?.split(' ')?.[1],
|
|
108
|
+
anonymous: h.sfzm === YES,
|
|
109
|
+
},
|
|
110
|
+
}))
|
|
111
|
+
.reduce((acc, cur) => {
|
|
112
|
+
if (!acc[cur.baseId]) {
|
|
113
|
+
acc[cur.baseId] = [];
|
|
114
|
+
}
|
|
115
|
+
acc[cur.baseId].push(cur);
|
|
116
|
+
return acc;
|
|
117
|
+
}, {});
|
|
118
|
+
}
|
|
119
|
+
async function parseHomeworkAtUrl(s, url) {
|
|
120
|
+
const response = await s.fetchWithToken(url);
|
|
121
|
+
const result = $(await response.text());
|
|
122
|
+
const fileDivs = result('div.list.fujian.clearfix');
|
|
123
|
+
return {
|
|
124
|
+
description: trimAndDefine(result('div.list.calendar.clearfix > div.fl.right > div.c55').slice(0, 1).html()),
|
|
125
|
+
answerContent: trimAndDefine(result('div.list.calendar.clearfix > div.fl.right > div.c55').slice(1, 2).html()),
|
|
126
|
+
submittedContent: trimAndDefine($(result('div.boxbox').slice(1, 2).toArray())('div.right').slice(2, 3).html()),
|
|
127
|
+
attachment: parseHomeworkFile(s, fileDivs[0]),
|
|
128
|
+
answerAttachment: parseHomeworkFile(s, fileDivs[1]),
|
|
129
|
+
submittedAttachment: parseHomeworkFile(s, fileDivs[2]),
|
|
130
|
+
gradeAttachment: parseHomeworkFile(s, fileDivs[3]),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get the detail of one homework or excellent homework: its page (answer, submitted content, attachments) and the
|
|
135
|
+
* description JSON (which wins for `description`). 2 requests.
|
|
136
|
+
*/
|
|
137
|
+
export async function getHomeworkDetail(s, homework) {
|
|
138
|
+
const [page, description] = await Promise.all([
|
|
139
|
+
parseHomeworkAtUrl(s, homework.url),
|
|
140
|
+
getHomeworkDescription(s, homework.baseId),
|
|
141
|
+
]);
|
|
142
|
+
return { ...page, ...description };
|
|
143
|
+
}
|
|
144
|
+
async function getHomeworkDescription(s, baseId) {
|
|
145
|
+
const json = await (await s.fetchWithToken(URLS.LEARN_HOMEWORK_DETAIL, {
|
|
146
|
+
method: 'POST',
|
|
147
|
+
body: URLS.LEARN_HOMEWORK_DETAIL_FORM_DATA(baseId),
|
|
148
|
+
})).json();
|
|
149
|
+
if (json.result !== 'success') {
|
|
150
|
+
throw {
|
|
151
|
+
reason: FailReason.INVALID_RESPONSE,
|
|
152
|
+
extra: json,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
description: trimAndDefine(json.msg),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function parseHomeworkFile(s, fileDiv) {
|
|
160
|
+
const fileNode = $(fileDiv)('.ftitle').children('a')[0] ?? $(fileDiv)('.fl').children('a')[0];
|
|
161
|
+
if (fileNode !== undefined) {
|
|
162
|
+
const size = trimAndDefine($(fileDiv)('.fl > span[class^="color"]').first().text());
|
|
163
|
+
const params = new URLSearchParams(fileNode.attribs.href.split('?').slice(-1)[0]);
|
|
164
|
+
const attachmentId = params.get('fileId');
|
|
165
|
+
// so dirty here...
|
|
166
|
+
let downloadUrl = URLS.LEARN_PREFIX + fileNode.attribs.href;
|
|
167
|
+
if (params.has('downloadUrl')) {
|
|
168
|
+
downloadUrl = URLS.LEARN_PREFIX + params.get('downloadUrl');
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
id: attachmentId,
|
|
172
|
+
name: fileNode.children[0].data,
|
|
173
|
+
downloadUrl,
|
|
174
|
+
previewUrl: URLS.LEARN_FILE_PREVIEW(ContentType.HOMEWORK, attachmentId, CourseType.STUDENT, s.previewFirstPage),
|
|
175
|
+
size,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
export async function submitHomework(s, id, content = '', attachment, removeAttachment = false) {
|
|
183
|
+
const json = await (await s.fetchWithToken(URLS.LEARN_HOMEWORK_SUBMIT(), {
|
|
184
|
+
method: 'POST',
|
|
185
|
+
body: URLS.LEARN_HOMEWORK_SUBMIT_FORM_DATA(id, content, attachment, removeAttachment),
|
|
186
|
+
})).json();
|
|
187
|
+
if (json.result !== 'success') {
|
|
188
|
+
return Promise.reject({
|
|
189
|
+
reason: FailReason.OPERATION_FAILED,
|
|
190
|
+
extra: json,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=homework.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"homework.js","sourceRoot":"","sources":["../src/homework.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAG/D,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGnC,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AActC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAiBpF,MAAM,CAAC,K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AAC,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,aAAa,CAAE,CAAC;QAC/D,CAAC;QACD,OAAO;YACL,EAAE,EAAE,YAAY;YAChB,IAAI,EAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAsB,CAAC,IAAI;YACrD,WAAW;YACX,UAAU,EAAE,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,QAAQ,EAAE,YAAY,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,gBAAgB,CAAC;YAC/G,IAAI;SACL,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,CAAU,EACV,EAAU,EACV,OAAO,GAAG,EAAE,EACZ,UAAsC,EACtC,gBAAgB,GAAG,KAAK;IAExB,MAAM,IAAI,GAAG,MAAM,CACjB,MAAM,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,qBAAqB,EAAE,EAAE;QACnD,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,IAAI,CAAC,+BAA+B,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,CAAC;KACtF,CAAC,CACH,CAAC,IAAI,EAAE,CAAC;IACT,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,OAAO,CAAC,MAAM,CAAC;YACpB,MAAM,EAAE,UAAU,CAAC,gBAAgB;YACnC,KAAK,EAAE,IAAI;SACZ,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { AllContentsOptions, AllContentsResult, CalendarOptions, CalendarResult, CourseListOptions, ExcellentHomework, HomeworkListOptions, IHomeworkDetail, NotificationListOptions, RemoteFile, CommentItem, CourseInfo, Discussion, FavoriteItem, File, FileCategory, HelperConfig, Homework, HomeworkTA, IHomeworkSubmitAttachment, Language, Notification, Question, Questionnaire, SemesterInfo, UserInfo, ContentType } from './types.ts';
|
|
2
|
+
import { CourseType } from './types.ts';
|
|
3
|
+
export { addCSRFTokenToUrl } from './request.ts';
|
|
4
|
+
export * from './types.ts';
|
|
5
|
+
/** the main helper class */
|
|
6
|
+
export declare class Learn2018Helper {
|
|
7
|
+
#private;
|
|
8
|
+
/** you can provide a CookieJar and / or CredentialProvider in the configuration */
|
|
9
|
+
constructor(config?: HelperConfig);
|
|
10
|
+
/** whether preview URLs open the first page only (`HelperConfig.generatePreviewUrlForFirstPage`) */
|
|
11
|
+
get previewFirstPage(): boolean;
|
|
12
|
+
set previewFirstPage(value: boolean);
|
|
13
|
+
/** fetch CSRF token from helper (invalid after login / re-login), might be '' if not logged in */
|
|
14
|
+
getCSRFToken(): string;
|
|
15
|
+
/** manually set CSRF token (useful when you want to reuse previous token) */
|
|
16
|
+
setCSRFToken(csrfToken: string): void;
|
|
17
|
+
/**
|
|
18
|
+
* If using alternative cookie management systems,
|
|
19
|
+
* be sure to clear id.tsinghua.edu.cn cookies before calling this function
|
|
20
|
+
*/
|
|
21
|
+
getRoamingTicket(username: string, password: string, fingerPrint: string, fingerGenPrint?: string, fingerGenPrint3?: string): Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Login is necessary if you do not provide a `CredentialProvider`.
|
|
24
|
+
* Without credentials it uses the provider, and concurrent calls share one SSO login.
|
|
25
|
+
*/
|
|
26
|
+
login(username?: string, password?: string, fingerPrint?: string, fingerGenPrint?: string, fingerGenPrint3?: string): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Make sure the session is usable without a full SSO login when possible: with a CSRF token (from an earlier login
|
|
29
|
+
* or `setCSRFToken`), make one cheap request and log in again only if the session has expired; without one, log in.
|
|
30
|
+
* Use it when resuming an app instead of `login()`.
|
|
31
|
+
*/
|
|
32
|
+
ensureSession(): Promise<void>;
|
|
33
|
+
/** logout (to make everyone happy) */
|
|
34
|
+
logout(): Promise<void>;
|
|
35
|
+
/** get user's name and department */
|
|
36
|
+
getUserInfo(courseType?: CourseType): Promise<UserInfo>;
|
|
37
|
+
/**
|
|
38
|
+
* Get calendar items during the specified period (in yyyymmdd format, both inclusive).
|
|
39
|
+
* Ranges longer than 28 days are fetched in windows and merged; windows that fail even after a retry are listed in
|
|
40
|
+
* `failedRanges`. Rejects only when every window fails (usually with `FailReason.INVALID_RESPONSE`).
|
|
41
|
+
*/
|
|
42
|
+
getCalendar(startDate: string, endDate: string, options?: CalendarOptions): Promise<CalendarResult>;
|
|
43
|
+
getSemesterIdList(): Promise<string[]>;
|
|
44
|
+
getCurrentSemester(): Promise<SemesterInfo>;
|
|
45
|
+
/**
|
|
46
|
+
* Get all courses in the specified semester.
|
|
47
|
+
* `timeAndLocation` is only fetched (one request per course) with `options.timeAndLocation`.
|
|
48
|
+
*/
|
|
49
|
+
getCourseList(semesterID: string, courseType?: CourseType, lang?: Language, options?: CourseListOptions): Promise<CourseInfo[]>;
|
|
50
|
+
/** Get the time and location of one course. */
|
|
51
|
+
getCourseTimeAndLocation(courseID: string): Promise<string[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Get certain type of content of all specified courses.
|
|
54
|
+
* It wraps around the `getXXX` list functions; a course that fails is reported in `errors` instead of failing
|
|
55
|
+
* the rest. `options.details` is passed on as homework `details` or notification `attachments`.
|
|
56
|
+
*/
|
|
57
|
+
getAllContents<T extends ContentType>(courseIDs: string[], type: T, options?: AllContentsOptions<T>): Promise<AllContentsResult<T>>;
|
|
58
|
+
/**
|
|
59
|
+
* Get all notifications (课程公告) of the specified course.
|
|
60
|
+
* Attachments are only fetched (one request per notice) for the notices `options.attachments` selects;
|
|
61
|
+
* use `getNotificationAttachment` for the others.
|
|
62
|
+
*/
|
|
63
|
+
getNotificationList(courseID: string, courseType?: CourseType, options?: NotificationListOptions): Promise<Notification[]>;
|
|
64
|
+
/** Get the attachment of a notice (one request), `undefined` if it has none. */
|
|
65
|
+
getNotificationAttachment(notification: Pick<Notification, 'url' | 'attachmentName'>, courseType?: CourseType): Promise<RemoteFile | undefined>;
|
|
66
|
+
/** Get all files (课程文件) of the specified course. */
|
|
67
|
+
getFileList(courseID: string, courseType?: CourseType): Promise<File[]>;
|
|
68
|
+
/** Get file categories of the specified course. */
|
|
69
|
+
getFileCategoryList(courseID: string, courseType?: CourseType): Promise<FileCategory[]>;
|
|
70
|
+
/**
|
|
71
|
+
* Get all files of the specified category of the specified course.
|
|
72
|
+
* Note: this cannot get correct `visitCount` and `downloadCount` for student
|
|
73
|
+
*/
|
|
74
|
+
getFileListByCategory(courseID: string, categoryId: string, courseType?: CourseType): Promise<File[]>;
|
|
75
|
+
/**
|
|
76
|
+
* Get all homeworks (课程作业) of the specified course, with the excellent homework list (without details).
|
|
77
|
+
* Details (page + description, two requests per homework) are only fetched for the homework `options.details`
|
|
78
|
+
* selects; use `getHomeworkDetail` for the others.
|
|
79
|
+
*/
|
|
80
|
+
getHomeworkList(courseID: string): Promise<Homework[]>;
|
|
81
|
+
getHomeworkList(courseID: string, courseType: CourseType.STUDENT, options?: HomeworkListOptions): Promise<Homework[]>;
|
|
82
|
+
getHomeworkList(courseID: string, courseType: CourseType.TEACHER): Promise<HomeworkTA[]>;
|
|
83
|
+
/** Get the detail (page content, attachments and description) of one homework. */
|
|
84
|
+
getHomeworkDetail(item: Pick<Homework, 'url' | 'baseId'>): Promise<IHomeworkDetail>;
|
|
85
|
+
/** Get the detail (page content, attachments and description) of one excellent homework. */
|
|
86
|
+
getExcellentHomeworkDetail(item: Pick<ExcellentHomework, 'url' | 'baseId'>): Promise<IHomeworkDetail>;
|
|
87
|
+
/** Get all discussions (课程讨论) of the specified course. */
|
|
88
|
+
getDiscussionList(courseID: string, courseType?: CourseType): Promise<Discussion[]>;
|
|
89
|
+
/**
|
|
90
|
+
* Get all notifications (课程答疑) of the specified course.
|
|
91
|
+
* The student version supports only answered questions, while the teacher version supports all questions.
|
|
92
|
+
*/
|
|
93
|
+
getAnsweredQuestionList(courseID: string, courseType?: CourseType): Promise<Question[]>;
|
|
94
|
+
/**
|
|
95
|
+
* Get all questionnaires (课程问卷/QNR) of the specified course.
|
|
96
|
+
*/
|
|
97
|
+
getQuestionnaireList(courseID: string): Promise<Questionnaire[]>;
|
|
98
|
+
/**
|
|
99
|
+
* Add an item to favorites. (收藏)
|
|
100
|
+
*/
|
|
101
|
+
addToFavorites(type: ContentType, id: string): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Remove an item from favorites. (取消收藏)
|
|
104
|
+
*/
|
|
105
|
+
removeFromFavorites(id: string): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Get favorites. (我的收藏)
|
|
108
|
+
* If `courseID` or `type` is specified, only return favorites of that course or type.
|
|
109
|
+
*/
|
|
110
|
+
getFavorites(courseID?: string, type?: ContentType): Promise<FavoriteItem[]>;
|
|
111
|
+
/**
|
|
112
|
+
* Pin a favorite item. (置顶)
|
|
113
|
+
*/
|
|
114
|
+
pinFavoriteItem(id: string): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Unpin a favorite item. (取消置顶)
|
|
117
|
+
*/
|
|
118
|
+
unpinFavoriteItem(id: string): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Set a comment. (备注)
|
|
121
|
+
* Set an empty string to remove the comment.
|
|
122
|
+
*/
|
|
123
|
+
setComment(type: ContentType, id: string, content: string): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Get comments. (我的备注)
|
|
126
|
+
* If `courseID` or `type` is specified, only return favorites of that course or type.
|
|
127
|
+
*/
|
|
128
|
+
getComments(courseID?: string, type?: ContentType): Promise<CommentItem[]>;
|
|
129
|
+
sortCourses(courseIDs: string[]): Promise<void>;
|
|
130
|
+
submitHomework(id: string, content?: string, attachment?: IHomeworkSubmitAttachment, removeAttachment?: boolean): Promise<void>;
|
|
131
|
+
setLanguage(lang: Language): Promise<void>;
|
|
132
|
+
getCurrentLanguage(): Language;
|
|
133
|
+
}
|
|
134
|
+
//# sourceM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AEf;IAEY,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAEtD;IAEM,kBAAkB,IAAI,QAAQ,CAEpC;CACF"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import * as auth from './auth.js';
|
|
2
|
+
import * as calendar from './calendar.js';
|
|
3
|
+
import * as contents from './contents.js';
|
|
4
|
+
import * as courses from './courses.js';
|
|
5
|
+
import * as discussions from './discussions.js';
|
|
6
|
+
import * as favorites from './favorites.js';
|
|
7
|
+
import * as files from './files.js';
|
|
8
|
+
import * as homework from './homework.js';
|
|
9
|
+
import * as notices from './notices.js';
|
|
10
|
+
import * as questionnaires from './questionnaires.js';
|
|
11
|
+
import { Session } from './request.js';
|
|
12
|
+
import { CourseType } from './types.js';
|
|
13
|
+
import * as URLS from './urls.js';
|
|
14
|
+
import * as user from './user.js';
|
|
15
|
+
export { addCSRFTokenToUrl } from './request.js';
|
|
16
|
+
export * from './types.js';
|
|
17
|
+
/** the main helper class */
|
|
18
|
+
export class Learn2018Helper {
|
|
19
|
+
#session;
|
|
20
|
+
/** you can provide a CookieJar and / or CredentialProvider in the configuration */
|
|
21
|
+
constructor(config) {
|
|
22
|
+
this.#session = new Session(config, () => auth.login(this.#session));
|
|
23
|
+
}
|
|
24
|
+
/** whether preview URLs open the first page only (`HelperConfig.generatePreviewUrlForFirstPage`) */
|
|
25
|
+
get previewFirstPage() {
|
|
26
|
+
return this.#session.previewFirstPage;
|
|
27
|
+
}
|
|
28
|
+
set previewFirstPage(value) {
|
|
29
|
+
this.#session.previewFirstPage = value;
|
|
30
|
+
}
|
|
31
|
+
/** fetch CSRF token from helper (invalid after login / re-login), might be '' if not logged in */
|
|
32
|
+
getCSRFToken() {
|
|
33
|
+
return this.#session.csrfToken;
|
|
34
|
+
}
|
|
35
|
+
/** manually set CSRF token (useful when you want to reuse previous token) */
|
|
36
|
+
setCSRFToken(csrfToken) {
|
|
37
|
+
this.#session.csrfToken = csrfToken;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* If using alternative cookie management systems,
|
|
41
|
+
* be sure to clear id.tsinghua.edu.cn cookies before calling this function
|
|
42
|
+
*/
|
|
43
|
+
async getRoamingTicket(username, password, fingerPrint, fingerGenPrint = '', fingerGenPrint3 = '') {
|
|
44
|
+
return auth.getRoamingTicket(this.#session, username, password, fingerPrint, fingerGenPrint, fingerGenPrint3);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Login is necessary if you do not provide a `CredentialProvider`.
|
|
48
|
+
* Without credentials it uses the provider, and concurrent calls share one SSO login.
|
|
49
|
+
*/
|
|
50
|
+
async login(username, password, fingerPrint, fingerGenPrint, fingerGenPrint3) {
|
|
51
|
+
if (!username || !password || !fingerPrint)
|
|
52
|
+
return this.#session.relogin();
|
|
53
|
+
return auth.login(this.#session, username, password, fingerPrint, fingerGenPrint, fingerGenPrint3);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Make sure the session is usable without a full SSO login when possible: with a CSRF token (from an earlier login
|
|
57
|
+
* or `setCSRFToken`), make one cheap request and log in again only if the session has expired; without one, log in.
|
|
58
|
+
* Use it when resuming an app instead of `login()`.
|
|
59
|
+
*/
|
|
60
|
+
async ensureSession() {
|
|
61
|
+
return this.#session.ensureSession(URLS.LEARN_CURRENT_SEMESTER());
|
|
62
|
+
}
|
|
63
|
+
/** logout (to make everyone happy) */
|
|
64
|
+
async logout() {
|
|
65
|
+
return auth.logout(this.#session);
|
|
66
|
+
}
|
|
67
|
+
/** get user's name and department */
|
|
68
|
+
async getUserInfo(courseType = CourseType.STUDENT) {
|
|
69
|
+
return user.getUserInfo(this.#session, courseType);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get calendar items during the specified period (in yyyymmdd format, both inclusive).
|
|
73
|
+
* Ranges longer than 28 days are fetched in windows and merged; windows that fail even after a retry are listed in
|
|
74
|
+
* `failedRanges`. Rejects only when every window fails (usually with `FailReason.INVALID_RESPONSE`).
|
|
75
|
+
*/
|
|
76
|
+
async getCalendar(startDate, endDate, options) {
|
|
77
|
+
return calendar.getCalendar(this.#session, startDate, endDate, options);
|
|
78
|
+
}
|
|
79
|
+
async getSemesterIdList() {
|
|
80
|
+
return courses.getSemesterIdList(this.#session);
|
|
81
|
+
}
|
|
82
|
+
async getCurrentSemester() {
|
|
83
|
+
return courses.getCurrentSemester(this.#session);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get all courses in the specified semester.
|
|
87
|
+
* `timeAndLocation` is only fetched (one request per course) with `options.timeAndLocation`.
|
|
88
|
+
*/
|
|
89
|
+
async getCourseList(semesterID, courseType = CourseType.STUDENT, lang = this.#session.lang, options) {
|
|
90
|
+
return courses.getCourseList(this.#session, semesterID, courseType, lang, options);
|
|
91
|
+
}
|
|
92
|
+
/** Get the time and location of one course. */
|
|
93
|
+
async getCourseTimeAndLocation(courseID) {
|
|
94
|
+
return courses.getCourseTimeAndLocation(this.#session, courseID);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get certain type of content of all specified courses.
|
|
98
|
+
* It wraps around the `getXXX` list functions; a course that fails is reported in `errors` instead of failing
|
|
99
|
+
* the rest. `options.details` is passed on as homework `details` or notification `attachments`.
|
|
100
|
+
*/
|
|
101
|
+
async getAllContents(courseIDs, type, options) {
|
|
102
|
+
return contents.getAllContents(this.#session, courseIDs, type, options);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get all notifications (课程公告) of the specified course.
|
|
106
|
+
* Attachments are only fetched (one request per notice) for the notices `options.attachments` selects;
|
|
107
|
+
* use `getNotificationAttachment` for the others.
|
|
108
|
+
*/
|
|
109
|
+
async getNotificationList(courseID, courseType = CourseType.STUDENT, options) {
|
|
110
|
+
return notices.getNotificationList(this.#session, courseID, courseType, options);
|
|
111
|
+
}
|
|
112
|
+
/** Get the attachment of a notice (one request), `undefined` if it has none. */
|
|
113
|
+
async getNotificationAttachment(notification, courseType = CourseType.STUDENT) {
|
|
114
|
+
return notices.getNotificationAttachment(this.#session, notification, courseType);
|
|
115
|
+
}
|
|
116
|
+
/** Get all files (课程文件) of the specified course. */
|
|
117
|
+
async getFileList(courseID, courseType = CourseType.STUDENT) {
|
|
118
|
+
return files.getFileList(this.#session, courseID, courseType);
|
|
119
|
+
}
|
|
120
|
+
/** Get file categories of the specified course. */
|
|
121
|
+
async getFileCategoryList(courseID, courseType = CourseType.STUDENT) {
|
|
122
|
+
return files.getFileCategoryList(this.#session, courseID, courseType);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Get all files of the specified category of the specified course.
|
|
126
|
+
* Note: this cannot get correct `visitCount` and `downloadCount` for student
|
|
127
|
+
*/
|
|
128
|
+
async getFileListByCategory(courseID, categoryId, courseType = CourseType.STUDENT) {
|
|
129
|
+
return files.getFileListByCategory(this.#session, courseID, categoryId, courseType);
|
|
130
|
+
}
|
|
131
|
+
async getHomeworkList(courseID, courseType = CourseType.STUDENT, options) {
|
|
132
|
+
return courseType === CourseType.TEACHER
|
|
133
|
+
? homework.getHomeworkList(this.#session, courseID, CourseType.TEACHER)
|
|
134
|
+
: homework.getHomeworkList(this.#session, courseID, CourseType.STUDENT, options);
|
|
135
|
+
}
|
|
136
|
+
/** Get the detail (page content, attachments and description) of one homework. */
|
|
137
|
+
async getHomeworkDetail(item) {
|
|
138
|
+
return homework.getHomeworkDetail(this.#session, item);
|
|
139
|
+
}
|
|
140
|
+
/** Get the detail (page content, attachments and description) of one excellent homework. */
|
|
141
|
+
async getExcellentHomeworkDetail(item) {
|
|
142
|
+
return homework.getHomeworkDetail(this.#session, item);
|
|
143
|
+
}
|
|
144
|
+
/** Get all discussions (课程讨论) of the specified course. */
|
|
145
|
+
async getDiscussionList(courseID, courseType = CourseType.STUDENT) {
|
|
146
|
+
return discussions.getDiscussionList(this.#session, courseID, courseType);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Get all notifications (课程答疑) of the specified course.
|
|
150
|
+
* The student version supports only answered questions, while the teacher version supports all questions.
|
|
151
|
+
*/
|
|
152
|
+
async getAnsweredQuestionList(courseID, courseType = CourseType.STUDENT) {
|
|
153
|
+
return discussions.getAnsweredQuestionList(this.#session, courseID, courseType);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Get all questionnaires (课程问卷/QNR) of the specified course.
|
|
157
|
+
*/
|
|
158
|
+
async getQuestionnaireList(courseID) {
|
|
159
|
+
return questionnaires.getQuestionnaireList(this.#session, courseID);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Add an item to favorites. (收藏)
|
|
163
|
+
*/
|
|
164
|
+
async addToFavorites(type, id) {
|
|
165
|
+
return favorites.addToFavorites(this.#session, type, id);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Remove an item from favorites. (取消收藏)
|
|
169
|
+
*/
|
|
170
|
+
async removeFromFavorites(id) {
|
|
171
|
+
return favorites.removeFromFavorites(this.#session, id);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Get favorites. (我的收藏)
|
|
175
|
+
* If `courseID` or `type` is specified, only return favorites of that course or type.
|
|
176
|
+
*/
|
|
177
|
+
async getFavorites(courseID, type) {
|
|
178
|
+
return favorites.getFavorites(this.#session, courseID, type);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Pin a favorite item. (置顶)
|
|
182
|
+
*/
|
|
183
|
+
async pinFavoriteItem(id) {
|
|
184
|
+
return favorites.pinFavoriteItem(this.#session, id);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Unpin a favorite item. (取消置顶)
|
|
188
|
+
*/
|
|
189
|
+
async unpinFavoriteItem(id) {
|
|
190
|
+
return favorites.unpinFavoriteItem(this.#session, id);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Set a comment. (备注)
|
|
194
|
+
* Set an empty string to remove the comment.
|
|
195
|
+
*/
|
|
196
|
+
async setComment(type, id, content) {
|
|
197
|
+
return favorites.setComment(this.#session, type, id, content);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Get comments. (我的备注)
|
|
201
|
+
* If `courseID` or `type` is specified, only return favorites of that course or type.
|
|
202
|
+
*/
|
|
203
|
+
async getComments(courseID, type) {
|
|
204
|
+
return favorites.getComments(this.#session, courseID, type);
|
|
205
|
+
}
|
|
206
|
+
async sortCourses(courseIDs) {
|
|
207
|
+
return courses.sortCourses(this.#session, courseIDs);
|
|
208
|
+
}
|
|
209
|
+
async submitHomework(id, content = '', attachment, removeAttachment = false) {
|
|
210
|
+
return homework.submitHomework(this.#session, id, content, attachment, removeAttachment);
|
|
211
|
+
}
|
|
212
|
+
async setLanguage(lang) {
|
|
213
|
+
return user.setLanguage(this.#session, lang);
|
|
214
|
+
}
|
|
215
|
+
getCurrentLanguage() {
|
|
216
|
+
return this.#session.lang;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc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I,KAAK,CAAC,WAAW,CAAC,QAAiB,EAAE,IAAkB;QAC5D,OAAO,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,SAAmB;QAC1C,OAAO,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IACvD,CAAC;IAEM,KAAK,CAAC,cAAc,CACzB,EAAU,EACV,OAAO,GAAG,EAAE,EACZ,UAAsC,EACtC,gBAAgB,GAAG,KAAK;QAExB,OAAO,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;IAC3F,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,IAAc;QACrC,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IAEM,kBAAkB;QACvB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC5B,CAAC;CACF"}
|
package/lib/notices.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Session } from './request.ts';
|
|
2
|
+
import type { INotification, Notification, NotificationListOptions, RemoteFile } from './types.ts';
|
|
3
|
+
import { CourseType } from './types.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Get all notifications (课程公告) of the specified course: current and expired lists.
|
|
6
|
+
* Attachments only for the notices `options.attachments` selects.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getNotificationList(s: Session, courseID: string, courseType?: CourseType, options?: NotificationListOptions): Promise<Notification[]>;
|
|
9
|
+
/**
|
|
10
|
+
* Get the attachment of a notice from its detail page (1 request), or `undefined` without a request if
|
|
11
|
+
* `attachmentName` says it has none.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getNotificationAttachment(s: Session, notification: Pick<INotification, 'url' | 'attachmentName'>, courseType?: CourseType): Promise<RemoteFile | undefined>;
|
|
14
|
+
//# sourceMappingURL=notices.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notices.d.ts","sourceRoot":"","sources":["../src/notices.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACnG,OAAO,EAAe,UAAU,EAAc,MAAM,YAAY,CAAC;AAIjE;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,CAAC,EAAE,OAAO,EACV,QAAQ,EAAE,MAAM,EAChB,UAAU,GAAE,UAA+B,EAC3C,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,YAAY,EAAE,CAAC,CAWzB;AA0CD;;;GAGG;AACH,wBAAsB,yBAAyB,CAC7C,CAAC,EAAE,OAAO,EACV,YAAY,EAAE,IAAI,CAAC,aAAa,EAAE,KAAK,GAAG,gBAAgB,CAAC,EAC3D,UAAU,GAAE,UAA+B,GAC1C,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAiCjC"}
|