mirror of
https://github.com/skidoodle/albert.lol.git
synced 2025-02-15 06:09:15 +01:00
Initial commit
This commit is contained in:
commit
d1b8e8f676
26 changed files with 3283 additions and 0 deletions
14
pages/api/ip.ts
Normal file
14
pages/api/ip.ts
Normal 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
49
pages/api/s3.ts
Normal 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
23
pages/api/spotify.ts
Normal 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,
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue