-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eef44ec
commit c1fb03e
Showing
8 changed files
with
168 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { NextResponse } from "next/server"; | ||
import { gql } from "@apollo/client"; | ||
|
||
import client from "@/lib/apolloClient"; | ||
|
||
// Define the GraphQL query to fetch torrent details by hash | ||
const query = gql` | ||
query StatsInfo { | ||
statsInfo { | ||
size | ||
total_count | ||
updated_at | ||
latest_torrent_hash | ||
latest_torrent { | ||
hash | ||
name | ||
size | ||
created_at | ||
updated_at | ||
} | ||
} | ||
} | ||
`; | ||
|
||
// Function to handle GET requests | ||
const handler = async () => { | ||
try { | ||
// Execute the GraphQL query with the provided hash variable | ||
const { data } = await client.query({ query, fetchPolicy: "no-cache" }); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 5000)); | ||
|
||
// Return a 200 response with the query data | ||
return NextResponse.json( | ||
{ | ||
data: data.statsInfo, | ||
message: "success", | ||
status: 200, | ||
}, | ||
{ | ||
status: 200, | ||
}, | ||
); | ||
} catch (error: any) { | ||
console.error(error); | ||
|
||
// Return a 500 response if there's an error during the query execution | ||
return NextResponse.json( | ||
{ | ||
message: error?.message || "Internal Server Error", | ||
status: 500, | ||
}, | ||
{ | ||
status: 500, | ||
}, | ||
); | ||
} | ||
}; | ||
|
||
export { handler as GET, handler as POST }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Suspense } from "react"; | ||
import { getTranslations } from "next-intl/server"; | ||
import { Tooltip } from "@nextui-org/react"; | ||
|
||
import apiFetch from "@/utils/api"; | ||
import { InfoFilledIcon } from "@/components/icons"; | ||
import { formatByteSize, formatDate } from "@/utils"; | ||
|
||
async function StatsCard() { | ||
const t = await getTranslations(); | ||
|
||
const { data } = await apiFetch("/api/stats", { | ||
next: { revalidate: 60 }, | ||
}); | ||
|
||
return ( | ||
<div className="text-xs text-foreground-600"> | ||
<h4 className="font-bold">{t("Stats.title")}</h4> | ||
<ul> | ||
<li>{t("Stats.size", { size: formatByteSize(data.size) })}</li> | ||
<li> | ||
{t("Stats.total_count", { | ||
total_count: data.total_count.toLocaleString(), | ||
})} | ||
</li> | ||
<li> | ||
{t("Stats.updated_at", { | ||
updated_at: formatDate( | ||
data.updated_at, | ||
t("COMMON.DATE_FORMAT_DATE"), | ||
), | ||
})} | ||
</li> | ||
</ul> | ||
</div> | ||
); | ||
} | ||
|
||
export function Stats() { | ||
return ( | ||
<Tooltip | ||
classNames={{ | ||
content: "bg-opacity-60", | ||
}} | ||
closeDelay={0} | ||
content={ | ||
<Suspense fallback={<div>Loading...</div>}> | ||
<StatsCard /> | ||
</Suspense> | ||
} | ||
delay={0} | ||
radius="sm" | ||
> | ||
<InfoFilledIcon className="cursor-pointer text-stone-500" size={15} /> | ||
</Tooltip> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters