init. moved lil website for madeline into fuse project so I can write apis in here

This commit is contained in:
2024-09-09 22:39:25 -05:00
commit 28f44c35c6
23 changed files with 4867 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
'use server';
import { NextResponse } from 'next/server';
import { getCountdown } from '~/server/functions';
export const GET = async (request: Request) => {
try {
const url = new URL(request.url);
const apiKey = url.searchParams.get('apiKey');
if (apiKey !== process.env.API_KEY) {
console.log('Invalid API Key');
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
} else {
const countdown = await getCountdown();
return NextResponse.json(countdown);
}
} catch (error) {
console.error(error);
return NextResponse.json({ message: "Error" }, { status: 500 });
}
};
// localhost:3000/api/getCountdown?apiKey=I_Love_Madeline

22
src/app/api/getMessage/route.ts Executable file
View File

@@ -0,0 +1,22 @@
'use server';
import { NextResponse } from 'next/server';
import { getMessage } from '~/server/functions';
export const GET = async (request: Request) => {
try {
const url = new URL(request.url);
const apiKey = url.searchParams.get('apiKey');
if (apiKey !== process.env.API_KEY) {
console.log('Invalid API Key');
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
} else {
const userId = url.searchParams.get('userId') ?? '2';
const message = await getMessage(parseInt(userId));
return NextResponse.json(message);
}
} catch (error) {
console.error(error);
return NextResponse.json({ message: "Error" }, { status: 500 });
}
};
// localhost:3000/api/getMessage?apiKey=I_Love_Madeline&userId=2

View File

@@ -0,0 +1,23 @@
"use server";
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { setCountdown } from "~/server/functions";
export const POST = async (request: NextRequest) => {
try {
const url = new URL(request.url);
const apiKey = url.searchParams.get("apiKey");
if (apiKey !== process.env.API_KEY) {
console.log("Invalid API Key");
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
} else {
const countdown = url.searchParams.get("countdown") ?? "2023-01-01T00:00:00.000Z";
await setCountdown(new Date(countdown));
return NextResponse.json({ message: "Countdown set successfully" });
}
} catch (error) {
console.error(error);
return NextResponse.json({ message: "Error" }, { status: 500 });
}
};
// localhost:3000/api/setCountdown?apiKey=I_Love_Madeline&countdown=2023-01-01T00:00:00.000Z

24
src/app/api/setMessage/route.ts Executable file
View File

@@ -0,0 +1,24 @@
"use server";
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { setMessage } from "~/server/functions";
export const POST = async (request: NextRequest) => {
try {
const url = new URL(request.url);
const apiKey = url.searchParams.get("apiKey");
if (apiKey !== process.env.API_KEY) {
console.log("Invalid API Key");
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
} else {
const userId = url.searchParams.get("userId") ?? "2";
const message = url.searchParams.get("message") ?? "Test";
await setMessage(parseInt(userId), message);
return NextResponse.json({ message: "Message set successfully" });
}
} catch (error) {
console.error(error);
return NextResponse.json({ message: "Error" }, { status: 500 });
}
};
// localhost:3000/api/setMessage?apiKey=I_Love_Madeline&userId=2&message=HelloWorld

20
src/app/layout.tsx Executable file
View File

@@ -0,0 +1,20 @@
import "~/styles/globals.css";
import { GeistSans } from "geist/font/sans";
import { type Metadata } from "next";
export const metadata: Metadata = {
title: "Is Madeline the Cutest?",
description: "Answering the easiest question in the world!",
icons: [{ rel: "icon", url: "/favicon.png" }],
};
export default function RootLayout({
children,
}: Readonly<{ children: React.ReactNode }>) {
return (
<html lang="en" className={`${GeistSans.variable}`}>
<body>{children}</body>
</html>
);
}

35
src/app/page.tsx Executable file
View File

@@ -0,0 +1,35 @@
"use client";
import { useState, useEffect } from "react";
const interestingYes = () => {
const yesArray = [
"Absolutely, yes.",
"Without a doubt.",
"Of course.",
"Definitely.",
"Obviously!",
"Certainly!",
"Positively.",
"100%",
];
return yesArray[Math.floor(Math.random() * yesArray.length)];
}
export default function HomePage() {
const [currentText, setCurrentText] = useState("");
useEffect(() => {
setCurrentText(interestingYes() ?? "Absolutely, yes.");
}, []);
const handleClick = () => {
setCurrentText(interestingYes() ?? "Absolutely, yes.");
};
return (
<main className="flex min-h-screen flex-col items-center justify-center
bg-gradient-to-b from-pink-500 to-orange-400 text-white cursor-pointer">
<h3 className="text-5xl font-extrabold tracking-tight
text-white sm:text-[5rem] text-center" onClick={handleClick}>
{currentText}
</h3>
</main>
);
}