@robertying/thu-learn-lib 5.0.0 → 6.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/README.md +94 -227
- package/lib/auth.d.ts +15 -4
- package/lib/auth.d.ts.map +1 -1
- package/lib/auth.js +65 -55
- package/lib/auth.js.map +1 -1
- package/lib/calendar.d.ts +12 -5
- package/lib/calendar.d.ts.map +1 -1
- package/lib/calendar.js +118 -20
- package/lib/calendar.js.map +1 -1
- package/lib/contents.d.ts.map +1 -1
- package/lib/contents.js +10 -6
- package/lib/contents.js.map +1 -1
- package/lib/courses.d.ts.map +1 -1
- package/lib/courses.js +15 -29
- package/lib/courses.js.map +1 -1
- package/lib/discussions.d.ts.map +1 -1
- package/lib/discussions.js +8 -19
- 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 +25 -60
- package/lib/favorites.js.map +1 -1
- package/lib/files.d.ts +4 -4
- package/lib/files.d.ts.map +1 -1
- package/lib/files.js +112 -134
- package/lib/files.js.map +1 -1
- package/lib/homework.d.ts +35 -5
- package/lib/homework.d.ts.map +1 -1
- package/lib/homework.js +150 -92
- package/lib/homework.js.map +1 -1
- package/lib/index.d.ts +45 -20
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +52 -17
- package/lib/index.js.map +1 -1
- package/lib/notices.d.ts +4 -4
- package/lib/notices.d.ts.map +1 -1
- package/lib/notices.js +13 -33
- package/lib/notices.js.map +1 -1
- package/lib/questionnaires.d.ts +6 -3
- package/lib/questionnaires.d.ts.map +1 -1
- package/lib/questionnaires.js +26 -24
- package/lib/questionnaires.js.map +1 -1
- package/lib/request.d.ts +64 -20
- package/lib/request.d.ts.map +1 -1
- package/lib/request.js +174 -64
- 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 +117 -76
- 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 +20 -6
- 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 +80 -29
- package/lib/utils.js.map +1 -1
- package/package.json +9 -8
- package/src/auth.ts +72 -70
- package/src/calendar.ts +136 -24
- package/src/contents.ts +13 -6
- package/src/courses.ts +21 -37
- package/src/discussions.ts +10 -21
- package/src/favorites.ts +44 -80
- package/src/files.ts +124 -142
- package/src/homework.ts +207 -135
- package/src/index.ts +79 -48
- package/src/notices.ts +29 -42
- package/src/questionnaires.ts +62 -45
- package/src/request.ts +192 -69
- package/src/timetable.ts +121 -0
- package/src/types.ts +123 -87
- package/src/urls.ts +13 -64
- package/src/user.ts +22 -7
- package/src/utils.ts +97 -29
package/lib/favorites.js
CHANGED
|
@@ -1,47 +1,32 @@
|
|
|
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
|
-
const json = await
|
|
11
|
-
|
|
12
|
-
return Promise.reject({
|
|
13
|
-
reason: FailReason.OPERATION_FAILED,
|
|
14
|
-
extra: json,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
10
|
+
const json = await s.fetchJsonWithToken(URLS.LEARN_FAVORITE_ADD(type, id));
|
|
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
|
-
const json = await
|
|
23
|
-
|
|
24
|
-
return Promise.reject({
|
|
25
|
-
reason: FailReason.OPERATION_FAILED,
|
|
26
|
-
extra: json,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
17
|
+
const json = await s.fetchJsonWithToken(URLS.LEARN_FAVORITE_REMOVE(id));
|
|
18
|
+
expectSuccess(json, FailReason.OPERATION_FAILED);
|
|
29
19
|
}
|
|
30
20
|
/**
|
|
31
21
|
* Get favorites. (我的收藏)
|
|
32
22
|
* If `courseID` or `type` is specified, only return favorites of that course or type.
|
|
33
23
|
*/
|
|
34
24
|
export async function getFavorites(s, courseID, type) {
|
|
35
|
-
const json = await
|
|
25
|
+
const json = await s.fetchJsonWithToken(URLS.LEARN_FAVORITE_LIST(type), {
|
|
36
26
|
method: 'POST',
|
|
37
27
|
body: URLS.LEARN_PAGE_LIST_FORM_DATA(courseID),
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
return Promise.reject({
|
|
41
|
-
reason: FailReason.INVALID_RESPONSE,
|
|
42
|
-
extra: json,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
28
|
+
});
|
|
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
|
})
|
|
@@ -70,63 +55,43 @@ export async function getFavorites(s, courseID, type) {
|
|
|
70
55
|
* Pin a favorite item. (置顶)
|
|
71
56
|
*/
|
|
72
57
|
export async function pinFavoriteItem(s, id) {
|
|
73
|
-
const json = await
|
|
58
|
+
const json = await s.fetchJsonWithToken(URLS.LEARN_FAVORITE_PIN, {
|
|
74
59
|
method: 'POST',
|
|
75
60
|
body: URLS.LEARN_FAVORITE_PIN_UNPIN_FORM_DATA(id),
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
return Promise.reject({
|
|
79
|
-
reason: FailReason.OPERATION_FAILED,
|
|
80
|
-
extra: json,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
61
|
+
});
|
|
62
|
+
expectSuccess(json, FailReason.OPERATION_FAILED);
|
|
83
63
|
}
|
|
84
64
|
/**
|
|
85
65
|
* Unpin a favorite item. (取消置顶)
|
|
86
66
|
*/
|
|
87
67
|
export async function unpinFavoriteItem(s, id) {
|
|
88
|
-
const json = await
|
|
68
|
+
const json = await s.fetchJsonWithToken(URLS.LEARN_FAVORITE_UNPIN, {
|
|
89
69
|
method: 'POST',
|
|
90
70
|
body: URLS.LEARN_FAVORITE_PIN_UNPIN_FORM_DATA(id),
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
return Promise.reject({
|
|
94
|
-
reason: FailReason.OPERATION_FAILED,
|
|
95
|
-
extra: json,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
71
|
+
});
|
|
72
|
+
expectSuccess(json, FailReason.OPERATION_FAILED);
|
|
98
73
|
}
|
|
99
74
|
/**
|
|
100
75
|
* Set a comment. (备注)
|
|
101
76
|
* Set an empty string to remove the comment.
|
|
102
77
|
*/
|
|
103
78
|
export async function setComment(s, type, id, content) {
|
|
104
|
-
const json = await
|
|
79
|
+
const json = await s.fetchJsonWithToken(URLS.LEARN_COMMENT_SET, {
|
|
105
80
|
method: 'POST',
|
|
106
81
|
body: URLS.LEARN_COMMENT_SET_FORM_DATA(type, id, content),
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
return Promise.reject({
|
|
110
|
-
reason: FailReason.OPERATION_FAILED,
|
|
111
|
-
extra: json,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
82
|
+
});
|
|
83
|
+
expectSuccess(json, FailReason.OPERATION_FAILED);
|
|
114
84
|
}
|
|
115
85
|
/**
|
|
116
86
|
* Get comments. (我的备注)
|
|
117
87
|
* If `courseID` or `type` is specified, only return favorites of that course or type.
|
|
118
88
|
*/
|
|
119
89
|
export async function getComments(s, courseID, type) {
|
|
120
|
-
const json = await
|
|
90
|
+
const json = await s.fetchJsonWithToken(URLS.LEARN_COMMENT_LIST(type), {
|
|
121
91
|
method: 'POST',
|
|
122
92
|
body: URLS.LEARN_PAGE_LIST_FORM_DATA(courseID),
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
return Promise.reject({
|
|
126
|
-
reason: FailReason.INVALID_RESPONSE,
|
|
127
|
-
extra: json,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
93
|
+
});
|
|
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":"favorites.js","sourceRoot":"","sources":["../src/favorites.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAIpC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EACL,wBAAwB,EACxB,GAAG,EACH,UAAU,EACV,aAAa,EACb,oBAAoB,EACpB,YAAY,GACb,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,CAAU,EAAE,IAAiB,EAAE,EAAU;IAC5E,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3E,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAC;AACnD,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,CAAU,EAAE,EAAU;IAC9D,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,qBAAqB,CAAC,EAAE,CAAC,CAAC,CAAC;IACxE,aAAa,CAAC,IAAI,EAAE,UAAU,CAA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|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { Session } from './request.ts';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CourseFile, FileCategory } from './types.ts';
|
|
3
3
|
import { CourseType } from './types.ts';
|
|
4
|
-
/** Get all files (课程文件) of the specified course. */
|
|
5
|
-
export declare function getFileList(s: Session, courseID: string, courseType?: CourseType): Promise<
|
|
4
|
+
/** Get all files (课程文件) of the specified course; `category` is left out if the categories can't be fetched. */
|
|
5
|
+
export declare function getFileList(s: Session, courseID: string, courseType?: CourseType): Promise<CourseFile[]>;
|
|
6
6
|
/** Get file categories of the specified course. */
|
|
7
7
|
export declare function getFileCategoryList(s: Session, courseID: string, courseType?: CourseType): Promise<FileCategory[]>;
|
|
8
8
|
/**
|
|
9
9
|
* Get all files of the specified category of the specified course.
|
|
10
10
|
* Note: this cannot get correct `visitCount` and `downloadCount` for student
|
|
11
11
|
*/
|
|
12
|
-
export declare function getFileListByCategory(s: Session, courseID: string, categoryId: string, courseType?: CourseType): Promise<
|
|
12
|
+
export declare function getFileListByCategory(s: Session, courseID: string, categoryId: string, courseType?: CourseType): Promise<CourseFile[]>;
|
|
13
13
|
//# sourceMappingURL=files.d.ts.map
|
package/lib/files.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAe,UAAU,EAAc,MAAM,YAAY,CAAC;AAIjE,+GAA+G;AAC/G,wBAAsB,WAAW,CAC/B,CAAC,EAAE,OAAO,EACV,QAAQ,EAAE,MAAM,EAChB,UAAU,GAAE,UAA+B,GAC1C,OAAO,CAAC,UAAU,EAAE,CAAC,CAmBvB;AAyCD,mDAAmD;AACnD,wBAAsB,mBAAmB,CACvC,CAAC,EAAE,OAAO,EACV,QAAQ,EAAE,MAAM,EAChB,UAAU,GAAE,UAA+B,GAC1C,OAAO,CAAC,YAAY,EAAE,CAAC,CAczB;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,CACzC,CAAC,EAAE,OAAO,EACV,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,UAAU,GAAE,UAA+B,GAC1C,OAAO,CAAC,UAAU,EAAE,CAAC,CAIvB"}
|
package/lib/files.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
// Course files (课程文件) and file categories.
|
|
2
2
|
import { ContentType, CourseType, FailReason } from './types.js';
|
|
3
3
|
import * as URLS from './urls.js';
|
|
4
|
-
import { decodeHTML, formatFileSize } from './utils.js';
|
|
5
|
-
/** Get all files (课程文件) of the specified course. */
|
|
4
|
+
import { YES, decodeHTML, expectSuccess, formatFileSize, toRequiredServerTime } from './utils.js';
|
|
5
|
+
/** Get all files (课程文件) of the specified course; `category` is left out if the categories can't be fetched. */
|
|
6
6
|
export async function getFileList(s, courseID, courseType = CourseType.STUDENT) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
7
|
+
// categories only fill `category`; don't fail the whole list when they can't be fetched
|
|
8
|
+
const [json, categoryList] = await Promise.all([
|
|
9
|
+
s.fetchJsonWithToken(URLS.LEARN_FILE_LIST(courseID, courseType)),
|
|
10
|
+
getFileCategoryList(s, courseID, courseType).catch(() => []),
|
|
11
|
+
]);
|
|
12
|
+
expectSuccess(json, FailReason.INVALID_RESPONSE);
|
|
14
13
|
let result = [];
|
|
15
14
|
if (Array.isArray(json.object?.resultsList)) {
|
|
16
15
|
// teacher
|
|
@@ -20,54 +19,54 @@ export async function getFileList(s, courseID, courseType = CourseType.STUDENT)
|
|
|
20
19
|
// student
|
|
21
20
|
result = json.object;
|
|
22
21
|
}
|
|
23
|
-
const categories = new Map(
|
|
24
|
-
return result.map((f) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
22
|
+
const categories = new Map(categoryList.map((c) => [c.id, c]));
|
|
23
|
+
return result.map((f) => ({ ...parseFile(s, f, courseType), category: categories.get(f.kjflid) }));
|
|
24
|
+
}
|
|
25
|
+
/** a 0 / 1 flag, which the server sends as a number, a string or (in older answers) a boolean */
|
|
26
|
+
const isSet = (flag) => flag === true || Number(flag) === 1;
|
|
27
|
+
/** a count or size, which the server sends as a number or a string */
|
|
28
|
+
const toNumber = (value) => Number(value ?? 0) || 0;
|
|
29
|
+
/** a file of the object-shaped lists (`getFileList`, and `getFileListByCategory` for a teacher) */
|
|
30
|
+
function parseFile(s, f, courseType) {
|
|
31
|
+
const title = decodeHTML(f.bt);
|
|
32
|
+
const fileId = f.wjid;
|
|
33
|
+
const uploadTime = toRequiredServerTime(f.scsj);
|
|
34
|
+
const downloadUrl = URLS.LEARN_FILE_DOWNLOAD(fileId, courseType);
|
|
35
|
+
const previewUrl = URLS.LEARN_FILE_PREVIEW(ContentType.FILE, fileId, courseType, s.previewFirstPage);
|
|
36
|
+
return {
|
|
37
|
+
id: f.kjxxid,
|
|
38
|
+
fileId,
|
|
39
|
+
title,
|
|
40
|
+
description: decodeHTML(f.ms),
|
|
41
|
+
rawSize: toNumber(f.wjdx),
|
|
42
|
+
size: f.fileSize,
|
|
43
|
+
uploadTime,
|
|
44
|
+
publishTime: uploadTime,
|
|
45
|
+
downloadUrl,
|
|
46
|
+
previewUrl,
|
|
47
|
+
isNew: isSet(f.isNew), // 1 / 0 for a student
|
|
48
|
+
markedImportant: isSet(f.sfqd), // string '1' for a teacher, number 1 for a student
|
|
49
|
+
visitCount: toNumber(f.xsllcs ?? f.llcs),
|
|
50
|
+
downloadCount: toNumber(f.xzcs),
|
|
51
|
+
fileType: f.wjlx,
|
|
52
|
+
remoteFile: {
|
|
53
|
+
id: fileId,
|
|
54
|
+
name: title,
|
|
40
55
|
downloadUrl,
|
|
41
56
|
previewUrl,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
downloadCount: f.xzcs ?? 0,
|
|
46
|
-
fileType: f.wjlx,
|
|
47
|
-
remoteFile: {
|
|
48
|
-
id: fileId,
|
|
49
|
-
name: title,
|
|
50
|
-
downloadUrl,
|
|
51
|
-
previewUrl,
|
|
52
|
-
size: f.fileSize,
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
});
|
|
57
|
+
size: f.fileSize,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
56
60
|
}
|
|
57
61
|
/** Get file categories of the specified course. */
|
|
58
62
|
export async function getFileCategoryList(s, courseID, courseType = CourseType.STUDENT) {
|
|
59
|
-
const json = await
|
|
60
|
-
|
|
61
|
-
return Promise.reject({
|
|
62
|
-
reason: FailReason.INVALID_RESPONSE,
|
|
63
|
-
extra: json,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
63
|
+
const json = await s.fetchJsonWithToken(URLS.LEARN_FILE_CATEGORY_LIST(courseID, courseType));
|
|
64
|
+
expectSuccess(json, FailReason.INVALID_RESPONSE);
|
|
66
65
|
const result = (json.object?.rows ?? []);
|
|
67
66
|
return result.map((c) => ({
|
|
68
67
|
id: c.kjflid,
|
|
69
68
|
title: decodeHTML(c.bt),
|
|
70
|
-
creationTime: c.czsj,
|
|
69
|
+
creationTime: toRequiredServerTime(c.czsj),
|
|
71
70
|
}));
|
|
72
71
|
}
|
|
73
72
|
/**
|
|
@@ -75,93 +74,72 @@ export async function getFileCategoryList(s, courseID, courseType = CourseType.S
|
|
|
75
74
|
* Note: this cannot get correct `visitCount` and `downloadCount` for student
|
|
76
75
|
*/
|
|
77
76
|
export async function getFileListByCategory(s, courseID, categoryId, courseType = CourseType.STUDENT) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return Promise.reject({
|
|
129
|
-
reason: FailReason.INVALID_RESPONSE,
|
|
130
|
-
extra: json,
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
const result = (json.object.aaData ?? []);
|
|
134
|
-
return result.map((f) => {
|
|
135
|
-
const title = decodeHTML(f.bt);
|
|
136
|
-
const fileId = f.wjid;
|
|
137
|
-
const uploadTime = f.scsj;
|
|
138
|
-
const downloadUrl = URLS.LEARN_FILE_DOWNLOAD(fileId, courseType);
|
|
139
|
-
const previewUrl = URLS.LEARN_FILE_PREVIEW(ContentType.FILE, fileId, courseType, s.previewFirstPage);
|
|
140
|
-
return {
|
|
141
|
-
id: f.kjxxid,
|
|
142
|
-
fileId,
|
|
143
|
-
title,
|
|
144
|
-
description: decodeHTML(f.ms),
|
|
145
|
-
rawSize: f.wjdx,
|
|
146
|
-
size: f.fileSize,
|
|
147
|
-
uploadTime,
|
|
148
|
-
publishTime: uploadTime,
|
|
77
|
+
return courseType === CourseType.STUDENT
|
|
78
|
+
? getStudentFileListByCategory(s, courseID, categoryId)
|
|
79
|
+
: getTeacherFileListByCategory(s, courseID, categoryId);
|
|
80
|
+
}
|
|
81
|
+
/** the columns of a row of the student's file list of a category, which is an array instead of an object */
|
|
82
|
+
const COLUMN = {
|
|
83
|
+
ID: 0,
|
|
84
|
+
TITLE: 1,
|
|
85
|
+
MARKED_IMPORTANT: 2,
|
|
86
|
+
DESCRIPTION: 5,
|
|
87
|
+
UPLOAD_TIME: 6,
|
|
88
|
+
FILE_ID: 7,
|
|
89
|
+
IS_NEW: 8,
|
|
90
|
+
RAW_SIZE: 9,
|
|
91
|
+
PUBLISH_TIME: 10,
|
|
92
|
+
IS_FAVORITE: 11,
|
|
93
|
+
FILE_TYPE: 13,
|
|
94
|
+
COMMENT: 14,
|
|
95
|
+
};
|
|
96
|
+
async function getStudentFileListByCategory(s, courseID, categoryId) {
|
|
97
|
+
const json = await s.fetchJsonWithToken(URLS.LEARN_FILE_LIST_BY_CATEGORY_STUDENT(courseID, categoryId));
|
|
98
|
+
expectSuccess(json, FailReason.INVALID_RESPONSE);
|
|
99
|
+
const result = (json.object ?? []);
|
|
100
|
+
return result.map((f) => {
|
|
101
|
+
const fileId = f[COLUMN.FILE_ID];
|
|
102
|
+
const title = decodeHTML(f[COLUMN.TITLE]);
|
|
103
|
+
const rawSize = toNumber(f[COLUMN.RAW_SIZE]);
|
|
104
|
+
const size = formatFileSize(rawSize);
|
|
105
|
+
const downloadUrl = URLS.LEARN_FILE_DOWNLOAD(fileId, CourseType.STUDENT);
|
|
106
|
+
const previewUrl = URLS.LEARN_FILE_PREVIEW(ContentType.FILE, fileId, CourseType.STUDENT, s.previewFirstPage);
|
|
107
|
+
return {
|
|
108
|
+
id: f[COLUMN.ID],
|
|
109
|
+
fileId,
|
|
110
|
+
title,
|
|
111
|
+
description: decodeHTML(f[COLUMN.DESCRIPTION]),
|
|
112
|
+
rawSize,
|
|
113
|
+
size,
|
|
114
|
+
uploadTime: toRequiredServerTime(f[COLUMN.UPLOAD_TIME]),
|
|
115
|
+
publishTime: toRequiredServerTime(f[COLUMN.PUBLISH_TIME]),
|
|
116
|
+
downloadUrl,
|
|
117
|
+
previewUrl,
|
|
118
|
+
isNew: isSet(f[COLUMN.IS_NEW]),
|
|
119
|
+
markedImportant: isSet(f[COLUMN.MARKED_IMPORTANT]),
|
|
120
|
+
// not in this list
|
|
121
|
+
visitCount: 0,
|
|
122
|
+
downloadCount: 0,
|
|
123
|
+
fileType: f[COLUMN.FILE_TYPE],
|
|
124
|
+
remoteFile: {
|
|
125
|
+
id: fileId,
|
|
126
|
+
name: title,
|
|
149
127
|
downloadUrl,
|
|
150
128
|
previewUrl,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
129
|
+
size,
|
|
130
|
+
},
|
|
131
|
+
isFavorite: f[COLUMN.IS_FAVORITE] === YES, // '是' / '否' like the other lists
|
|
132
|
+
comment: f[COLUMN.COMMENT] ?? undefined,
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
async function getTeacherFileListByCategory(s, courseID, categoryId) {
|
|
137
|
+
const json = await s.fetchJsonWithToken(URLS.LEARN_FILE_LIST_BY_CATEGORY_TEACHER, {
|
|
138
|
+
method: 'POST',
|
|
139
|
+
body: URLS.LEARN_FILE_LIST_BY_CATEGORY_TEACHER_FORM_DATA(courseID, categoryId),
|
|
140
|
+
});
|
|
141
|
+
expectSuccess(json, FailReason.INVALID_RESPONSE);
|
|
142
|
+
const result = (json.object?.aaData ?? []);
|
|
143
|
+
return result.map((f) => parseFile(s, f, CourseType.TEACHER));
|
|
166
144
|
}
|
|
167
145
|
//# sourceMappingURL=files.js.map
|
package/lib/files.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.js","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAI3C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAI3C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElG,+GAA+G;AAC/G,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,CAAU,EACV,QAAgB,EAChB,UAAU,GAAe,UAAU,CAAC,OAAO;IAE3C,wFAAwF;IACxF,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC7C,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAChE,mBAAmB,CAAC,CAAC,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,KAAK,CAAC,GAAmB,EAAE,CAAC,EAAE,CAAC;KAC7E,CAAC,CAAC;IACH,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAEjD,IAAI,MAAM,GAAU,EAAE,CAAC;IACvB,IAA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EAAE,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC;YAC7B,UAAU,EAAE;gBACV,EAAE,EAAE,MAAM;gBACV,IAAI,EAAE,KAAK;gBACX,WAAW;gBACX,UAAU;gBACV,IAAI;aACL;YACD,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,GAAG,EAAE,iCAAiC;YAC5E,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,SAAS;SACnB,CAAC;IACzB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,KAAK,UAAU,4BAA4B,CAAC,CAAU,EAAE,QAAgB,EAAE,UAAkB;IAC1F,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,mCAAmC,EAAE;QAChF,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,IAAI,CAAC,6CAA6C,CAAC,QAAQ,EAAE,UAAU,CAAC;KAC/E,CAAC,CAAC;IACH,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAEjD,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,IAAI,EAAE,CAAU,CAAC;IAEpD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;AAChE,CAAC"}
|
package/lib/homework.d.ts
CHANGED
|
@@ -1,17 +1,47 @@
|
|
|
1
1
|
import type { Session } from './request.ts';
|
|
2
|
-
import type { Homework,
|
|
2
|
+
import type { ExcellentHomeworkBase, Homework, HomeworkBase, HomeworkDetail, HomeworkListOptions, HomeworkStatus, HomeworkSubmitAttachment, HomeworkSubmitRequest, HomeworkTA } from './types.ts';
|
|
3
3
|
import { CourseType } from './types.ts';
|
|
4
|
+
/** the student homework lists, by submission status */
|
|
5
|
+
export declare const HOMEWORK_LIST_SOURCES: readonly {
|
|
6
|
+
url: string;
|
|
7
|
+
status: HomeworkStatus;
|
|
8
|
+
}[];
|
|
4
9
|
/**
|
|
5
10
|
* Get all homeworks (课程作业) of the specified course: 3 status lists and the excellent homework list.
|
|
6
11
|
* Details (page + description) only for the homework `options.details` selects.
|
|
7
12
|
*/
|
|
8
|
-
export declare function getHomeworkList(s: Session, courseID: string): Promise<Homework[]>;
|
|
9
|
-
export declare function getHomeworkList(s: Session, courseID: string, courseType: CourseType.STUDENT, options?: HomeworkListOptions): Promise<Homework[]>;
|
|
13
|
+
export declare function getHomeworkList(s: Session, courseID: string, courseType?: CourseType.STUDENT, options?: HomeworkListOptions): Promise<Homework[]>;
|
|
10
14
|
export declare function getHomeworkList(s: Session, courseID: string, courseType: CourseType.TEACHER): Promise<HomeworkTA[]>;
|
|
11
15
|
/**
|
|
12
16
|
* Get the detail of one homework or excellent homework: its page (answer, submitted content, attachments) and the
|
|
13
17
|
* description JSON (which wins for `description`). 2 requests.
|
|
14
18
|
*/
|
|
15
|
-
export declare function getHomeworkDetail(s: Session, homework: Pick<
|
|
16
|
-
export declare function submitHomework(s: Session, id: string, content?: string, attachment?:
|
|
19
|
+
export declare function getHomeworkDetail(s: Session, homework: Pick<HomeworkBase | ExcellentHomeworkBase, 'url' | 'baseId'>): Promise<HomeworkDetail>;
|
|
20
|
+
export declare function submitHomework(s: Session, id: string, content?: string, attachment?: HomeworkSubmitAttachment, removeAttachment?: boolean): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* The request `submitHomework` would send, for sending it with another HTTP client (e.g. one that reports upload
|
|
23
|
+
* progress). Checks the session first (`ensureSession`: one request, and a login only if it has expired), as the
|
|
24
|
+
* request is sent without the helper's re-login and retry. Read the answer with `checkHomeworkSubmitResponse`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getHomeworkSubmitRequest(s: Session, id: string, content?: string, attachment?: HomeworkSubmitAttachment, removeAttachment?: boolean): Promise<HomeworkSubmitRequest>;
|
|
27
|
+
/**
|
|
28
|
+
* Check the server's answer to a homework submission: its parsed JSON, or the body as text. Rejects with
|
|
29
|
+
* `NOT_LOGGED_IN` for the login page of an expired session (which the server sends with status 200),
|
|
30
|
+
* `INVALID_RESPONSE` for any other text that isn't JSON, and `OPERATION_FAILED` (with the answer in `extra`) unless
|
|
31
|
+
* `result` is `'success'`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function checkHomeworkSubmitResponse(body: unknown): void;
|
|
34
|
+
/**
|
|
35
|
+
* The form the website's submit page sends (`fileUploadProgress` in `/res/js/common/myApp.js`): `fileupload` is the
|
|
36
|
+
* picked file, or the text "undefined" when none is picked (it appends `files[0]` as is); `zynr` is the whole current
|
|
37
|
+
* answer as HTML from its editor, sent every time (also when only the attachment changes); `isDeleted` is "1" when the
|
|
38
|
+
* existing attachment is deleted, and then the server ignores `zynr` (the submitted answer stays).
|
|
39
|
+
*/
|
|
40
|
+
export declare const homeworkSubmitForm: (id: string, content?: string, attachment?: HomeworkSubmitAttachment, removeAttachment?: boolean) => FormData;
|
|
41
|
+
/**
|
|
42
|
+
* Plain text as the website's answer editor sends it: one `<p>` per line, with ` ` for an empty line, and `''`
|
|
43
|
+
* for text that is only whitespace. The server replaces the submitted answer with what is sent, so send its HTML
|
|
44
|
+
* as it is when the answer wasn't edited, to keep its formatting.
|
|
45
|
+
*/
|
|
46
|
+
export declare function homeworkContentHtml(text: string): string;
|
|
17
47
|
//# sourceMappingURL=homework.d.ts.map
|
package/lib/homework.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"homework.d.ts","sourceRoot":"","sources":["../src/homework.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"homework.d.ts","sourceRoot":"","sources":["../src/homework.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAEV,qBAAqB,EACrB,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,m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