cleanup and cache the paste response 5 mins
All checks were successful
Deploy App / docker (ubuntu-latest) (push) Successful in 1m13s
Publish Docker Image / docker (ubuntu-latest) (push) Successful in 51s

This commit is contained in:
Lee 2024-04-23 16:37:33 +01:00
parent 29c483aeb1
commit 4cfc368f96
4 changed files with 16 additions and 16 deletions

View File

@ -26,7 +26,7 @@ type Paste = {
export async function generateMetadata({
params: { id },
}: PasteProps): Promise<Metadata> {
const data = await getData(id);
const data: Paste | undefined = await getData(id);
if (data == undefined) {
return {
description: "Not found",
@ -40,7 +40,14 @@ export async function generateMetadata({
}
async function getData(id: string): Promise<Paste | undefined> {
const response = await fetch(`${process.env.NEXT_PUBLIC_API_ENDPOINT}/${id}`);
const response: Response = await fetch(
`${process.env.NEXT_PUBLIC_API_ENDPOINT}/${id}`,
{
next: {
revalidate: 300, // Keep this response cached for 5 minutes
},
},
);
const json = await response.json();
if (json.code && json.message) {
@ -52,7 +59,7 @@ async function getData(id: string): Promise<Paste | undefined> {
export default async function Paste({
params: { id },
}: PasteProps): Promise<ReactElement> {
const data = await getData(id);
const data: Paste | undefined = await getData(id);
if (data == undefined) {
return notFound();

View File

@ -16,6 +16,7 @@ export default function Home(): ReactElement {
return;
}
// Upload the paste to the server
const response = await fetch(
`${process.env.NEXT_PUBLIC_API_ENDPOINT}/upload`,
{
@ -27,6 +28,7 @@ export default function Home(): ReactElement {
},
);
// Redirect to the new paste
const data = await response.json();
window.location.href = `/${data.id}`;
}

View File

@ -1,9 +0,0 @@
/**
* Capitalizes the first letter of a string
*
* @param str the string to change
* @returns the updated string
*/
export function capitalizeFirstLetter(str: string) {
return str.charAt(0).toUpperCase() + str.slice(1);
}

View File

@ -1,18 +1,18 @@
import "./globals.css";
import type { Metadata } from "next";
import { ThemeProvider } from "@/app/components/theme-provider";
import "./globals.css";
import { ReactNode } from "react";
import { jetbrainsMono } from "@/app/common/font/font";
export const metadata: Metadata = {
title: "Paste",
description: "Simple Pastebin",
description: "A simple Pastebin service",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
children: ReactNode;
}>) {
return (
<html lang="en">