Skip to content

Commit a86fa78

Browse files
made shit faster
1 parent 9d2d687 commit a86fa78

File tree

13 files changed

+29
-100
lines changed

13 files changed

+29
-100
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"cloudinary": "^2.2.0",
2727
"clsx": "^2.1.1",
2828
"cmdk": "1.0.0",
29-
"cryptr": "^6.3.0",
3029
"debounce": "^2.1.1",
3130
"file-saver": "^2.0.5",
3231
"geist": "^1.3.0",
@@ -51,7 +50,6 @@
5150
"react-dom": "^18.3.0",
5251
"react-dropzone": "^14.2.3",
5352
"react-hot-toast": "^2.4.1",
54-
"react-icons": "^5.3.0",
5553
"tailwind-merge": "^2.5.3",
5654
"tailwindcss-animate": "^1.0.7",
5755
"use-debounce": "^10.0.3",

pnpm-lock.yaml

Lines changed: 0 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/api/auth/login/route.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import { connectToDatabase } from "@/lib/mongoose";
22
import bcrypt from "bcrypt";
3-
import Cryptr from "cryptr";
43
import User, { type IUser } from "@/db/user";
54
import { generateToken } from "@/lib/auth";
65
import { NextResponse } from "next/server";
76
import { type LoginRequest } from "@/interface";
87

