Skip to content

Commit

Permalink
feat: use new notification list api
Browse files Browse the repository at this point in the history
  • Loading branch information
AsakuraMizu committed Dec 1, 2024
1 parent 2f8c7b7 commit fd30dba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
18 changes: 17 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,23 @@ export class Learn2018Helper {
courseID: string,
courseType: CourseType = CourseType.STUDENT,
): Promise<Notification[]> {
const json = await (await this.#myFetchWithToken(URLS.LEARN_NOTIFICATION_LIST(courseID, courseType))).json();
return Promise.all([
this.getNotificationListKind(courseID, courseType, false),
this.getNotificationListKind(courseID, courseType, true),
]).then((r) => r.flat());
}

private async getNotificationListKind(
courseID: string,
courseType: CourseType,
expired: boolean,
): Promise<Notification[]> {
const json = await (
await this.#myFetchWithToken(URLS.LEARN_NOTIFICATION_LIST(courseType, expired), {
method: 'POST',
body: URLS.LEARN_PAGE_LIST_FORM_DATA(courseID),
})
).json();
if (json.result !== 'success') {
return Promise.reject({
reason: FailReason.INVALID_RESPONSE,
Expand Down
8 changes: 4 additions & 4 deletions src/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ export const LEARN_FILE_PREVIEW = (type: ContentType, fileID: string, courseType
type,
)}&browser=-1&sfgk=0&pageType=${firstPageOnly ? 'first' : 'all'}`;

export const LEARN_NOTIFICATION_LIST = (courseID: string, courseType: CourseType) =>
courseType === CourseType.STUDENT
? `${LEARN_PREFIX}/b/wlxt/kcgg/wlkc_ggb/student/kcggListXs?wlkcid=${courseID}&size=${MAX_SIZE}`
: `${LEARN_PREFIX}/b/wlxt/kcgg/wlkc_ggb/teacher/kcggList?wlkcid=${courseID}&size=${MAX_SIZE}`;
export const LEARN_NOTIFICATION_LIST = (courseType: CourseType, expired: boolean) =>
`${LEARN_PREFIX}/b/wlxt/kcgg/wlkc_ggb/` +
(courseType === CourseType.STUDENT ? 'student/pageListXsby' : 'teacher/pageListby') +
(expired ? 'Ygq' : 'Wgq');

export const LEARN_NOTIFICATION_DETAIL = (courseID: string, notificationID: string, courseType: CourseType) =>
courseType === CourseType.STUDENT
Expand Down

0 comments on commit fd30dba

Please sign in to comment.