Initial commit

This commit is contained in:
skidoodle 2023-02-14 23:10:01 +01:00
commit d1b8e8f676
26 changed files with 3283 additions and 0 deletions

16
pages/_app.tsx Normal file
View file

@ -0,0 +1,16 @@
import { AppProps } from 'next/app';
import { Analytics } from '@vercel/analytics/react';
import Head from 'next/head';
import 'styles/globals.scss';
export default function App({ Component, pageProps }: AppProps) {
return (
<>
<Head>
<title>albert</title>
</Head>
<Component {...pageProps} />
<Analytics />
</>
);
}

25
pages/_document.tsx Normal file
View file

@ -0,0 +1,25 @@
import Document, { Html, Head, Main, NextScript } from 'next/document';
class AppDocument extends Document {
render() {
return (
<Html lang='en'>
<Head>
<link rel='preconnect' href='https://vitals.vercel-insights.com' />
<meta name='title' content='albert' />
<meta name='og:title' content='albert' />
<meta name='description' content='system administrator' />
<meta name='og:description' content='system administrator' />
<meta name='theme-color' content='#000000' />
<meta property='og:image' content='/favicon.ico' />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
export default AppDocument;

14
pages/api/ip.ts Normal file
View file

@ -0,0 +1,14 @@
import { NextApiRequest, NextApiResponse } from 'next';
export default async function ip(req: NextApiRequest, res: NextApiResponse){
let ip = req.headers['x-vercel-forwarded-for'];
let region = req.headers['x-vercel-ip-country-region'];
let country = req.headers['x-vercel-ip-country'];
let city = req.headers['x-vercel-ip-city'];
res.status(200).json({
ip: ip,
city: city,
country: country,
region: region
});
}

49
pages/api/s3.ts Normal file
View file

@ -0,0 +1,49 @@
import { NextApiRequest, NextApiResponse } from 'next';
import aws from 'aws-sdk';
const { BUCKET, ACCESS_KEY, SECRET_KEY, ENDPOINT, REGION } = process.env;
export default async function Storage(req: NextApiRequest, res: NextApiResponse) {
aws.config.s3 = {
accessKeyId: ACCESS_KEY,
secretAccessKey: SECRET_KEY,
region: REGION,
endpoint: ENDPOINT,
signatureVersion: 'v4',
};
let isTruncated: boolean | undefined = true;
let startAfter;
let objects = 0;
let size = 0;
const s3 = new aws.S3();
while (isTruncated) {
let params: any = { Bucket: BUCKET };
if (startAfter) {
params.StartAfter = startAfter;
}
const data = await s3.listObjectsV2(params).promise();
data.Contents?.forEach((object: any) => {
objects++;
size += object.Size! / 1024 / 1024 / 1024;
});
isTruncated = data.IsTruncated;
if (isTruncated) {
startAfter = data.Contents!.slice(-1)[0].Key;
}
}
res.setHeader(
'Cache-Control',
'public, s-maxage=10, stale-while-revalidate=59'
);
res.json({
object: objects,
size: Number(size.toFixed(2))
});
}

23
pages/api/spotify.ts Normal file
View file

@ -0,0 +1,23 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { SpotifyService } from 'spotify-now-playing'
export default async function Spotify(req: NextApiRequest, res: NextApiResponse) {
const { CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN } = process.env;
const spotify = new SpotifyService(CLIENT_ID!, CLIENT_SECRET!, REFRESH_TOKEN!)
const song = await spotify.getCurrentSong()
if(!song || !song.isPlaying ) {
return res.status(200).json({
nowplaying: false,
});
}
res.status(200).json({
nowplaying: true,
song: {
artist: song.artists.name,
title: song.title,
url: song.url,
}
});
}

87
pages/index.tsx Normal file
View file

@ -0,0 +1,87 @@
import Image from 'next/image';
import Link from 'next/link';
import React from 'react';
import useSWR from 'swr';
import FadeIn from 'react-fade-in';
import { socials } from 'components/data/socials';
import { Icon } from 'components/Icon';
import { Toaster } from 'react-hot-toast';
import { FaSpotify } from 'react-icons/fa';
import profilePic from 'public/profile.webp';
export const fetcher = (url: RequestInfo) => fetch(url).then((r) => r.json());
export default function Main() {
var { data: spotify } = useSWR('/api/spotify', fetcher, {
refreshInterval: 3000,
fallbackData: 'loading',
});
return (
<FadeIn>
<div className='px-8 2xl:translate-y-2/3 translate-y-1/3 m-auto max-w-4xl'>
<div className='flex flex-col justify-center items-center'>
<Image
src={profilePic}
alt='Profile Picture'
placeholder='blur'
className='rounded-full text-center'
height={150}
width={150}
/>
<h1 className='text-4xl font-bold mt-1'>
albert
<span className='align-text-top text-xs'>
{Math.floor(
(new Date().getTime() - new Date('2004-07-22').getTime()) /
(1000 * 60 * 60 * 24 * 365.25)
)}
</span>
</h1>
<p className='text-[#9ca3af] text-xl flex flex-wrap items-center justify-center whitespace-pre-wrap'>
Systems Administrator
</p>
</div>
<hr className='border-t-[#727277] w-4/5 md:w-2/5 m-auto mt-5 md:mt-8' />
<div className='mt-3 flex justify-center items-center'>
<FaSpotify className='text-[#32a866]' />
<p className='font-semibold pl-1'>
Listening to{' '}
{spotify.song ? (
<Link
href={`${spotify.song.url}`}
target='_blank'
className='text-[#32a866]'
>
{' '}
{spotify.song.title}
</Link>
) : (
<span className='text-[#32a866]'>nothing</span>
)}
</p>
</div>
<div className='flex justify-between items-center text-3xl mt-11 md:mt-16 max-w-sm m-auto'>
{socials.map((social) => (
<Icon
key={social.id}
reference={social.ref}
copyValue={social.copyValue}
>
{React.createElement(social.icon)}
</Icon>
))}
</div>
</div>
<Toaster />
</FadeIn>
);
}