9-
const cryptr = new Cryptr(process.env.CRYPTO_SECRET || "default_crypto_secret");
10-
118
export async function POST(req: Request) {
12-
console.log(process.env.CRYPTO_SECRET);
139
await connectToDatabase();
1410

1511
const body = (await req.json()) as LoginRequest;
@@ -29,12 +25,10 @@ export async function POST(req: Request) {
2925

3026
console.log("User logged in:", token);
3127

32-
const encryptedResponse = cryptr.encrypt(JSON.stringify({
28+
return NextResponse.json({
3329
token,
3430
user: { id: user._id, email: user.email },
35-
}));
36-
37-
return NextResponse.json({res: encryptedResponse}, { status: 200 });
31+
}, { status: 200 });
3832
} catch (error) {
3933
console.error("Error logging in:", error);
4034
return NextResponse.json({ message: "Failed to login", error }, { status: 500 });

src/app/api/papers/route.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
import { NextResponse, NextRequest } from "next/server";
22
import { connectToDatabase } from "@/lib/mongoose";
33
import Paper from "@/db/papers";
4-
import Cryptr from "cryptr";
54
import { type IPaper } from "@/interface";
65

7-
8-
const cryptr = new Cryptr(process.env.CRYPTO_SECRET ?? "default_crypto_secret");
9-
106
export const dynamic = "force-dynamic";
117

128
export async function GET(req: NextRequest) {
139
try {
1410
await connectToDatabase();
1511
const url = req.nextUrl.searchParams;
1612
const subject = url.get("subject");
17-
console.log("Subject:", subject);
1813
const escapeRegExp = (text: string) => {
1914
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2015
};
@@ -38,21 +33,20 @@ export async function GET(req: NextRequest) {
3833
{ status: 404 },
3934
);
4035
}
41-
36+
4237
const uniqueYears = Array.from(new Set(papers.map((paper) => paper.year)));
4338
const uniqueSlots = Array.from(new Set(papers.map((paper) => paper.slot)));
4439
const uniqueExams = Array.from(new Set(papers.map((paper) => paper.exam)));
4540

46-
const encryptedResponse = cryptr.encrypt(
47-
JSON.stringify({ papers, uniqueYears, uniqueSlots, uniqueExams }),
41+
return NextResponse.json(
42+
{ papers, uniqueYears, uniqueSlots, uniqueExams },
43+
{ status: 200 }
4844
);
49-
50-
return NextResponse.json({ res: encryptedResponse }, { status: 200 });
5145
} catch (error) {
5246
console.error("Error fetching papers by subject:", error);
5347
return NextResponse.json(
5448
{ message: "Failed to fetch papers", error },
55-
{ status: 500 },
49+
{ status: 500 }
5650
);
5751
}
5852
}

src/app/api/search/route.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { NextResponse } from "next/server";
22
import { connectToDatabase } from "@/lib/mongoose";
33
import Paper from "@/db/papers";
4-
import Cryptr from "cryptr";
5-
6-
const cryptr = new Cryptr(process.env.CRYPTO_SECRET ?? "default_crypto_secret");
74

85
export const dynamic = "force-dynamic";
96

@@ -16,7 +13,7 @@ export async function GET(req: Request) {
1613
if (!searchText) {
1714
return NextResponse.json(
1815
{ message: "Text query parameter is required" },
19-
{ status: 400 },
16+
{ status: 400 }
2017
);
2118
}
2219

@@ -29,18 +26,16 @@ export async function GET(req: Request) {
2926
if (subjects.length === 0) {
3027
return NextResponse.json(
3128
{ message: "No subjects found for the specified text" },
32-
{ status: 404 },
29+
{ status: 404 }
3330
);
3431
}
3532

36-
const encryptedResponse = cryptr.encrypt(JSON.stringify({ subjects }));
37-
38-
return NextResponse.json({ res: encryptedResponse }, { status: 200 });
33+
return NextResponse.json({ subjects }, { status: 200 });
3934
} catch (error) {
4035
console.error("Error fetching subjects:", error);
4136
return NextResponse.json(
4237
{ message: "Failed to fetch subjects", error },
43-
{ status: 500 },
38+
{ status: 500 }
4439
);
4540
}
4641
}

src/app/catalogue/page.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import CatalogueContent from "@/components/CatalogueContent";
44
import { Suspense } from "react";
55
import Navbar from "@/components/Navbar";
6-
import { RiLoader2Fill } from "react-icons/ri";
76
import Loader from "@/components/ui/loader";
87
const Catalogue = () => {
98
return (

src/app/papersadminlogin/page.tsx

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,43 @@ import { useRouter } from "next/navigation";
55
import {
66
type LoginResponse,
77
type ErrorResponse,
8-
type DecryptedLoginResponse,
98
} from "@/interface";
10-
import Cryptr from "cryptr";
119
import { handleAPIError } from "@/util/error";
12-
import { totalmem } from "os";
1310
import toast from "react-hot-toast";
1411
import { ApiError } from "next/dist/server/api-utils";
15-
const cryptr = new Cryptr(
16-
process.env.NEXT_PUBLIC_CRYPTO_SECRET ?? "default_crypto_secret",
17-
);
1812

1913
const LoginPage = () => {
2014
const router = useRouter();
2115
const [email, setEmail] = useState("");
2216
const [password, setPassword] = useState("");
2317
const [error, setError] = useState<string | null>(null);
18+
2419
async function apiLogin() {
2520
try {
2621
const response = await axios.post<LoginResponse>("/api/auth/login", {
2722
email,
2823
password,
2924
});
3025

31-
const { res } = response.data;
32-
const decryptedToken = cryptr.decrypt(res);
33-
try {
34-
const message = JSON.parse(decryptedToken) as DecryptedLoginResponse;
35-
const token = message.token;
36-
localStorage.setItem("token", token);
37-
return response.data;
38-
// router.push("/adminupload");
39-
} catch (error) {
40-
toast.error(`Failed to parse decrypted token${error}`);
41-
}
26+
const { token } = response.data;
27+
localStorage.setItem("token", token);
28+
return response.data;
4229
} catch (error) {
4330
throw handleAPIError(error);
4431
}
4532
}
33+
4634
const handleLogin = async () => {
4735
try {
4836
const response = await toast.promise(
4937
apiLogin(),
50-
5138
{
5239
loading: "Logging you in...",
5340
success: "Logged in!",
5441
error: (err: ApiError) => err.message,
5542
},
5643
);
57-
if (response && "res" in response) {
44+
if (response) {
5845
setTimeout(() => {
5946
router.push("/adminupload");
6047
}, 1500);

src/components/Card.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
import { capsule } from "@/util/utils";
1010
import axios from "axios";
1111
import { useRouter } from "next/navigation";
12-
import Link from "next/link";
1312

1413
const Card = ({
1514
paper,

src/components/CatalogueContent.tsx

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
import { useSearchParams } from "next/navigation";
22
import { useEffect, useState } from "react";
33
import axios, { type AxiosError } from "axios";
4-
import Cryptr from "cryptr";
54
import { Button } from "@/components/ui/button";
65
import { type Paper, type Filters } from "@/interface";
76
import { FilterDialog } from "@/components/FilterDialog";
87
import Card from "./Card";
98
import { extractBracketContent } from "@/util/utils";
109
import { useRouter } from "next/navigation";
1110
import SearchBar from "./searchbar";
12-
import { RiLoader2Fill } from "react-icons/ri";
1311
import Loader from "./ui/loader";
1412

15-
const cryptr = new Cryptr(
16-
process.env.NEXT_PUBLIC_CRYPTO_SECRET ?? "default_crypto_secret",
17-
);
18-
1913
const CatalogueContent = () => {
2014
const searchParams = useSearchParams();
2115
const router = useRouter();
@@ -121,14 +115,9 @@ const CatalogueContent = () => {
121115
const papersResponse = await axios.get("/api/papers", {
122116
params: { subject },
123117
});
124-
const { res: encryptedPapersResponse } = papersResponse.data;
125-
const decryptedPapersResponse = cryptr.decrypt(
126-
encryptedPapersResponse,
127-
);
128-
const papersData: Paper[] = JSON.parse(
129-
decryptedPapersResponse,
130-
).papers;
131-
const filters: Filters = JSON.parse(decryptedPapersResponse);
118+
const papersData: Paper[] = papersResponse.data.papers;
119+
const filters: Filters = papersResponse.data;
120+
132121
setFilterOptions(filters);
133122

134123
const papersDataWithFilters = papersData.filter((paper) => {
@@ -189,8 +178,7 @@ const CatalogueContent = () => {
189178

190179
{error && <p className="text-red-500">{error}</p>}
191180
{loading ? (
192-
<Loader />
193-
181+
<Loader />
194182
) : papers.length > 0 ? (
195183
<>
196184
<div className="mb-4 flex justify-center gap-2 md:justify-end 2xl:mr-4">

src/components/searchbar.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@
33
import { useState, useCallback } from "react";
44
import axios, { AxiosError } from "axios";
55
import { Search } from "lucide-react";
6-
import Cryptr from "cryptr";
76
import debounce from 'debounce';
87
import { useRouter } from "next/navigation";
9-
import { Input } from "@/components/ui/input"
10-
11-
const cryptr = new Cryptr(
12-
process.env.NEXT_PUBLIC_CRYPTO_SECRET ?? "default_crypto_secret"
13-
);
8+
import { Input } from "@/components/ui/input";
149

1510
function SearchBar () {
1611
const router = useRouter();
@@ -28,9 +23,7 @@ function SearchBar () {
2823
params: { text },
2924
});
3025

31-
const { res: encryptedSearchResponse } = searchResponse.data;
32-
const decryptedSearchResponse = cryptr.decrypt(encryptedSearchResponse);
33-
const { subjects } = JSON.parse(decryptedSearchResponse);
26+
const { subjects } = searchResponse.data;
3427
const suggestionList = subjects.map((subjectObj: { subject: string }) => subjectObj.subject);
3528
setSuggestions(suggestionList);
3629
setError(null);
@@ -45,7 +38,7 @@ function SearchBar () {
4538
setSuggestions([]);
4639
}
4740
}, 500),
48-
[cryptr]
41+
[]
4942
);
5043

5144
const handleSearchChange = (e: React.ChangeEvent<HTMLInputElement>) => {

0 commit comments

Comments
 (0)