diff --git a/app.vue b/app.vue index 01ecf93..633b78f 100644 --- a/app.vue +++ b/app.vue @@ -7,27 +7,27 @@ diff --git a/composables/useCampus.ts b/composables/useCampus.ts new file mode 100644 index 0000000..58e3af1 --- /dev/null +++ b/composables/useCampus.ts @@ -0,0 +1,43 @@ +import { ref } from 'vue'; + +const baseCampusURL = "https://selfservice.campus-dual.de" +const baseCorsUrl = "https://corsproxy.io/?" + +export function useCampus() { + const username = useCookie("username"); + const password = useCookie("password"); + + async function getCampusData(type: 'room' | 'timeline' | 'credits' | 'semester') { + + const UrlParams = `?userid=${username.value}&hash=${password.value}&t=${Math.floor(Date.now() / 1000)}&_=${Date.now()}` + + switch (type) { + + case 'room': + var urlPath = "/room/json" + break; + case 'timeline': + var urlPath = "/dash/gettimeline" + break; + case 'credits': + var urlPath = "/dash/getcp" + break; + case 'semester': + var urlPath = "/dash/getfs" + break; + + default: + throw new Error('Invalid type'); + } + + const url = baseCorsUrl + encodeURIComponent(baseCampusURL + urlPath + UrlParams) + + return await $fetch(url); + } + + return { + username, + password, + getCampusData + }; +} \ No newline at end of file diff --git a/middleware/isLoggedIn.global.ts b/middleware/isLoggedIn.global.ts index a9eaeb3..d1cabf8 100644 --- a/middleware/isLoggedIn.global.ts +++ b/middleware/isLoggedIn.global.ts @@ -17,7 +17,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => { try { const test_url = `https://corsproxy.io/?https%3A%2F%2Fselfservice.campus-dual.de%2Fdash%2Fgetcp%3Fuser%3D${username.value}%26hash%3D${password.value}` const response = await $fetch(test_url) - isLoggedIn.value = !!(response == 0) + isLoggedIn.value = !!(typeof response === 'number') } catch (error) { isLoggedIn.value = false } diff --git a/pages/dash/stundenplan.vue b/pages/dash/stundenplan.vue index 2ee90ca..17828ee 100644 --- a/pages/dash/stundenplan.vue +++ b/pages/dash/stundenplan.vue @@ -42,6 +42,8 @@ definePageMeta({ key: route => route.fullPath, }); +const { getCampusData } = useCampus() + const router = useRouter(); const localData = ref([]); @@ -117,14 +119,23 @@ onMounted(async () => { localStorage.setItem('stundenplan', JSON.stringify(newValue)); }, { deep: true }); + const response = await getCampusData('room'); + function arraysEqual(a, b) { + if (a === b) return true; + if (a == null || b == null) return false; + if (a.length !== b.length) return false; - const response = await $fetch( - `https://corsproxy.io/?https%3A%2F%2Fselfservice.campus-dual.de%2Froom%2Fjson%3Fuserid%3D${username.value}%26hash%3D${password.value}%26t%3D${Math.floor(Date.now() / 1000)}%26_%3D${Date.now()}` - ); + for (var i = 0; i < a.length; ++i) { + if (JSON.stringify(a[i]) !== JSON.stringify(b[i])) return false; + } + return true; + } - data.value = response; - localData.value = data.value; + if (!arraysEqual(JSON.parse(JSON.stringify(localData.value)), response)) { + data.value = response; + localData.value = data.value; + } hasLoaded.value = true; }); diff --git a/pages/login.vue b/pages/login.vue index 3ff2fa4..50d844c 100644 --- a/pages/login.vue +++ b/pages/login.vue @@ -8,27 +8,16 @@
Bitte geben Sie einen Benutzernamen ein.
- +Bitte geben Sie ein Passwort ein.
-Der Login ist fehlgeschlagen. Überprüfe ob du tatsächlich deinen aktuellen Hash von der CampusDual API hast. @@ -37,48 +26,48 @@