1
0
Fork 0
mirror of https://github.com/classchartsapi/classcharts-api-js.git synced 2026-05-14 11:58:13 +00:00

fix: client getting logged out (#18)

This commit is contained in:
James Cook 2022-09-23 19:40:32 +01:00 committed by GitHub
parent 8609ff4ba6
commit ecbbc4777b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 8 deletions

View file

@ -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(/&nbsp;/g, "");