From 53ee3c1cad49f3e51c643f94ee34cc02dee7a29f Mon Sep 17 00:00:00 2001 From: Christian Landgren Date: Fri, 6 Oct 2023 14:50:27 +0200 Subject: [PATCH 1/2] feat: get messages and canvas token --- libs/api-admentum/lib/apiAdmentum.ts | 8 +++++++- libs/api-admentum/lib/routes.ts | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/libs/api-admentum/lib/apiAdmentum.ts b/libs/api-admentum/lib/apiAdmentum.ts index 19f804ab..bf77e6e9 100644 --- a/libs/api-admentum/lib/apiAdmentum.ts +++ b/libs/api-admentum/lib/apiAdmentum.ts @@ -366,12 +366,18 @@ export class ApiAdmentum extends EventEmitter implements Api { if (!this.isLoggedIn) { throw new Error('Not logged in...') } + const token = await this.fetch('get-messages', apiUrls.messages) + .then((res) => res.text()) + .then((html) => /token:\s+'(.*)'/.exec(html)?.pop()) // HACK: this could probably be found at a better place than the html code.. - const fetchUrl = apiUrls.messages(this.userId, '1') + console.log('token', token) + + const fetchUrl = apiUrls.conversations(this.userId, '1') console.log('fetching messages', fetchUrl) const messagesResponse = await this.fetch('get-messages', fetchUrl, { headers: { 'x-requested-with': 'XMLHttpRequest', + 'user-info': token, }, }) const messagesResponseJson = await messagesResponse.json() diff --git a/libs/api-admentum/lib/routes.ts b/libs/api-admentum/lib/routes.ts index ea55668a..0b29d344 100644 --- a/libs/api-admentum/lib/routes.ts +++ b/libs/api-admentum/lib/routes.ts @@ -15,9 +15,10 @@ export const apiUrls = { leisure_groups: api + 'leisure_groups', lesson_infos: api + 'lesson_infos', lessons: api + 'lessons', + messages: 'https://skola.admentum.se/messages/', // start at page 1 - messages: (userId: string, page: string) => - `https://messages.admentum.se/api/users/${userId}/conversations?page=${page}`, // unread_only=1 + conversations: (userId: string, page: string) => + `https://messages.admentum.se/api/users/${userId}/conversations?page=${page}`, // unread_only=1 organisations: api + 'organisations', orientations: api + 'orientations', overview: (action: string, year: string, week: string) => From b0764cf65ade5441811b633a655e16d53ae043dc Mon Sep 17 00:00:00 2001 From: Christian Landgren Date: Fri, 6 Oct 2023 14:51:11 +0200 Subject: [PATCH 2/2] fix: correct name for fetch token --- libs/api-admentum/lib/apiAdmentum.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/api-admentum/lib/apiAdmentum.ts b/libs/api-admentum/lib/apiAdmentum.ts index bf77e6e9..5750d153 100644 --- a/libs/api-admentum/lib/apiAdmentum.ts +++ b/libs/api-admentum/lib/apiAdmentum.ts @@ -366,7 +366,7 @@ export class ApiAdmentum extends EventEmitter implements Api { if (!this.isLoggedIn) { throw new Error('Not logged in...') } - const token = await this.fetch('get-messages', apiUrls.messages) + const token = await this.fetch('get-token', apiUrls.messages) .then((res) => res.text()) .then((html) => /token:\s+'(.*)'/.exec(html)?.pop()) // HACK: this could probably be found at a better place than the html code..