diff --git a/.eslintrc.json b/.eslintrc.json index d3067d4..21071b2 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -88,5 +88,11 @@ "next": ["const", "let", "var"] } ] - } + }, + "prettier/prettier": [ + "warn", + { + "endOfLine": "auto" + } + ] } diff --git a/.readme/en_Search.jpg b/.readme/en_Search.jpg index ede5d76..6b292cf 100644 Binary files a/.readme/en_Search.jpg and b/.readme/en_Search.jpg differ diff --git a/app/api/detail/route.ts b/app/api/detail/route.ts index 1729bf0..e9e71aa 100644 --- a/app/api/detail/route.ts +++ b/app/api/detail/route.ts @@ -26,7 +26,7 @@ const query = gql` `; // Function to handle GET requests -export async function GET(request: Request) { +const handler = async(request: Request) => { const { searchParams } = new URL(request.url); const hash = searchParams.get("hash"); @@ -34,7 +34,7 @@ export async function GET(request: Request) { if (!hash) { return NextResponse.json( { - message: "hash is required", + message: "`hash` is required", status: 400, }, { @@ -76,3 +76,5 @@ export async function GET(request: Request) { ); } } + +export { handler as GET, handler as POST }; diff --git a/app/api/search/route.ts b/app/api/search/route.ts index 6c0a72b..c72d246 100644 --- a/app/api/search/route.ts +++ b/app/api/search/route.ts @@ -57,7 +57,7 @@ const schema = z.object({ withTotalCount: z.coerce.boolean().default(false), }); -export async function GET(request: Request) { +const handler = async (request: Request) => { // Extract search parameters from the request URL const { searchParams } = new URL(request.url); const params = Object.fromEntries(searchParams.entries()); @@ -92,12 +92,13 @@ export async function GET(request: Request) { variables: { queryInput: safeParams, }, + fetchPolicy: "no-cache", }); return NextResponse.json( { data: data.search, - message: "Success", + message: "success", status: 200, }, { @@ -119,3 +120,5 @@ export async function GET(request: Request) { ); } } + +export { handler as GET, handler as POST }; diff --git a/app/detail/[hash64]/page.tsx b/app/detail/[hash64]/page.tsx index c740652..07b050e 100644 --- a/app/detail/[hash64]/page.tsx +++ b/app/detail/[hash64]/page.tsx @@ -14,7 +14,9 @@ async function fetchData(hash64: string) { notFound(); } - const data = await apiFetch(`/api/detail?hash=${hash}`); // Fetch data from API + const data = await apiFetch(`/api/detail?hash=${hash}`, { + next: { revalidate: 60 * 60 * 24 * 7 }, // cache for 7 days + }); return data; } diff --git a/app/search/page.tsx b/app/search/page.tsx index b87412f..fe66792 100644 --- a/app/search/page.tsx +++ b/app/search/page.tsx @@ -1,5 +1,4 @@ import { Metadata } from "next"; -import { redirect } from "next/navigation"; import { getTranslations } from "next-intl/server"; import { Link } from "@nextui-org/react"; @@ -8,7 +7,6 @@ import SearchResultsList from "@/components/SearchResultsList"; import apiFetch from "@/utils/api"; import { MagnetIcon } from "@/components/icons"; import { siteConfig } from "@/config/site"; -import { Toast } from "@/utils"; import { DEFAULT_SORT_TYPE, SEARCH_PAGE_SIZE, @@ -70,7 +68,9 @@ async function fetchData({ } try { - const resp = await apiFetch(`/api/search?${params.toString()}`); + const resp = await apiFetch(`/api/search?${params.toString()}`, { + next: { revalidate: 60 * 60 * 6 }, // cache for 6 hours + }); if (isNewSearch) { totalCount = resp.data.total_count;