@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/files.d.ts
CHANGED
|
@@ -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
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<
|
|
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';
|
|
4
|
+
import { YES, decodeHTML, expectSuccess, formatFileSize, toRequiredServerTime } from './utils.js';
|
|
5
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,56 +19,54 @@ export async function getFileList(s, courseID, courseType = CourseType.STUDENT)
|
|
|
20
19
|
// student
|
|
21
20
|
result = json.object;
|
|
22
21
|
}
|
|
23
|
-
// categories only fill `category`; don't fail the whole list when they can't be fetched
|
|
24
|
-
const categoryList = await getFileCategoryList(s, courseID, courseType).catch(() => []);
|
|
25
22
|
const categories = new Map(categoryList.map((c) => [c.id, c]));
|
|
26
|
-
return result.map((f) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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,
|
|
42
55
|
downloadUrl,
|
|
43
56
|
previewUrl,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
downloadCount: f.xzcs ?? 0,
|
|
48
|
-
fileType: f.wjlx,
|
|
49
|
-
remoteFile: {
|
|
50
|
-
id: fileId,
|
|
51
|
-
name: title,
|
|
52
|
-
downloadUrl,
|
|
53
|
-
previewUrl,
|
|
54
|
-
size: f.fileSize,
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
});
|
|
57
|
+
size: f.fileSize,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
58
60
|
}
|
|
59
61
|
/** Get file categories of the specified course. */
|
|
60
62
|
export async function getFileCategoryList(s, courseID, courseType = CourseType.STUDENT) {
|
|
61
63
|
const json = await s.fetchJsonWithToken(URLS.LEARN_FILE_CATEGORY_LIST(courseID, courseType));
|
|
62
|
-
|
|
63
|
-
return Promise.reject({
|
|
64
|
-
reason: FailReason.INVALID_RESPONSE,
|
|
65
|
-
extra: json,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
64
|
+
expectSuccess(json, FailReason.INVALID_RESPONSE);
|
|
68
65
|
const result = (json.object?.rows ?? []);
|
|
69
66
|
return result.map((c) => ({
|
|
70
67
|
id: c.kjflid,
|
|
71
68
|
title: decodeHTML(c.bt),
|
|
72
|
-
creationTime: c.czsj,
|
|
69
|
+
creationTime: toRequiredServerTime(c.czsj),
|
|
73
70
|
}));
|
|
74
71
|
}
|
|
75
72
|
/**
|
|
@@ -77,93 +74,72 @@ export async function getFileCategoryList(s, courseID, courseType = CourseType.S
|
|
|
77
74
|
* Note: this cannot get correct `visitCount` and `downloadCount` for student
|
|
78
75
|
*/
|
|
79
76
|
export async function getFileListByCategory(s, courseID, categoryId, courseType = CourseType.STUDENT) {
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
return Promise.reject({
|
|
131
|
-
reason: FailReason.INVALID_RESPONSE,
|
|
132
|
-
extra: json,
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
const result = (json.object?.aaData ?? []);
|
|
136
|
-
return result.map((f) => {
|
|
137
|
-
const title = decodeHTML(f.bt);
|
|
138
|
-
const fileId = f.wjid;
|
|
139
|
-
const uploadTime = f.scsj;
|
|
140
|
-
const downloadUrl = URLS.LEARN_FILE_DOWNLOAD(fileId, courseType);
|
|
141
|
-
const previewUrl = URLS.LEARN_FILE_PREVIEW(ContentType.FILE, fileId, courseType, s.previewFirstPage);
|
|
142
|
-
return {
|
|
143
|
-
id: f.kjxxid,
|
|
144
|
-
fileId,
|
|
145
|
-
title,
|
|
146
|
-
description: decodeHTML(f.ms),
|
|
147
|
-
rawSize: f.wjdx,
|
|
148
|
-
size: f.fileSize,
|
|
149
|
-
uploadTime,
|
|
150
|
-
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,
|
|
151
127
|
downloadUrl,
|
|
152
128
|
previewUrl,
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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));
|
|
168
144
|
}
|
|
169
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,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AAC,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,6 +1,11 @@
|
|
|
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.
|
|
@@ -11,6 +16,32 @@ export declare function getHomeworkList(s: Session, courseID: string, courseType
|
|
|
11
16
|
* Get the detail of one homework or excellent homework: its page (answer, submitted content, attachments) and the
|
|
12
17
|
* description JSON (which wins for `description`). 2 requests.
|
|
13
18
|
*/
|
|
14
|
-
export declare function getHomeworkDetail(s: Session, homework: Pick<
|
|
15
|
-
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;
|
|
16
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,mBAAmB,EACnB,cAAc,EACd,wBAAwB,EACxB,qBAAqB,EACrB,UAAU,EAEX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAe,UAAU,EAAc,MAAM,YAAY,CAAC;AAiBjE,uDAAuD;AACvD,eAAO,MAAM,qBAAqB,EAAE,SAAS;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,cAAc,CAAA;CAAE,EAInF,CAAC;AAEF;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,CAAC,EAAE,OAAO,EACV,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,UAAU,CAAC,OAAO,EAC/B,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;AAEvB,wBAAgB,eAAe,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;AA2JrH;;;GAGG;AACH,wBAAsB,iBAAiB,CACrC,CAAC,EAAE,OAAO,EACV,QAAQ,EAAE,IAAI,CAAC,YAAY,GAAG,qBAAqB,EAAE,KAAK,GAAG,QAAQ,CAAC,GACrE,OAAO,CAAC,cAAc,CAAC,CAOzB;AAoCD,wBAAsB,cAAc,CAClC,CAAC,EA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