From b270f66b2af7b10a93fdda10f663c932c0f62a17 Mon Sep 17 00:00:00 2001 From: ImJustChew Date: Tue, 20 Aug 2024 21:38:54 +0800 Subject: [PATCH] feat: added course selection system --- src/app/[lang]/(mods-pages)/apps/page.tsx | 4 +- .../[lang]/ais-redirect/[...path]/page.tsx | 40 +++++++++++++++---- src/app/api/scrape-enrollment-status/route.ts | 11 ----- src/components/Today/TodaySchedule.tsx | 2 +- src/const/apps.ts | 15 +++++++ 5 files changed, 51 insertions(+), 21 deletions(-) diff --git a/src/app/[lang]/(mods-pages)/apps/page.tsx b/src/app/[lang]/(mods-pages)/apps/page.tsx index f2b0bbc0..9d936670 100644 --- a/src/app/[lang]/(mods-pages)/apps/page.tsx +++ b/src/app/[lang]/(mods-pages)/apps/page.tsx @@ -31,11 +31,11 @@ const AppList = ({ params: { lang } }: LangProps) => { className="flex flex-row flex-1 items-center space-x-2" target={app.target} > -
+
-

+

{lang == "zh" ? app.title_zh : app.title_en}

diff --git a/src/app/[lang]/ais-redirect/[...path]/page.tsx b/src/app/[lang]/ais-redirect/[...path]/page.tsx index 19a4d459..6bf1114b 100644 --- a/src/app/[lang]/ais-redirect/[...path]/page.tsx +++ b/src/app/[lang]/ais-redirect/[...path]/page.tsx @@ -3,7 +3,7 @@ import { useSettings } from "@/hooks/contexts/settings"; import { useEffect, useState } from "react"; import { AISLoading } from "@/components/Pages/AISLoading"; import { AISError } from "@/components/Pages/AISError"; -import { useParams } from "next/navigation"; +import { useParams, useSearchParams } from "next/navigation"; import { useHeadlessAIS } from "@/hooks/contexts/useHeadlessAIS"; import { AISNotLoggedIn } from "@/components/Pages/AISNotLoggedIn"; @@ -28,13 +28,13 @@ import { AISNotLoggedIn } from "@/components/Pages/AISNotLoggedIn"; const RedirectPage = ({}) => { const params = useParams(); + const searchParams = useSearchParams(); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const { getACIXSTORE, ais } = useHeadlessAIS(); const path = params.path instanceof Array ? params.path : [params.path]; - const redirect_url = `https://www.ccxp.nthu.edu.tw/ccxp/INQUIRE/${path.join("/")}?ACIXSTORE=`; useEffect(() => { (async () => { const token = await getACIXSTORE(); @@ -44,14 +44,40 @@ const RedirectPage = ({}) => { return; } - //redirect user - const link = document.createElement("a"); - link.href = redirect_url + token; - link.click(); + //handle custom url (but strictly for ccxp) + if (path[0] === "custom") { + const url = searchParams.get("url"); + if (!url) { + setLoading(false); + setError("Invalid URL"); + return; + } + + // check if the url is a valid ccxp url, prevent phishing for ACIXSTORE + if (!url.startsWith("https://www.ccxp.nthu.edu.tw")) { + setLoading(false); + setError("Invalid URL"); + return; + } + + // Redirect user + const redirect_url = url + `?ACIXSTORE=${token}`; + console.log(redirect_url); + const link = document.createElement("a"); + link.href = redirect_url; + link.click(); + setLoading(false); + } else { + //redirect user + const redirect_url = `https://www.ccxp.nthu.edu.tw/ccxp/INQUIRE/${path.join("/")}?ACIXSTORE=`; + const link = document.createElement("a"); + link.href = redirect_url + token; + link.click(); + } setLoading(false); })(); - }, [getACIXSTORE, redirect_url]); + }, [getACIXSTORE, searchParams, path]); if (!ais.enabled) return ; if (loading) return ; diff --git a/src/app/api/scrape-enrollment-status/route.ts b/src/app/api/scrape-enrollment-status/route.ts index cd915a23..ded33c2c 100644 --- a/src/app/api/scrape-enrollment-status/route.ts +++ b/src/app/api/scrape-enrollment-status/route.ts @@ -8,17 +8,6 @@ import supabase from "@/config/supabase"; import supabase_server from "@/config/supabase_server"; export const GET = async (request: NextRequest, _try = 0) => { - const authHeader = request.headers.get("authorization"); - - if ( - process.env.NODE_ENV == "production" && - authHeader !== `Bearer ${process.env.CRON_SECRET}` - ) { - return new Response("Unauthorized", { - status: 401, - }); - } - const user = await signInToCCXP( process.env.DONER_STUDENTID!, process.env.DONER_PASSWORD!, diff --git a/src/components/Today/TodaySchedule.tsx b/src/components/Today/TodaySchedule.tsx index c7307ee0..2d192d14 100644 --- a/src/components/Today/TodaySchedule.tsx +++ b/src/components/Today/TodaySchedule.tsx @@ -139,7 +139,7 @@ const TodaySchedule: FC<{ {applist.map((app, index) => (
-
+
diff --git a/src/const/apps.ts b/src/const/apps.ts index c3826c2d..4a5409a1 100644 --- a/src/const/apps.ts +++ b/src/const/apps.ts @@ -11,6 +11,8 @@ import { WalletCards, Gamepad, Paperclip, + TicketCheck, + CalendarCheck2, } from "lucide-react"; export const apps = [ @@ -50,6 +52,19 @@ export const apps = [ Icon: Clipboard, ais: true, }, + { + id: "coursereg", + title_zh: "選課系統", + title_en: "Course Selection System", + href: + "/ais-redirect/custom?url=" + + encodeURIComponent( + "https://www.ccxp.nthu.edu.tw/ccxp/COURSE/JH/7/7.1/7.1.3/JH713001.php", + ), + Icon: CalendarCheck2, + target: "_blank", + ais: true, + }, { id: "eform", title_zh: "電子表單系統",