mirror of
https://github.com/classchartsapi/classcharts-api-js.git
synced 2026-05-14 11:58:13 +00:00
intial fix
This commit is contained in:
parent
8609ff4ba6
commit
a465a84499
3 changed files with 15 additions and 6 deletions
|
|
@ -37,7 +37,6 @@ export class ClasschartsClient {
|
|||
this.axios = axios.create({
|
||||
...axiosConfig,
|
||||
headers: {
|
||||
"User-Agent": "classcharts-api.js",
|
||||
...axiosConfig?.headers,
|
||||
},
|
||||
validateStatus: () => true,
|
||||
|
|
@ -45,16 +44,17 @@ export class ClasschartsClient {
|
|||
}
|
||||
public async makeAuthedRequest(
|
||||
path: string,
|
||||
options: Omit<AxiosRequestConfig, "path">
|
||||
axiosOptions: Omit<AxiosRequestConfig, "path">,
|
||||
options?: { inlcudeMeta?: boolean }
|
||||
) {
|
||||
if (!this.authCookies) throw new Error("Not authenticated");
|
||||
const requestOptions: AxiosRequestConfig = {
|
||||
...options,
|
||||
...axiosOptions,
|
||||
url: path,
|
||||
headers: {
|
||||
Cookie: this.authCookies.join(";"),
|
||||
authorization: "Basic " + this.sessionId,
|
||||
...options.headers,
|
||||
...axiosOptions.headers,
|
||||
},
|
||||
};
|
||||
const request = await this.axios.request(requestOptions);
|
||||
|
|
@ -62,6 +62,9 @@ export class ClasschartsClient {
|
|||
if (responseJSON.success == 0) {
|
||||
throw new Error(responseJSON.error);
|
||||
}
|
||||
if (options?.inlcudeMeta) {
|
||||
return responseJSON;
|
||||
}
|
||||
return responseJSON.data;
|
||||
}
|
||||
|
||||
|
|
@ -166,7 +169,6 @@ export class ClasschartsClient {
|
|||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
data[i].description_raw = data[i].description;
|
||||
|
||||
// homework.lesson.replace(/\\/g, '')
|
||||
data[i].description = data[i].description.replace(/(<([^>]+)>)/gi, "");
|
||||
data[i].description = data[i].description.replace(/ /g, "");
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ export class ClasschartsParentClient extends ClasschartsClient {
|
|||
formData.append("logintype", "existing");
|
||||
formData.append("password", this.password);
|
||||
formData.append("recaptcha-token", "no-token-avaliable");
|
||||
|
||||
const request = await this.axios.request({
|
||||
url: BASE_URL + "/parent/login",
|
||||
method: "POST",
|
||||
|
|
|
|||
|
|
@ -58,5 +58,13 @@ export class ClasschartsStudentClient extends ClasschartsClient {
|
|||
const user = await this.getStudentInfo();
|
||||
this.studentId = user.id;
|
||||
this.studentName = user.name;
|
||||
const pingData = await this.makeAuthedRequest(
|
||||
this.API_BASE + "/ping",
|
||||
{
|
||||
method: "GET",
|
||||
},
|
||||
{ inlcudeMeta: true }
|
||||
);
|
||||
this.sessionId = pingData.meta.session_id;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue