Skip to content

Commit

Permalink
v2.16.5 (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
HACO8888 authored Dec 19, 2024
2 parents 1b1051e + 5d3ba1d commit d5c2027
Showing 8 changed files with 75 additions and 34 deletions.
7 changes: 6 additions & 1 deletion app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import NextAuth from "next-auth";
import axios from "axios";
import GoogleProvider from "next-auth/providers/google";
import { profile } from "console";
import Swal from "sweetalert2";

const emoji: { [key: string]: string } = {
developer: "<:developer:1222933983164235876>",
@@ -17,7 +19,9 @@ const handler = NextAuth({
}),
],
callbacks: {
async signIn({ account }) {
async signIn({ account, profile }) {
if (!profile?.email?.endsWith("@ms.mingdao.edu.tw"))
return "/?error=not_md";
if (account) {
const urlencoded = new URLSearchParams();
urlencoded.append("googleToken", String(account.access_token));
@@ -62,6 +66,7 @@ const handler = NextAuth({
});
}
}

return true;
},
async jwt({ token, account }) {
14 changes: 9 additions & 5 deletions app/api/webhook/login/route.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import axios from "axios";
import { NextRequest, NextResponse } from "next/server";

function isDev(req: NextRequest) {
const urlObj = new URL(req.url);

return urlObj.hostname !== "sig.mingdao.edu.tw";
}

export async function POST(req: NextRequest) {
const data = await req.formData();
const content = {
username: "MDSIG Login",
avatar_url:
"https://sig.mingdao.edu.tw/images/sig2pfp.png",
avatar_url: "https://sig.mingdao.edu.tw/images/sig2pfp.png",
embeds: [
{
title: `${data.get("name")} ${req.url.includes("localhost") ? "(Development)" : ""}${req.url.includes("dev") ? "(Development)" : ""}`,
title: `${data.get("name")} ${isDev(req) ? "(Development)" : ""}`,
description: data.get("description"),
color: parseInt("0x34e718"),
thumbnail: {
@@ -65,8 +70,7 @@ export async function POST(req: NextRequest) {
timestamp: new Date().toISOString(),
footer: {
text: "MDSIG 2.0 Login System",
icon_url:
"https://sig.mingdao.edu.tw/images/sig2pfp.png",
icon_url: "https://sig.mingdao.edu.tw/images/sig2pfp.png",
},
},
],
41 changes: 37 additions & 4 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -9,8 +9,43 @@ import Information from "./(home)/desktop/Information";
import ThreadsListMobile from "./(home)/mobile/ThreadsList";
import useIsMobile from "@/utils/useIsMobile";

const Home = () => {
// Module
import Swal from "sweetalert2";
import { useSearchParams, useRouter } from "next/navigation";
import { useEffect } from "react";

export default function Home() {
const isMobile = useIsMobile();
const router = useRouter();
const searchParams = useSearchParams();
const error = searchParams.get("error");

useEffect(() => {
if (error === "not_md") {
Swal.fire({
title: "Login Fail",
text: "You should use your Mingdao email to login!",
icon: "error",
confirmButtonText: "Sure",
allowEscapeKey: false,
allowOutsideClick: false,
customClass: {
container: "select-none",
},
focusConfirm: false,
background: "#fff url(/images/trees.png)",
backdrop: `
rgba(0,0,123,0.4)
url("/images/nyan-cat.gif")
left top
no-repeat
`,
preConfirm: () => {
router.push("/");
}
});
}
}, [error, router]);

if (isMobile) {
return <ThreadsListMobile />;
@@ -22,6 +57,4 @@ const Home = () => {
</SplitBlock>
);
}
};

export default Home;
}
44 changes: 22 additions & 22 deletions app/ping/route.ts
Original file line number Diff line number Diff line change
@@ -5,38 +5,38 @@ import axios from "axios";
import ReadableTime from "@/modules/api/ReadableTime";
import GetOnlineAppVersion from "@/modules/api/GetOnlineAppVersion";


export async function GET() {
const packageJSON = JSON.parse(readFileSync("./package.json").toString());
const { mainVersion, developmentVersion } = await GetOnlineAppVersion();

const apiResponse = await axios.get(`${process.env.NEXT_PUBLIC_API_URL}/ping`);
const apiResponse = await axios.get(
`${process.env.NEXT_PUBLIC_API_URL}/ping`,
);
const apiData = apiResponse.data;

const data: any = {
"Frontend": {
"status": "Online",
"uptime": ReadableTime(Math.round(performance.now()))["string"],
"currentVersion": packageJSON.version,
"latestVersion": {
"main": mainVersion,
"development": developmentVersion
Frontend: {
status: "Online",
uptime: ReadableTime(Math.round(performance.now()))["string"],
currentVersion: packageJSON.version,
latestVersion: {
main: mainVersion,
development: developmentVersion,
},
"upToDate": {
"main": mainVersion <= packageJSON.version,
"development": developmentVersion <= packageJSON.version
upToDate: {
main: mainVersion >= packageJSON.version,
development: developmentVersion >= packageJSON.version,
},
},
"Backend": {
"status": apiData.service.replace("up", "Online") || "Offline",
"uptime": apiData.uptime || "N/A",
"currentVersion": apiData.version.current || "N/A",
"latestVersion": apiData.version.latest || "N/A",
"upToDate": apiData.version.upToDate || "N/A"
}
},
Backend: {
status: apiData.service.replace("up", "Online") || "Offline",
uptime: apiData.uptime || "N/A",
currentVersion: apiData.version.current || "N/A",
latestVersion: apiData.version.latest || "N/A",
upToDate: apiData.version.upToDate || "N/A",
},
};


return NextResponse.json(data);
}

@@ -45,4 +45,4 @@ export const dynamicParams = false;
export const revalidate = false;
export const fetchCache = "auto";
export const runtime = "nodejs";
export const preferredRegion = "auto";
export const preferredRegion = "auto";
1 change: 0 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/** @type {import('next').NextConfig} */
const path = require("path");
const nextConfig = {
swcMinify: false,
experimental: {
missingSuspenseWithCSRBailout: false,
},
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mdsig-frontend",
"version": "2.16.4",
"version": "2.16.5",
"private": true,
"scripts": {
"dev": "next dev",
Binary file added public/images/nyan-cat.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/trees.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d5c2027

Please sign in to comment.