mirror of
https://github.com/classchartsapi/classcharts-api-js.git
synced 2026-05-14 19:59:37 +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({
|
this.axios = axios.create({
|
||||||
...axiosConfig,
|
...axiosConfig,
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": "classcharts-api.js",
|
|
||||||
...axiosConfig?.headers,
|
...axiosConfig?.headers,
|
||||||
},
|
},
|
||||||
validateStatus: () => true,
|
validateStatus: () => true,
|
||||||
|
|
@ -45,16 +44,17 @@ export class ClasschartsClient {
|
||||||
}
|
}
|
||||||
public async makeAuthedRequest(
|
public async makeAuthedRequest(
|
||||||
path: string,
|
path: string,
|
||||||
options: Omit<AxiosRequestConfig, "path">
|
axiosOptions: Omit<AxiosRequestConfig, "path">,
|
||||||
|
options?: { inlcudeMeta?: boolean }
|
||||||
) {
|
) {
|
||||||
if (!this.authCookies) throw new Error("Not authenticated");
|
if (!this.authCookies) throw new Error("Not authenticated");
|
||||||
const requestOptions: AxiosRequestConfig = {
|
const requestOptions: AxiosRequestConfig = {
|
||||||
...options,
|
...axiosOptions,
|
||||||
url: path,
|
url: path,
|
||||||
headers: {
|
headers: {
|
||||||
Cookie: this.authCookies.join(";"),
|
Cookie: this.authCookies.join(";"),
|
||||||
authorization: "Basic " + this.sessionId,
|
authorization: "Basic " + this.sessionId,
|
||||||
...options.headers,
|
...axiosOptions.headers,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const request = await this.axios.request(requestOptions);
|
const request = await this.axios.request(requestOptions);
|
||||||
|
|
@ -62,6 +62,9 @@ export class ClasschartsClient {
|
||||||
if (responseJSON.success == 0) {
|
if (responseJSON.success == 0) {
|
||||||
throw new Error(responseJSON.error);
|
throw new Error(responseJSON.error);
|
||||||
}
|
}
|
||||||
|
if (options?.inlcudeMeta) {
|
||||||
|
return responseJSON;
|
||||||
|
}
|
||||||
return responseJSON.data;
|
return responseJSON.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,7 +169,6 @@ export class ClasschartsClient {
|
||||||
|
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
data[i].description_raw = data[i].description;
|
data[i].description_raw = data[i].description;
|
||||||
|
|
||||||
// homework.lesson.replace(/\\/g, '')
|
// homework.lesson.replace(/\\/g, '')
|
||||||
data[i].description = data[i].description.replace(/(<([^>]+)>)/gi, "");
|
data[i].description = data[i].description.replace(/(<([^>]+)>)/gi, "");
|
||||||
data[i].description = data[i].description.replace(/ /g, "");
|
data[i].description = data[i].description.replace(/ /g, "");
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,6 @@ export class ClasschartsParentClient extends ClasschartsClient {
|
||||||
formData.append("logintype", "existing");
|
formData.append("logintype", "existing");
|
||||||
formData.append("password", this.password);
|
formData.append("password", this.password);
|
||||||
formData.append("recaptcha-token", "no-token-avaliable");
|
formData.append("recaptcha-token", "no-token-avaliable");
|
||||||
|
|
||||||
const request = await this.axios.request({
|
const request = await this.axios.request({
|
||||||
url: BASE_URL + "/parent/login",
|
url: BASE_URL + "/parent/login",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|
|
||||||
|
|
@ -58,5 +58,13 @@ export class ClasschartsStudentClient extends ClasschartsClient {
|
||||||
const user = await this.getStudentInfo();
|
const user = await this.getStudentInfo();
|
||||||
this.studentId = user.id;
|
this.studentId = user.id;
|
||||||
this.studentName = user.name;
|
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