@robertying/thu-learn-lib 5.1.0 → 6.0.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 +81 -248
- package/lib/auth.d.ts +14 -3
- package/lib/auth.d.ts.map +1 -1
- package/lib/auth.js +56 -58
- package/lib/auth.js.map +1 -1
- package/lib/calendar.d.ts +7 -2
- package/lib/calendar.d.ts.map +1 -1
- package/lib/calendar.js +99 -14
- package/lib/calendar.js.map +1 -1
- package/lib/contents.d.ts.map +1 -1
- package/lib/contents.js +4 -9
- package/lib/contents.js.map +1 -1
- package/lib/courses.d.ts.map +1 -1
- package/lib/courses.js +11 -25
- package/lib/courses.js.map +1 -1
- package/lib/discussions.d.ts.map +1 -1
- package/lib/discussions.js +6 -17
- package/lib/discussions.js.map +1 -1
- package/lib/favorites.d.ts +1 -0
- package/lib/favorites.d.ts.map +1 -1
- package/lib/favorites.js +13 -48
- package/lib/favorites.js.map +1 -1
- package/lib/files.d.ts +3 -3
- package/lib/files.d.ts.map +1 -1
- package/lib/files.js +109 -133
- package/lib/files.js.map +1 -1
- package/lib/homework.d.ts +34 -3
- package/lib/homework.d.ts.map +1 -1
- package/lib/homework.js +135 -79
- package/lib/homework.js.map +1 -1
- package/lib/index.d.ts +39 -19
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +44 -17
- package/lib/index.js.map +1 -1
- package/lib/notices.d.ts +3 -3
- package/lib/notices.d.ts.map +1 -1
- package/lib/notices.js +4 -20
- package/lib/notices.js.map +1 -1
- package/lib/questionnaires.d.ts.map +1 -1
- package/lib/questionnaires.js +8 -14
- package/lib/questionnaires.js.map +1 -1
- package/lib/request.d.ts +27 -13
- package/lib/request.d.ts.map +1 -1
- package/lib/request.js +84 -51
- package/lib/request.js.map +1 -1
- package/lib/timetable.d.ts +26 -0
- package/lib/timetable.d.ts.map +1 -0
- package/lib/timetable.js +110 -0
- package/lib/timetable.js.map +1 -0
- package/lib/types.d.ts +108 -75
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -1
- package/lib/urls.d.ts +10 -20
- package/lib/urls.d.ts.map +1 -1
- package/lib/urls.js +11 -56
- package/lib/urls.js.map +1 -1
- package/lib/user.d.ts +7 -2
- package/lib/user.d.ts.map +1 -1
- package/lib/user.js +19 -5
- package/lib/user.js.map +1 -1
- package/lib/utils.d.ts +42 -4
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +78 -31
- package/lib/utils.js.map +1 -1
- package/package.json +8 -7
- package/src/auth.ts +62 -73
- package/src/calendar.ts +110 -16
- package/src/contents.ts +7 -9
- package/src/courses.ts +12 -26
- package/src/discussions.ts +8 -19
- package/src/favorites.ts +22 -48
- package/src/files.ts +121 -139
- package/src/homework.ts +184 -102
- package/src/index.ts +67 -48
- package/src/notices.ts +19 -26
- package/src/questionnaires.ts +18 -15
- package/src/request.ts +86 -62
- package/src/timetable.ts +121 -0
- package/src/types.ts +111 -86
- package/src/urls.ts +13 -64
- package/src/user.ts +21 -6
- package/src/utils.ts +96 -32
package/lib/calendar.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { Session } from './request.ts';
|
|
2
2
|
import type { CalendarOptions, CalendarRange, CalendarResult } from './types.ts';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* The registrar often fails for ranges longer than about a month, so longer ranges are fetched in windows of this many
|
|
5
|
+
* days.
|
|
6
|
+
*/
|
|
4
7
|
export declare const CALENDAR_WINDOW_DAYS = 28;
|
|
5
8
|
/** Split an inclusive yyyymmdd range into consecutive inclusive windows of at most `days` days. */
|
|
6
9
|
export declare function splitCalendarRange(startDate: string, endDate: string, days?: number): CalendarRange[];
|
|
@@ -12,7 +15,9 @@ export declare function splitCalendarRange(startDate: string, endDate: string, d
|
|
|
12
15
|
* show partial data and retry only those; after two windows in a row time out, the rest are listed there without a
|
|
13
16
|
* request. If every window fails, this rejects with the last error instead (usually `FailReason.INVALID_RESPONSE`).
|
|
14
17
|
* The result might be empty if the period is too far away from now. Throws a `RangeError` for a date that is not a
|
|
15
|
-
* valid yyyymmdd.
|
|
18
|
+
* valid yyyymmdd, and rejects with `FailReason.ERROR_REGISTRAR_AUTH` if signing in to the registrar fails. Off campus
|
|
19
|
+
* this goes through WebVPN and needs the id.tsinghua.edu.cn session of the last `login`; when that has expired, a
|
|
20
|
+
* helper with a `CredentialProvider` logs in again and tries once more.
|
|
16
21
|
*/
|
|
17
22
|
export declare function getCalendar(s: Session, startDate: string, endDate: string, options?: CalendarOptions): Promise<CalendarResult>;
|
|
18
23
|
//# sourceMappingURL=calendar.d.ts.map
|
package/lib/calendar.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calendar.d.ts","sourceRoot":"","sources":["../src/calendar.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"calendar.d.ts","sourceRoot":"","sources":["../src/calendar.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAA2B,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAK1G;;;GAGG;AACH,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAoBvC,mGAAmG;AACnG,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,SAAuB,GAAG,aAAa,EAAE,CASnH;AAuHD;;;;;;;;;;;GAWG;AACH,wBAAsB,WAAW,CAC/B,CAAC,EAAE,OAAO,EACV,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,cAAc,CAAC,CAkCzB"}
|
package/lib/calendar.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
// Course calendar from the registrar (
|
|
1
|
+
// Course calendar from the registrar (zhjw.cic.tsinghua.edu.cn).
|
|
2
|
+
import { discard } from './request.js';
|
|
2
3
|
import { FailReason } from './types.js';
|
|
3
4
|
import * as URLS from './urls.js';
|
|
4
|
-
import { JSONP_EXTRACTOR_NAME, extractJSONPResult } from './utils.js';
|
|
5
|
-
/**
|
|
5
|
+
import { $, JSONP_EXTRACTOR_NAME, apiError, extractJSONPResult } from './utils.js';
|
|
6
|
+
/**
|
|
7
|
+
* The registrar often fails for ranges longer than about a month, so longer ranges are fetched in windows of this many
|
|
8
|
+
* days.
|
|
9
|
+
*/
|
|
6
10
|
export const CALENDAR_WINDOW_DAYS = 28;
|
|
7
11
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
8
12
|
/** after this many windows in a row time out, `getCalendar` gives up on the rest (they go to `failedRanges`) */
|
|
@@ -28,14 +32,98 @@ export function splitCalendarRange(startDate, endDate, days = CALENDAR_WINDOW_DA
|
|
|
28
32
|
}
|
|
29
33
|
return ranges;
|
|
30
34
|
}
|
|
35
|
+
const FINGERPRINT_FIELDS = ['fingerPrint', 'fingerGenPrint', 'fingerGenPrint3'];
|
|
36
|
+
const isFingerprintField = (name) => FINGERPRINT_FIELDS.includes(name);
|
|
37
|
+
/** `extra.step` of an `ERROR_REGISTRAR_AUTH` that id.tsinghua.edu.cn turned down (rather than the registrar failing) */
|
|
38
|
+
const ID_STEP = 'id.tsinghua.edu.cn';
|
|
39
|
+
const isIdRefusal = (err) => err?.reason === FailReason.ERROR_REGISTRAR_AUTH &&
|
|
40
|
+
err.extra?.step === ID_STEP;
|
|
41
|
+
/** an id.tsinghua.edu.cn login form (`/do/off/ui/auth/login/check`, `.../checkSingle`) */
|
|
42
|
+
const isIdLoginPage = (res, page) => res.url.startsWith(URLS.ID_PREFIX) || /action="[^"]*\/do\/off\/ui\/auth\/login\//.test(page);
|
|
43
|
+
/**
|
|
44
|
+
* The body of a sign-in step, or '' when there is no text. The registrar's own pages are GBK, which React Native's
|
|
45
|
+
* fetch can't decode: its `text()` then gives `undefined` instead of a string. Only id.tsinghua.edu.cn pages (UTF-8)
|
|
46
|
+
* are looked into here, so an undecodable registrar page is as good as an empty one.
|
|
47
|
+
*/
|
|
48
|
+
const readText = async (res) => {
|
|
49
|
+
const text = await res.text();
|
|
50
|
+
return typeof text === 'string' ? text : '';
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Sign in to the registrar with a Web Learning ticket.
|
|
54
|
+
*
|
|
55
|
+
* Registrar requests use `rawFetch`, without the Web Learning login check: a 403 or login page from the registrar says
|
|
56
|
+
* nothing about the Web Learning session, and logging in there again wouldn't renew the registrar ticket. They don't
|
|
57
|
+
* carry Web Learning's CSRF token either: the registrar (and WebVPN in front of it off campus) has no use for it.
|
|
58
|
+
*
|
|
59
|
+
* Off campus the registrar is only reachable through WebVPN (webvpn.tsinghua.edu.cn): the auth URL redirects there,
|
|
60
|
+
* and WebVPN signs in through id.tsinghua.edu.cn OAuth. As the id.tsinghua.edu.cn session of the Web Learning login is
|
|
61
|
+
* still there, id.tsinghua.edu.cn answers with a form (`#logined`) that a browser submits right away with its device
|
|
62
|
+
* fingerprints. Submitting it answers with a page that links (by script) to the OAuth callback, which signs in to WebVPN
|
|
63
|
+
* and redirects back to the auth URL, so following the link ends on the registrar.
|
|
64
|
+
*/
|
|
65
|
+
async function authenticateRegistrar(s, ticket) {
|
|
66
|
+
let res = await s.rawFetch(URLS.REGISTRAR_AUTH(ticket));
|
|
67
|
+
let page = await readText(res);
|
|
68
|
+
const form = $(page)('form#logined');
|
|
69
|
+
if (form.length > 0) {
|
|
70
|
+
const fingerprints = s.fingerprints ?? (await s.provider?.());
|
|
71
|
+
const data = new FormData();
|
|
72
|
+
form.find('input[name]').each((_, input) => {
|
|
73
|
+
const name = input.attribs.name;
|
|
74
|
+
const known = isFingerprintField(name) ? fingerprints?.[name] : undefined;
|
|
75
|
+
data.append(name, known ?? input.attribs.value ?? '');
|
|
76
|
+
});
|
|
77
|
+
const action = new URL(form.attr('action') ?? '', res.url || URLS.ID_PREFIX).href;
|
|
78
|
+
const check = await s.rawFetch(action, { method: 'POST', body: data });
|
|
79
|
+
const link = check.ok ? $(await readText(check))('a').attr('href') : undefined;
|
|
80
|
+
if (!link) {
|
|
81
|
+
discard(check);
|
|
82
|
+
throw apiError(FailReason.ERROR_REGISTRAR_AUTH, { step: ID_STEP, code: check.status });
|
|
83
|
+
}
|
|
84
|
+
res = await s.rawFetch(new URL(link, check.url || action).href);
|
|
85
|
+
page = await readText(res);
|
|
86
|
+
}
|
|
87
|
+
if (isIdLoginPage(res, page)) {
|
|
88
|
+
throw apiError(FailReason.ERROR_REGISTRAR_AUTH, { step: ID_STEP, code: res.status, url: res.url.split('?')[0] });
|
|
89
|
+
}
|
|
90
|
+
if (!res.ok) {
|
|
91
|
+
throw apiError(FailReason.ERROR_REGISTRAR_AUTH, { code: res.status, url: res.url.split('?')[0] });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get a registrar ticket and sign in to the registrar with it. When id.tsinghua.edu.cn turns the sign-in down (its
|
|
96
|
+
* session from the last login has expired, e.g. in a session resumed from saved cookies) and there is a
|
|
97
|
+
* `CredentialProvider`, log in to Web Learning again (a new id.tsinghua.edu.cn session) and try once more.
|
|
98
|
+
*/
|
|
99
|
+
async function signInToRegistrar(s) {
|
|
100
|
+
const signIn = async () => {
|
|
101
|
+
const ticket = await s.fetchTextWithToken(URLS.REGISTRAR_TICKET, {
|
|
102
|
+
method: 'POST',
|
|
103
|
+
body: URLS.REGISTRAR_TICKET_FORM_DATA(),
|
|
104
|
+
});
|
|
105
|
+
await authenticateRegistrar(s, ticket.substring(1, ticket.length - 1));
|
|
106
|
+
};
|
|
107
|
+
try {
|
|
108
|
+
await signIn();
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
if (!s.provider || !isIdRefusal(err))
|
|
112
|
+
throw err;
|
|
113
|
+
await s.autoRelogin();
|
|
114
|
+
await signIn();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
31
117
|
async function fetchWindow(s, range, graduate) {
|
|
32
|
-
const response = await s.
|
|
118
|
+
const response = await s.rawFetch(URLS.REGISTRAR_CALENDAR(range.startDate, range.endDate, graduate, JSONP_EXTRACTOR_NAME));
|
|
33
119
|
if (!response.ok) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
120
|
+
discard(response);
|
|
121
|
+
throw apiError(FailReason.INVALID_RESPONSE, { code: response.status, text: response.statusText });
|
|
37
122
|
}
|
|
38
123
|
const result = extractJSONPResult(await response.text());
|
|
124
|
+
if (!Array.isArray(result)) {
|
|
125
|
+
throw apiError(FailReason.INVALID_RESPONSE, result);
|
|
126
|
+
}
|
|
39
127
|
return result.map((i) => ({
|
|
40
128
|
location: i.dd,
|
|
41
129
|
status: i.fl,
|
|
@@ -53,19 +141,16 @@ async function fetchWindow(s, range, graduate) {
|
|
|
53
141
|
* show partial data and retry only those; after two windows in a row time out, the rest are listed there without a
|
|
54
142
|
* request. If every window fails, this rejects with the last error instead (usually `FailReason.INVALID_RESPONSE`).
|
|
55
143
|
* The result might be empty if the period is too far away from now. Throws a `RangeError` for a date that is not a
|
|
56
|
-
* valid yyyymmdd.
|
|
144
|
+
* valid yyyymmdd, and rejects with `FailReason.ERROR_REGISTRAR_AUTH` if signing in to the registrar fails. Off campus
|
|
145
|
+
* this goes through WebVPN and needs the id.tsinghua.edu.cn session of the last `login`; when that has expired, a
|
|
146
|
+
* helper with a `CredentialProvider` logs in again and tries once more.
|
|
57
147
|
*/
|
|
58
148
|
export async function getCalendar(s, startDate, endDate, options = {}) {
|
|
59
149
|
const graduate = options.graduate ?? false;
|
|
60
150
|
const ranges = splitCalendarRange(startDate, endDate);
|
|
61
151
|
if (ranges.length === 0)
|
|
62
152
|
return { events: [], failedRanges: [] };
|
|
63
|
-
|
|
64
|
-
method: 'POST',
|
|
65
|
-
body: URLS.REGISTRAR_TICKET_FORM_DATA(),
|
|
66
|
-
});
|
|
67
|
-
ticket = ticket.substring(1, ticket.length - 1);
|
|
68
|
-
await s.fetch(URLS.REGISTRAR_AUTH(ticket));
|
|
153
|
+
await signInToRegistrar(s);
|
|
69
154
|
const events = [];
|
|
70
155
|
const failedRanges = [];
|
|
71
156
|
let lastError;
|
package/lib/calendar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calendar.js","sourceRoot":"","sources":["../src/calendar.ts"],"names":[],"mappings":"AAAA,iEAAiE;
|
|
1
|
+
{"version":3,"file":"calendar.js","sourceRoot":"","sources":["../src/calendar.ts"],"names":[],"mappings":"AAAA,iEAAiE;AAGjE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,CAAC,EAAE,oBAAoB,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEnF;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEvC,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEnC,gHAAgH;AAChH,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAEnC,MAAM,SAAS,GAAG,CAAC,GAAY,EAAE,EAAE,CAAE,GAA4B,EAAE,MAAM,KAAK,UAAU,CAAC,eAAe,CAAC;AAEzG,MAAM,SAAS,GAAG,CAAC,IAAY,EAAU,EAAE;IACzC,MAAM,KAAK,GAAG,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnD,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAA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AAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IAED,IAAI,YAAY,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM;QAAE,MAAM,SAAS,CAAC;IAC3D,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;AAClC,CAAC"}
|
package/lib/contents.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contents.d.ts","sourceRoot":"","sources":["../src/contents.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAiC,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"contents.d.ts","sourceRoot":"","sources":["../src/contents.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAiC,MAAM,YAAY,CAAC;AAEvG,OAAO,EAAE,WAAW,EAA0B,MAAM,YAAY,CAAC;AAOjE;;;GAGG;AACH,wBAAsB,cAAc,CAAC,CAAC,SAAS,WAAW,EACxD,CAAC,EAAE,OAAO,EACV,SAAS,EAAE,MAAM,EAAE,EACnB,IAAI,EAAE,CAAC,EACP,OAAO,GAAE,kBAAkB,CAAC,CAAC,CAAM,GAClC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAgD/B"}
|
package/lib/contents.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// One kind of content for many courses at once.
|
|
2
|
+
import { apiError } from './utils.js';
|
|
2
3
|
import { ContentType, CourseType, FailReason } from './types.js';
|
|
3
4
|
import { getAnsweredQuestionList, getDiscussionList } from './discussions.js';
|
|
4
5
|
import { getFileList } from './files.js';
|
|
@@ -11,7 +12,7 @@ import { getQuestionnaireList } from './questionnaires.js';
|
|
|
11
12
|
*/
|
|
12
13
|
export async function getAllContents(s, courseIDs, type, options = {}) {
|
|
13
14
|
const courseType = options.courseType ?? CourseType.STUDENT;
|
|
14
|
-
const fetchContentForCourse = (id) => {
|
|
15
|
+
const fetchContentForCourse = async (id) => {
|
|
15
16
|
switch (type) {
|
|
16
17
|
case ContentType.NOTIFICATION:
|
|
17
18
|
return getNotificationList(s, id, courseType, {
|
|
@@ -22,10 +23,7 @@ export async function getAllContents(s, courseIDs, type, options = {}) {
|
|
|
22
23
|
case ContentType.HOMEWORK:
|
|
23
24
|
if (courseType === CourseType.TEACHER) {
|
|
24
25
|
// the teacher list has another shape (`HomeworkTA`); use `getHomeworkList(id, CourseType.TEACHER)`
|
|
25
|
-
|
|
26
|
-
reason: FailReason.NOT_IMPLEMENTED,
|
|
27
|
-
extra: 'homework of a teacher course; use getHomeworkList(courseID, CourseType.TEACHER)',
|
|
28
|
-
});
|
|
26
|
+
throw apiError(FailReason.NOT_IMPLEMENTED, 'homework of a teacher course; use getHomeworkList(courseID, CourseType.TEACHER)');
|
|
29
27
|
}
|
|
30
28
|
return getHomeworkList(s, id, CourseType.STUDENT, {
|
|
31
29
|
details: options.details,
|
|
@@ -39,10 +37,7 @@ export async function getAllContents(s, courseIDs, type, options = {}) {
|
|
|
39
37
|
details: options.details,
|
|
40
38
|
});
|
|
41
39
|
default:
|
|
42
|
-
|
|
43
|
-
reason: FailReason.NOT_IMPLEMENTED,
|
|
44
|
-
extra: 'Unknown content type',
|
|
45
|
-
});
|
|
40
|
+
throw apiError(FailReason.NOT_IMPLEMENTED, 'Unknown content type');
|
|
46
41
|
}
|
|
47
42
|
};
|
|
48
43
|
const contents = {};
|
package/lib/contents.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contents.js","sourceRoot":"","sources":["../src/contents.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAIhD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CA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AAE,CAAC,GAAG,MAAM,qBAAqB,CAAC,EAAE,CAAC,CAAC;QACjD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC9B,CAAC"}
|
package/lib/courses.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"courses.d.ts","sourceRoot":"","sources":["../src/courses.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"courses.d.ts","sourceRoot":"","sources":["../src/courses.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAc,MAAM,YAAY,CAAC;AAIpD,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAQrE;AAED,wBAAsB,kBAAkB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,CAc1E;AAED,uGAAuG;AACvG,wBAAsB,aAAa,CACjC,CAAC,EAAE,OAAO,EACV,UAAU,EAAE,MAAM,EAClB,UAAU,GAAE,UAA+B,EAC3C,IAAI,gCAAS,EACb,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,UAAU,EAAE,CAAC,CAgCvB;AAED,0DAA0D;AAC1D,wBAAsB,wBAAwB,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAO9F;AAED,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAShF"}
|
package/lib/courses.js
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
// Semesters and courses.
|
|
2
2
|
import { CourseType, FailReason } from './types.js';
|
|
3
3
|
import * as URLS from './urls.js';
|
|
4
|
-
import { decodeHTML, parseSemesterType } from './utils.js';
|
|
4
|
+
import { apiError, decodeHTML, expectSuccess, parseSemesterType } from './utils.js';
|
|
5
5
|
export async function getSemesterIdList(s) {
|
|
6
|
-
const json = await s.fetchJsonWithToken(URLS.LEARN_SEMESTER_LIST
|
|
6
|
+
const json = await s.fetchJsonWithToken(URLS.LEARN_SEMESTER_LIST);
|
|
7
7
|
if (!Array.isArray(json)) {
|
|
8
|
-
|
|
9
|
-
reason: FailReason.INVALID_RESPONSE,
|
|
10
|
-
extra: json,
|
|
11
|
-
});
|
|
8
|
+
throw apiError(FailReason.INVALID_RESPONSE, json);
|
|
12
9
|
}
|
|
13
10
|
const semesters = json;
|
|
14
|
-
//
|
|
11
|
+
// the list can contain null entries
|
|
15
12
|
return semesters.filter((semester) => semester != null);
|
|
16
13
|
}
|
|
17
14
|
export async function getCurrentSemester(s) {
|
|
18
|
-
const json = await s.fetchJsonWithToken(URLS.LEARN_CURRENT_SEMESTER
|
|
15
|
+
const json = await s.fetchJsonWithToken(URLS.LEARN_CURRENT_SEMESTER);
|
|
19
16
|
if (json.message !== 'success') {
|
|
20
|
-
|
|
21
|
-
reason: FailReason.INVALID_RESPONSE,
|
|
22
|
-
extra: json,
|
|
23
|
-
});
|
|
17
|
+
throw apiError(FailReason.INVALID_RESPONSE, json);
|
|
24
18
|
}
|
|
25
19
|
const result = json.result;
|
|
26
20
|
return {
|
|
@@ -36,12 +30,9 @@ export async function getCurrentSemester(s) {
|
|
|
36
30
|
export async function getCourseList(s, semesterID, courseType = CourseType.STUDENT, lang = s.lang, options = {}) {
|
|
37
31
|
const json = await s.fetchJsonWithToken(URLS.LEARN_COURSE_LIST(semesterID, courseType, lang));
|
|
38
32
|
if (json.message !== 'success' || !Array.isArray(json.resultList)) {
|
|
39
|
-
|
|
40
|
-
reason: FailReason.INVALID_RESPONSE,
|
|
41
|
-
extra: json,
|
|
42
|
-
});
|
|
33
|
+
throw apiError(FailReason.INVALID_RESPONSE, json);
|
|
43
34
|
}
|
|
44
|
-
const result =
|
|
35
|
+
const result = json.resultList;
|
|
45
36
|
return Promise.all(result.map(async (c) => {
|
|
46
37
|
let timeAndLocation;
|
|
47
38
|
if (options.timeAndLocation) {
|
|
@@ -49,7 +40,7 @@ export async function getCourseList(s, semesterID, courseType = CourseType.STUDE
|
|
|
49
40
|
timeAndLocation = await getCourseTimeAndLocation(s, c.wlkcid);
|
|
50
41
|
}
|
|
51
42
|
catch {
|
|
52
|
-
|
|
43
|
+
// left out, so a failure doesn't look like a course without a schedule; see `getCourseTimeAndLocation`
|
|
53
44
|
}
|
|
54
45
|
}
|
|
55
46
|
return {
|
|
@@ -72,7 +63,7 @@ export async function getCourseTimeAndLocation(s, courseID) {
|
|
|
72
63
|
// see https://github.com/Harry-Chen/Learn-Helper/issues/145
|
|
73
64
|
const json = await s.fetchJsonWithToken(URLS.LEARN_COURSE_TIME_LOCATION(courseID));
|
|
74
65
|
if (!Array.isArray(json)) {
|
|
75
|
-
throw
|
|
66
|
+
throw apiError(FailReason.INVALID_RESPONSE, json);
|
|
76
67
|
}
|
|
77
68
|
return json;
|
|
78
69
|
}
|
|
@@ -84,11 +75,6 @@ export async function sortCourses(s, courseIDs) {
|
|
|
84
75
|
'Content-Type': 'application/json',
|
|
85
76
|
},
|
|
86
77
|
});
|
|
87
|
-
|
|
88
|
-
return Promise.reject({
|
|
89
|
-
reason: FailReason.OPERATION_FAILED,
|
|
90
|
-
extra: json,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
78
|
+
expectSuccess(json, FailReason.OPERATION_FAILED);
|
|
93
79
|
}
|
|
94
80
|
//# sourceMappingURL=courses.js.map
|
package/lib/courses.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"courses.js","sourceRoot":"","sources":["../src/courses.ts"],"names":[],"mappings":"AAAA,yBAAyB;AAIzB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"courses.js","sourceRoot":"","sources":["../src/courses.ts"],"names":[],"mappings":"AAAA,yBAAyB;AAIzB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpF,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,CAAU;IAChD,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IAClE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,MAAM,QAAQ,CAAC,UAAU,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;IACpD,CAAC;IACD,MAAM,SAAS,GAAG,IAAgB,CAAC;IACnC,oCAAoC;IACpC,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,IAAI,IAAI,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,CAAU;IACjD,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IACrE,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;Q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AAE,SAAmB;IAC/D,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,kBAAkB,EAAE;QAC/D,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QACnF,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;KACF,CAAC,CAAC;IACH,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAC;AACnD,CAAC"}
|
package/lib/discussions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discussions.d.ts","sourceRoot":"","sources":["../src/discussions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"discussions.d.ts","sourceRoot":"","sources":["../src/discussions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAkB,QAAQ,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,EAAE,UAAU,EAAc,MAAM,YAAY,CAAC;AAIpD,0DAA0D;AAC1D,wBAAsB,iBAAiB,CACrC,CAAC,EAAE,OAAO,EACV,QAAQ,EAAE,MAAM,EAChB,UAAU,GAAE,UAA+B,GAC1C,OAAO,CAAC,UAAU,EAAE,CAAC,CAcvB;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,CAC3C,CAAC,EAAE,OAAO,EACV,QAAQ,EAAE,MAAM,EAChB,UAAU,GAAE,UAA+B,GAC1C,OAAO,CAAC,QAAQ,EAAE,CAAC,CAcrB"}
|
package/lib/discussions.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
// Discussions (课程讨论) and answered questions (课程答疑).
|
|
2
2
|
import { Base64 } from 'js-base64';
|
|
3
|
-
import { YES } from './request.js';
|
|
4
3
|
import { CourseType, FailReason } from './types.js';
|
|
5
4
|
import * as URLS from './urls.js';
|
|
6
|
-
import { decodeHTML } from './utils.js';
|
|
5
|
+
import { YES, decodeHTML, expectSuccess, toRequiredServerTime } from './utils.js';
|
|
7
6
|
/** Get all discussions (课程讨论) of the specified course. */
|
|
8
7
|
export async function getDiscussionList(s, courseID, courseType = CourseType.STUDENT) {
|
|
9
8
|
const json = await s.fetchJsonWithToken(URLS.LEARN_DISCUSSION_LIST(courseID, courseType));
|
|
10
|
-
|
|
11
|
-
return Promise.reject({
|
|
12
|
-
reason: FailReason.INVALID_RESPONSE,
|
|
13
|
-
extra: json,
|
|
14
|
-
});
|
|
15
|
-
}
|
|
9
|
+
expectSuccess(json, FailReason.INVALID_RESPONSE);
|
|
16
10
|
const result = (json.object?.resultsList ?? []);
|
|
17
11
|
return result.map((d) => ({
|
|
18
12
|
...parseDiscussionBase(d),
|
|
@@ -26,16 +20,11 @@ export async function getDiscussionList(s, courseID, courseType = CourseType.STU
|
|
|
26
20
|
*/
|
|
27
21
|
export async function getAnsweredQuestionList(s, courseID, courseType = CourseType.STUDENT) {
|
|
28
22
|
const json = await s.fetchJsonWithToken(URLS.LEARN_QUESTION_LIST_ANSWERED(courseID, courseType));
|
|
29
|
-
|
|
30
|
-
return Promise.reject({
|
|
31
|
-
reason: FailReason.INVALID_RESPONSE,
|
|
32
|
-
extra: json,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
23
|
+
expectSuccess(json, FailReason.INVALID_RESPONSE);
|
|
35
24
|
const result = (json.object?.resultsList ?? []);
|
|
36
25
|
return result.map((q) => ({
|
|
37
26
|
...parseDiscussionBase(q),
|
|
38
|
-
question: Base64.decode(q.wtnr),
|
|
27
|
+
question: Base64.decode(q.wtnr ?? ''),
|
|
39
28
|
url: URLS.LEARN_QUESTION_DETAIL(q.wlkcid, q.id, courseType),
|
|
40
29
|
}));
|
|
41
30
|
}
|
|
@@ -44,8 +33,8 @@ function parseDiscussionBase(d) {
|
|
|
44
33
|
id: d.id,
|
|
45
34
|
title: decodeHTML(d.bt),
|
|
46
35
|
publisherName: d.fbrxm,
|
|
47
|
-
publishTime: d.fbsj,
|
|
48
|
-
lastReplyTime: d.zhhfsj,
|
|
36
|
+
publishTime: toRequiredServerTime(d.fbsj),
|
|
37
|
+
lastReplyTime: toRequiredServerTime(d.zhhfsj),
|
|
49
38
|
lastReplierName: d.zhhfrxm,
|
|
50
39
|
visitCount: d.djs ?? 0, // teacher cannot fetch this
|
|
51
40
|
replyCount: d.hfcs,
|
package/lib/discussions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discussions.js","sourceRoot":"","sources":["../src/discussions.ts"],"names":[],"mappings":"AAAA,oDAAoD;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"discussions.js","sourceRoot":"","sources":["../src/discussions.ts"],"names":[],"mappings":"AAAA,oDAAoD;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAInC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElF,0DAA0D;AAC1D,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,CAAU,EACV,QAAgB,EAChB,UAAU,GAAe,UAAU,CAAC,OAAO;IAE3C,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,qBAAqB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;IAC1F,aAAa,CAAC,IAAI,EAAE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,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;QACvB,aAAa,EAAE,CAAC,CAAC,KAAK;QACtB,WAAW,EAAE,oBAAoB,CAAC,CAAC,CAAC,IAAI,CAAC;QACzC,aAAa,EAAE,oBAAoB,CAAC,CAAC,CAAC,MAAM,CAAC;QAC7C,eAAe,EAAE,CAAC,CAAC,OAAO;QAC1B,UAAU,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,4BAA4B;QACpD,UAAU,EAAE,CAAC,CAAC,IAAI;QAClB,UAAU,EAAE,CAAC,CAAC,IAAI,KAAK,GAAG;QAC1B,OAAO,EAAE,CAAC,CAAC,IAAI,IAAI,SAAS;KAC7B,CAAC;AACJ,CAAC"}
|
package/lib/favorites.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { CommentItem, FavoriteItem } from './types.ts';
|
|
|
3
3
|
import { ContentType } from './types.ts';
|
|
4
4
|
/**
|
|
5
5
|
* Add an item to favorites. (收藏)
|
|
6
|
+
* Success is `result: 'success'`; the message is in the website's language ("收藏成功", "Added successfully.").
|
|
6
7
|
*/
|
|
7
8
|
export declare function addToFavorites(s: Session, type: ContentType, id: string): Promise<void>;
|
|
8
9
|
/**
|
package/lib/favorites.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"favorites.d.ts","sourceRoot":"","sources":["../src/favorites.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"favorites.d.ts","sourceRoot":"","sources":["../src/favorites.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAc,MAAM,YAAY,CAAC;AAWrD;;;GAGG;AACH,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG7F;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG/E;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CA8B7G;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAM3E;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAM7E;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAM1G;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAwB3G"}
|
package/lib/favorites.js
CHANGED
|
@@ -1,31 +1,21 @@
|
|
|
1
1
|
// Favorites (收藏) and comments (备注).
|
|
2
|
-
import { YES } from './request.js';
|
|
3
2
|
import { ContentType, FailReason } from './types.js';
|
|
4
3
|
import * as URLS from './urls.js';
|
|
5
|
-
import { CONTENT_TYPE_MAP_REVERSE, decodeHTML } from './utils.js';
|
|
4
|
+
import { CONTENT_TYPE_MAP_REVERSE, YES, decodeHTML, expectSuccess, toRequiredServerTime, toServerTime, } from './utils.js';
|
|
6
5
|
/**
|
|
7
6
|
* Add an item to favorites. (收藏)
|
|
7
|
+
* Success is `result: 'success'`; the message is in the website's language ("收藏成功", "Added successfully.").
|
|
8
8
|
*/
|
|
9
9
|
export async function addToFavorites(s, type, id) {
|
|
10
10
|
const json = await s.fetchJsonWithToken(URLS.LEARN_FAVORITE_ADD(type, id));
|
|
11
|
-
|
|
12
|
-
return Promise.reject({
|
|
13
|
-
reason: FailReason.OPERATION_FAILED,
|
|
14
|
-
extra: json,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
11
|
+
expectSuccess(json, FailReason.OPERATION_FAILED);
|
|
17
12
|
}
|
|
18
13
|
/**
|
|
19
14
|
* Remove an item from favorites. (取消收藏)
|
|
20
15
|
*/
|
|
21
16
|
export async function removeFromFavorites(s, id) {
|
|
22
17
|
const json = await s.fetchJsonWithToken(URLS.LEARN_FAVORITE_REMOVE(id));
|
|
23
|
-
|
|
24
|
-
return Promise.reject({
|
|
25
|
-
reason: FailReason.OPERATION_FAILED,
|
|
26
|
-
extra: json,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
18
|
+
expectSuccess(json, FailReason.OPERATION_FAILED);
|
|
29
19
|
}
|
|
30
20
|
/**
|
|
31
21
|
* Get favorites. (我的收藏)
|
|
@@ -36,12 +26,7 @@ export async function getFavorites(s, courseID, type) {
|
|
|
36
26
|
method: 'POST',
|
|
37
27
|
body: URLS.LEARN_PAGE_LIST_FORM_DATA(courseID),
|
|
38
28
|
});
|
|
39
|
-
|
|
40
|
-
return Promise.reject({
|
|
41
|
-
reason: FailReason.INVALID_RESPONSE,
|
|
42
|
-
extra: json,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
29
|
+
expectSuccess(json, FailReason.INVALID_RESPONSE);
|
|
45
30
|
const result = (json.object?.aaData ?? []);
|
|
46
31
|
return result
|
|
47
32
|
.map((e) => {
|
|
@@ -52,15 +37,15 @@ export async function getFavorites(s, courseID, type) {
|
|
|
52
37
|
id: e.ywid,
|
|
53
38
|
type: itemType,
|
|
54
39
|
title: decodeHTML(e.ywbt),
|
|
55
|
-
time: itemType === ContentType.DISCUSSION || itemType === ContentType.QUESTION ? e.tlsj : e.ywsj,
|
|
40
|
+
time: toRequiredServerTime(itemType === ContentType.DISCUSSION || itemType === ContentType.QUESTION ? e.tlsj : e.ywsj),
|
|
56
41
|
state: e.ywzt,
|
|
57
42
|
extra: e.ywbz ?? undefined,
|
|
58
43
|
semesterId: e.xnxq,
|
|
59
44
|
courseId: e.wlkcid,
|
|
60
45
|
pinned: e.sfzd === YES,
|
|
61
|
-
pinnedTime: e.zdsj
|
|
46
|
+
pinnedTime: toServerTime(e.zdsj),
|
|
62
47
|
comment: e.bznr ?? undefined,
|
|
63
|
-
addedTime: e.scsj,
|
|
48
|
+
addedTime: toRequiredServerTime(e.scsj),
|
|
64
49
|
itemId: e.id,
|
|
65
50
|
};
|
|
66
51
|
})
|
|
@@ -74,12 +59,7 @@ export async function pinFavoriteItem(s, id) {
|
|
|
74
59
|
method: 'POST',
|
|
75
60
|
body: URLS.LEARN_FAVORITE_PIN_UNPIN_FORM_DATA(id),
|
|
76
61
|
});
|
|
77
|
-
|
|
78
|
-
return Promise.reject({
|
|
79
|
-
reason: FailReason.OPERATION_FAILED,
|
|
80
|
-
extra: json,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
62
|
+
expectSuccess(json, FailReason.OPERATION_FAILED);
|
|
83
63
|
}
|
|
84
64
|
/**
|
|
85
65
|
* Unpin a favorite item. (取消置顶)
|
|
@@ -89,12 +69,7 @@ export async function unpinFavoriteItem(s, id) {
|
|
|
89
69
|
method: 'POST',
|
|
90
70
|
body: URLS.LEARN_FAVORITE_PIN_UNPIN_FORM_DATA(id),
|
|
91
71
|
});
|
|
92
|
-
|
|
93
|
-
return Promise.reject({
|
|
94
|
-
reason: FailReason.OPERATION_FAILED,
|
|
95
|
-
extra: json,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
72
|
+
expectSuccess(json, FailReason.OPERATION_FAILED);
|
|
98
73
|
}
|
|
99
74
|
/**
|
|
100
75
|
* Set a comment. (备注)
|
|
@@ -105,12 +80,7 @@ export async function setComment(s, type, id, content) {
|
|
|
105
80
|
method: 'POST',
|
|
106
81
|
body: URLS.LEARN_COMMENT_SET_FORM_DATA(type, id, content),
|
|
107
82
|
});
|
|
108
|
-
|
|
109
|
-
return Promise.reject({
|
|
110
|
-
reason: FailReason.OPERATION_FAILED,
|
|
111
|
-
extra: json,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
83
|
+
expectSuccess(json, FailReason.OPERATION_FAILED);
|
|
114
84
|
}
|
|
115
85
|
/**
|
|
116
86
|
* Get comments. (我的备注)
|
|
@@ -121,12 +91,7 @@ export async function getComments(s, courseID, type) {
|
|
|
121
91
|
method: 'POST',
|
|
122
92
|
body: URLS.LEARN_PAGE_LIST_FORM_DATA(courseID),
|
|
123
93
|
});
|
|
124
|
-
|
|
125
|
-
return Promise.reject({
|
|
126
|
-
reason: FailReason.INVALID_RESPONSE,
|
|
127
|
-
extra: json,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
94
|
+
expectSuccess(json, FailReason.INVALID_RESPONSE);
|
|
130
95
|
const result = (json.object?.aaData ?? []);
|
|
131
96
|
return result
|
|
132
97
|
.map((e) => {
|
|
@@ -141,7 +106,7 @@ export async function getComments(s, courseID, type) {
|
|
|
141
106
|
title: decodeHTML(e.ywbt),
|
|
142
107
|
semesterId: e.xnxq,
|
|
143
108
|
courseId: e.wlkcid,
|
|
144
|
-
commentTime: e.cjsj,
|
|
109
|
+
commentTime: toRequiredServerTime(e.cjsj),
|
|
145
110
|
itemId: e.id,
|
|
146
111
|
};
|
|
147
112
|
})
|
package/lib/favorites.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"favorites.js","sourceRoot":"","sources":["../src/favorites.ts"],"names":[],"mappings":"AAAA,oCAAoC;
|
|
1
|
+
{"version":3,"file":"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