Skip to content

Commit

Permalink
hoppa
Browse files Browse the repository at this point in the history
  • Loading branch information
QkeleQ10 committed Jun 11, 2024
1 parent 31a844e commit 9125451
Show file tree
Hide file tree
Showing 7 changed files with 376 additions and 632 deletions.
2 changes: 1 addition & 1 deletion manifest-firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"manifest_version": 3,
"name": "__MSG_appName__",
"description": "__MSG_appDesc__",
"version": "3.10.5",
"version": "3.11.0",
"default_locale": "nl",
"icons": {
"16": "icons/[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"manifest_version": 3,
"name": "__MSG_appName__",
"description": "__MSG_appDesc__",
"version": "3.10.5",
"version": "3.11.0",
"default_locale": "nl",
"icons": {
"16": "icons/[email protected]",
Expand Down
91 changes: 49 additions & 42 deletions src/magister/scripts/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,30 @@ const MagisterApi = {
)
})
},
examInfo: async (year) => {
return new Promise(async (resolve, reject) => {
magisterApiCache['examInfo' + year?.id] ??=
fetchWrapper(
`https://${magisterApiSchoolName}.magister.net/api/aanmeldingen/${year?.id}/examen`, null, 'examInfo'

exams: {
list: async (year) => {
return new Promise(async (resolve, reject) => {
magisterApiCache['examsList' + year?.id] ??=
fetchWrapper(
`https://${magisterApiSchoolName}.magister.net/api/aanmeldingen/${year?.id}/examens`, null, 'examsList'
)
resolve(
(await magisterApiCache['examsList' + year?.id])?.items || null
)
resolve(
(await magisterApiCache['examInfo' + year?.id])
)
})
},
exams: async (year) => {
return new Promise(async (resolve, reject) => {
magisterApiCache['exams' + year?.id] ??=
fetchWrapper(
`https://${magisterApiSchoolName}.magister.net/api/aanmeldingen/${year?.id}/examens`, null, 'exams'
})
},
info: async (year) => {
return new Promise(async (resolve, reject) => {
magisterApiCache['examsInfo' + year?.id] ??=
fetchWrapper(
`https://${magisterApiSchoolName}.magister.net/api/aanmeldingen/${year?.id}/examen`, null, 'examsInfo', true
)
resolve(
(await magisterApiCache['examsInfo' + year?.id]) || {}
)
resolve(
(await magisterApiCache['exams' + year?.id])?.items
)
})
})
}
},
events: async (start = gatherStart, end = gatherEnd) => {
return new Promise(async (resolve, reject) => {
Expand Down Expand Up @@ -226,7 +229,7 @@ const MagisterApi = {
* @param {Object} options
* @returns {Promise<Object>}
*/
async function fetchWrapper(url, options, identifier = 'unknown') {
async function fetchWrapper(url, options, identifier = 'unknown', quiet = false) {
const calledAt = new Date()

const promiseReq = new Promise(async (resolve, reject) => {
Expand Down Expand Up @@ -257,7 +260,7 @@ async function fetchWrapper(url, options, identifier = 'unknown') {
}

// Reject when ratelimit is hit
if (res1.status === 429) {
if (res1.status === 429 && !quiet) {
notify('snackbar', `Verzoeksquotum overschreden\nWacht even, vernieuw de pagina en probeer het opnieuw`)
return resolve({})
}
Expand Down Expand Up @@ -289,22 +292,24 @@ async function fetchWrapper(url, options, identifier = 'unknown') {
}

// Reject when ratelimit is hit
if (res2.status === 429) {
if (res2.status === 429 && !quiet) {
notify('snackbar', `Verzoeksquotum overschreden\nWacht even, vernieuw de pagina en probeer het opnieuw`)
return resolve({})
}

// Handle other errors
notify(
'snackbar',
`Fout ${res2.status}. Druk op Ctrl + Shift + J en stuur me een screenshot!`,
[
{ innerText: "E-mail", href: `mailto:[email protected]` },
{ innerText: "Discord", href: `https://discord.gg/2rP7pfeAKf` }
],
120000
)
console.log(`Het zou me erg helpen als je een screenshot of kopie van de volgende informatie doorstuurt via e-mail ([email protected]) of Discord (https://discord.gg/2rP7pfeAKf) 💚`)
if (!quiet) {
notify(
'snackbar',
`Fout ${res2.status}. Druk op Ctrl + Shift + J en stuur me een screenshot!`,
[
{ innerText: "E-mail", href: `mailto:[email protected]` },
{ innerText: "Discord", href: `https://discord.gg/2rP7pfeAKf` }
],
120000
)
console.log(`Het zou me erg helpen als je een screenshot of kopie van de volgende informatie doorstuurt via e-mail ([email protected]) of Discord (https://discord.gg/2rP7pfeAKf) 💚`)
}
console.error(`APIRQ: ${res2.status}\n\nurl: ${url}\nuserId: ${magisterApiUserId}\nuserToken.length: ${magisterApiUserToken?.length} (@ ${identifier})`)
return resolve({})
})
Expand All @@ -317,16 +322,18 @@ async function fetchWrapper(url, options, identifier = 'unknown') {
})
])
.catch(err => {
notify(
'snackbar',
`Er is iets misgegaan. Druk op Ctrl + Shift + J en stuur me een screenshot!`,
[
{ innerText: "e-mail", href: `mailto:[email protected]` },
{ innerText: "Discord", href: `https://discord.gg/2rP7pfeAKf` }
],
120000
)
console.log(`Het zou me erg helpen als je een screenshot of kopie van de volgende informatie doorstuurt via e-mail ([email protected]) of Discord (https://discord.gg/2rP7pfeAKf) 💚`)
if (!quiet) {
notify(
'snackbar',
`Er is iets misgegaan. Druk op Ctrl + Shift + J en stuur me een screenshot!`,
[
{ innerText: "e-mail", href: `mailto:[email protected]` },
{ innerText: "Discord", href: `https://discord.gg/2rP7pfeAKf` }
],
120000
)
console.log(`Het zou me erg helpen als je een screenshot of kopie van de volgende informatie doorstuurt via e-mail ([email protected]) of Discord (https://discord.gg/2rP7pfeAKf) 💚`)
}
console.error(`APIRQ: ${err}\n\nurl: ${url}\nuserId: ${magisterApiUserId}\nuserToken.length: ${magisterApiUserToken?.length} (@ ${identifier})`)
return ({})
})
Expand Down
Loading

0 comments on commit 9125451

Please sign in to comment.