Skip to content

Commit

Permalink
🐛 test
Browse files Browse the repository at this point in the history
  • Loading branch information
nrmnqdds committed Oct 6, 2024
1 parent 40e1cb3 commit 7023e80
Show file tree
Hide file tree
Showing 5 changed files with 523 additions and 358 deletions.
9 changes: 4 additions & 5 deletions app/api/profile/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IMALUUM_HOME_PAGE } from "@/constants";
import got from "got";
import { cookies } from "next/headers";
import { type NextRequest, NextResponse } from "next/server";
import { parse } from "node-html-parser";
Expand All @@ -14,12 +13,10 @@ export async function GET(request: NextRequest) {
}

try {
const response = await got(IMALUUM_HOME_PAGE, {
const response = await fetch(IMALUUM_HOME_PAGE, {
headers: {
Cookie: cookies().toString(),
},
https: { rejectUnauthorized: false },
followRedirect: false,
});

if (!response.ok) {
Expand All @@ -30,7 +27,9 @@ export async function GET(request: NextRequest) {
);
}

const root = parse(response.body);
const body = await response.text();

const root = parse(body);

const hiddenTextSelector = root.querySelector(
".navbar-custom-menu ul.nav.navbar-nav li.dropdown.user.user-menu span.hidden-xs",
Expand Down
38 changes: 25 additions & 13 deletions app/api/result/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IMALUUM_RESULT_PAGE } from "@/constants";
import got from "got";
import { cookies } from "next/headers";
import { NextResponse } from "next/server";
import { parse } from "node-html-parser";
Expand All @@ -16,15 +15,21 @@ const getResultFromSession = async (
): Promise<Result> => {
const url = `https://imaluum.iium.edu.my/MyAcademic/result${sessionQuery}`;
try {
const response = await got(url, {
const response = await fetch(url, {
headers: {
Cookie: cookies().toString(),
},
https: { rejectUnauthorized: false },
followRedirect: false,
// https: { rejectUnauthorized: false },
// followRedirect: false,
});

const root = parse(response.body);
if (!response.ok) {
throw new Error("Failed to fetch schedule");
}

const body = await response.text();

const root = parse(body);

const table = root.querySelector(".box-body table.table.table-hover");
const rows = table?.querySelectorAll("tr");
Expand Down Expand Up @@ -111,15 +116,19 @@ const getResultFromSession = async (

export async function GET() {
try {
const response = await got(IMALUUM_RESULT_PAGE, {
const response = await fetch(IMALUUM_RESULT_PAGE, {
headers: {
Cookie: cookies().toString(),
},
https: { rejectUnauthorized: false },
followRedirect: false,
});

const root = parse(response.body);
if (!response.ok) {
throw new Error("Failed to fetch result");
}

const body = await response.text();

const root = parse(body);
if (!root) throw new Error("Failed to parse the page body");

const sessionBody = root.querySelectorAll(
Expand All @@ -141,10 +150,13 @@ export async function GET() {
if (sessionList.length === 0) {
// must return null, dont throw error
// assuming the student is 1st year 1st sem and havent taken any exams yet
return {
success: true,
data: null,
};
return NextResponse.json(
{
success: true,
data: null,
},
{ status: 200 },
);
}

const results: Result[] = await Promise.all(
Expand Down
23 changes: 13 additions & 10 deletions app/api/schedule/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IMALUUM_SCHEDULE_PAGE } from "@/constants";
import got from "got";
import moment from "moment";
import { cookies } from "next/headers";
import { NextResponse } from "next/server";
Expand Down Expand Up @@ -40,16 +39,16 @@ const getScheduleFromSession = async (

try {
if (cookies().get("MOD_AUTH_CAS")) {
const response = await got(url, {
const response = await fetch(url, {
headers: {
Cookie: cookies().toString(),
},
https: { rejectUnauthorized: false },
followRedirect: false,
});
if (!response.body) throw new Error("Failed to go to page");
if (!response.ok) throw new Error("Failed to go to page");

const root = parse(response.body);
const body = await response.text();

const root = parse(body);
if (!root) throw new Error("Failed to parse the body");

const table = root.querySelector(".box-body table.table.table-hover");
Expand Down Expand Up @@ -271,15 +270,19 @@ const getScheduleFromSession = async (

export async function GET() {
try {
const response = await got(IMALUUM_SCHEDULE_PAGE, {
const response = await fetch(IMALUUM_SCHEDULE_PAGE, {
headers: {
Cookie: cookies().toString(),
},
https: { rejectUnauthorized: false },
followRedirect: false,
});

const root = parse(response.body);
if (!response.ok) {
throw new Error("Failed to fetch schedule");
}

const body = await response.text();

const root = parse(body);

const sessionBody = root.querySelectorAll(
".box.box-primary .box-header.with-border .dropdown ul.dropdown-menu li[style*='font-size:16px']",
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"framer-motion": "^10.17.4",
"got": "^14.0.0",
"leva": "^0.9.35",
"lucide-react": "^0.303.0",
"meshline": "^3.3.1",
Expand Down
Loading

0 comments on commit 7023e80

Please sign in to comment.