Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Cookie
cookie.json

# VSCode Specific
.vscode/settings.json
96 changes: 96 additions & 0 deletions auth/cas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,51 @@ export default class CASAuth {
}
}

async loginHUBM() {
const url = 'http://hub.m.hust.edu.cn/hub_weix';
const isLogin = await this.checkLoginStatus();

if (!isLogin) {
return false;
}

try {
let response = await this.axios.get(url);
response = await followRedirect(response, this.axios);

return response.status === 200;
} catch (e) {
return false;
}
}

async loginMHUB() {
const url = 'http://mhub.hust.edu.cn/';
const isLogin = await this.checkLoginStatus();

if (!isLogin) {
return false;
}

try {
let response = await this.axios.get(url);

if (
response.status === 302 &&
response.headers.location.includes('login')
) {
response = await this.axios.get(
`${CASAuth.CAS_URL}/login?service=${encodeURIComponent('https://mhub.hust.edu.cn/cas/login')}`,
);

response = await followRedirect(response, this.axios);
}
return response.status === 200;
} catch (e) {
return false;
}
}

async loginONE() {
const url = 'https://one.hust.edu.cn/dcp/';

Expand All @@ -284,6 +329,24 @@ export default class CASAuth {
}
}

async loginPhysics() {
const url = 'http://empxk.hust.edu.cn/';
const isLogin = await this.checkLoginStatus();

if (!isLogin) {
return false;
}

try {
let response = await this.axios.get(url);
response = await followRedirect(response, this.axios);

return response.status === 200;
} catch (e) {
return false;
}
}

// 检查对应网站是否登录
async checkPETYXY() {
const url = 'https://petyxy.hust.edu.cn';
Expand All @@ -307,6 +370,28 @@ export default class CASAuth {
}
}

async checkHUBM() {
const url = 'http://hub.m.hust.edu.cn/hub_weix/menuPage.do?CDBH=9128';

try {
const response = await this.axios.get(url);
return !isNeedAuth(response);
} catch (e) {
return false;
}
}

async checkMHUB() {
const url = 'https://mhub.hust.edu.cn/';

try {
const response = await this.axios.get(url);
return !isNeedAuth(response);
} catch (e) {
return false;
}
}

async checkONE() {
const url = 'https://one.hust.edu.cn/dcp/';

Expand All @@ -317,6 +402,17 @@ export default class CASAuth {
return false;
}
}

async checkPhysics() {
const url = 'http://empxk.hust.edu.cn/';

try {
const response = await this.axios.get(url);
return !isNeedAuth(response);
} catch (e) {
return false;
}
}
}

// const cookieManager = new CookieManager();
Expand Down
3 changes: 3 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

121 changes: 121 additions & 0 deletions clients/course-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import type { AxiosInstance } from 'axios';
import axios from 'axios';
import { useCookie } from '@/utils/use-cookie';
import type HUST from '..';
import {
getPhysicsCourseGrades,
getPhysicsCourseSchedule as getPhysicsCourseSchedule,
} from './course/physics';
import {
getExaminationArrangements,
getNormalCourseGrades,
getNormalCourseSchedule,
} from './course/course';
import { ExaminationType } from '@/types/clients/course/course';
import { getPracticeCourseSchedule } from './course/practice';

export default class CourseClient {
protected readonly axios: AxiosInstance;
protected readonly hust: HUST;

constructor(hust: HUST) {
this.hust = hust;
this.axios = axios.create({
timeout: 30000,
maxRedirects: 0,
validateStatus: (status) => status < 400,
headers: {
'User-Agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36',
},
});
useCookie(this.axios, this.hust.getCookieManager());
}

async getPhysicsCourseSchedule() {
return await this.hust.handleRequest(() =>
getPhysicsCourseSchedule(this.axios),
);
}

async getPhysicsCourseGrades() {
return await this.hust.handleRequest(() =>
getPhysicsCourseGrades(this.axios),
);
}

async getNormalCourseSchedule(semesterId: string) {
return await this.hust.handleRequest(() =>
getNormalCourseSchedule(this.axios, semesterId),
);
}

async getNormalCourseGrades(
semesterId: string,
{
all,
pageNumber,
pageSize,
}: {
all?: boolean;
pageNumber?: number;
pageSize?: number;
} = {
all: false,
pageNumber: 1,
pageSize: 20,
},
) {
if (all) {
pageNumber = 1;
pageSize = 100;
}
return await this.hust.handleRequest(() =>
getNormalCourseGrades(this.axios, semesterId, pageNumber, pageSize),
);
}

async getExaminationArrangements(
semesterId: string,
{
pageIndex,
pageSize,
keyword,
type,
}: {
pageIndex: number;
pageSize: number;
keyword: string;
type: ExaminationType;
} = {
pageIndex: 1,
pageSize: 100,
keyword: '',
type: ExaminationType.NORMAL,
},
) {
return await this.hust.handleRequest(() =>
getExaminationArrangements(this.axios, semesterId, {
pageIndex,
pageSize,
keyword,
type,
}),
);
}

async getPracticeCourseSchedule({
start,
end,
}: {
start: string;
end: string;
}): Promise<any[]> {
return await this.hust.handleRequest(() =>
getPracticeCourseSchedule(this.axios, {
start,
end,
}),
);
}
}
Loading