mirror of
https://github.com/classchartsapi/classcharts-api-js.git
synced 2026-05-14 19:59:37 +00:00
fix: client getting logged out (#18)
This commit is contained in:
parent
8609ff4ba6
commit
ecbbc4777b
5 changed files with 24 additions and 8 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -117,4 +117,5 @@ dist
|
|||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
tests/config.json
|
||||
tests/config.json
|
||||
tests/sandbox.js
|
||||
|
|
@ -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?: { includeMeta?: 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?.includeMeta) {
|
||||
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,19 @@ export class ClasschartsStudentClient extends ClasschartsClient {
|
|||
const user = await this.getStudentInfo();
|
||||
this.studentId = user.id;
|
||||
this.studentName = user.name;
|
||||
const pingFormData = new URLSearchParams();
|
||||
pingFormData.append("include_data", "true");
|
||||
const pingData = await this.makeAuthedRequest(
|
||||
this.API_BASE + "/ping",
|
||||
{
|
||||
method: "POST",
|
||||
data: pingFormData.toString(),
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
},
|
||||
{ includeMeta: true }
|
||||
);
|
||||
this.sessionId = pingData.meta.session_id;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ test("client returns activity data", () => {
|
|||
|
||||
test("client returns full activity", () => {
|
||||
return client
|
||||
.getFullActivity({ from: "2000-01-01", to: "2022-01-01" })
|
||||
.getFullActivity({ from: "2022-01-01", to: "2022-09-01" })
|
||||
.then((data) => {
|
||||
let valid = false;
|
||||
if (data.length > 50) valid = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue