0
0
mirror of https://github.com/yude-jp/yude.jp synced 2024-12-22 12:10:11 +09:00

Compare commits

...

6 Commits

Author SHA1 Message Date
c856a34867
Add out to .gitignore 2021-12-11 07:15:52 +09:00
d3283b12b2
https://github.com/vercel/next.js/issues/28596 2021-12-11 07:15:37 +09:00
8513ee795f
Cleanup 2021-12-11 06:58:32 +09:00
49bd87b276
Merge branch 'master' of https://github.com/yudejp/yude.jp 2021-12-11 06:47:47 +09:00
a095e20b6b
Remove /api/PlayerName 2021-12-11 06:42:23 +09:00
33dbec3339
bye Fitbit 2021-12-11 06:32:00 +09:00
13 changed files with 8 additions and 254 deletions

View File

@ -1,3 +1,6 @@
{
"extends": "next/core-web-vitals"
"extends": "next/core-web-vitals",
"rules": {
"@next/next/no-document-import-in-page": "off"
}
}

2
.gitignore vendored
View File

@ -11,5 +11,5 @@ yarn-error.log
.vimrc~
..vimrc.un~
.env.local
out
.vercel

View File

@ -1,44 +0,0 @@
// React
import { format } from 'date-fns'
const {
FITBIT_TOKEN: bearer
} = process.env;
const today = format(new Date(), 'yyyy-MM-dd')
export const getName = async (props) => {
const uuid = props;
return fetch(
'https://api.fitbit.com/1/user/-/activities/heart/date/today/1d/1sec/time/00:00/23:59.json',
{
headers: {
Authorization: `Bearer ${bearer}`,
},
}
);
};
const FitbitHeartrate = async (req, res) => {
const { uuid } = req.query
const response = await getName(uuid);
const data = await response.json();
if (response.status === 204 || response.status > 400) {
return res.status(200).send("404");
}
// const heartrate = data.map((item, i) => {
// if (item.dateTime = today) {
// return item
// } else {
// return "Failed to retrieve data."
// }
// }
// )
const array = data["activities-heart-intraday"].dataset
const heartrate = array[array.length - 1]
return res.status(200).json({
heartrate,
});
};
export default FitbitHeartrate

View File

@ -1,35 +0,0 @@
// React
import { format } from 'date-fns'
const {
FITBIT_TOKEN: bearer
} = process.env;
const today = format(new Date(), 'yyyy-MM-dd')
export const getName = async (props) => {
const uuid = props;
return fetch(
'https://api.fitbit.com/1.2/user/-/sleep/date/' + today + '.json',
{
headers: {
Authorization: `Bearer ${bearer}`,
},
}
);
};
const FitbitSleep = async (req, res) => {
const { uuid } = req.query
const response = await getName(uuid);
const data = await response.json();
if (response.status === 204 || response.status > 400) {
return res.status(200).send("404");
}
const duration = data.summary.totalMinutesAsleep
return res.status(200).json({
duration,
});
};
export default FitbitSleep

View File

@ -1,23 +0,0 @@
// React
import React, { useState, useEffect } from 'react';
import axios from 'axios';
export const getName = async (props) => {
const uuid = props;
return fetch('https://api.ashcon.app/mojang/v2/user/' + uuid);
};
const RawPlayerName = async (req, res) => {
const { uuid } = req.query
const response = await getName(uuid);
const data = await response.json();
if (response.status === 204 || response.status > 400) {
return res.status(200).send("404");
}
const username = data.username;
return res.status(200).json({
username,
});
};
export default RawPlayerName

View File

@ -1,60 +0,0 @@
import querystring from 'querystring';
const {
SPOTIFY_CLIENT_ID: client_id,
SPOTIFY_CLIENT_SECRET: client_secret,
SPOTIFY_REFRESH_TOKEN: refresh_token,
} = process.env;
const basic = Buffer.from(`${client_id}:${client_secret}`).toString('base64');
const NOW_PLAYING_ENDPOINT = `https://api.spotify.com/v1/me/player/currently-playing`;
const TOKEN_ENDPOINT = `https://accounts.spotify.com/api/token`;
const getAccessToken = async () => {
const response = await fetch(TOKEN_ENDPOINT, {
method: 'POST',
headers: {
Authorization: `Basic ${basic}`,
'Content-Type': 'application/x-www-form-urlencoded',
},
body: querystring.stringify({
grant_type: 'refresh_token',
refresh_token,
}),
});
return response.json();
};
export const getNowPlaying = async () => {
const { access_token } = await getAccessToken();
return fetch(NOW_PLAYING_ENDPOINT, {
headers: {
Authorization: `Bearer ${access_token}`,
},
});
};
const Spotify = async (_, res) => {
const response = await getNowPlaying();
if (response.status === 204 || response.status > 400) {
return res.status(200).json({ isPlaying: false });
}
const song = await response.json();
const isPlaying = song.is_playing;
const title = song.item.name;
const artist = song.item.artists.map((_artist) => _artist.name).join(', ');
const album = song.item.album.name;
return res.status(200).json({
album,
artist,
isPlaying,
title,
});
};
export default Spotify

View File

@ -1,38 +0,0 @@
// Data fetching
import useSwr from 'swr'
// Font Awesome
import { faHeartbeat } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
// Data fetching implements
const fetcher = (url) => fetch(url).then((res) => res.json())
function App (props) {
const { data, error } = useSwr(
'/api/Fitbit/Heartrate',
fetcher
)
if (error) {
return (
<>エラーが発生しました</>
)
} else {
if (!data) {
return (
<>読み込み中...</>
)
} else {
return (
<>
<FontAwesomeIcon icon={faHeartbeat} className="w-5 h-5 inline ml-3"/>
&nbsp;
{data.heartrate.value}
</>
)
}
}
}
export default App;

View File

@ -1,44 +0,0 @@
// Data fetching
import useSwr from 'swr'
// Font Awesome
import { faBed } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
// Data fetching implements
const fetcher = (url) => fetch(url).then((res) => res.json())
function App (props) {
const { data, error } = useSwr(
'/api/Fitbit/Sleep',
fetcher
)
if (error) {
return (
<>エラーが発生しました</>
)
} else {
if (!data) {
return (
<>読み込み中...</>
)
} else {
const duration = data.duration
const hours = Math.floor(duration / 60)
let minutes = duration % 60
if (minutes <= 9) {
minutes = '0' + minutes
}
return (
<>
<FontAwesomeIcon icon={faBed} className="w-5 h-5 inline"/>
&nbsp;
{hours}:{minutes}
</>
)
}
}
}
export default App;

View File

@ -9,7 +9,7 @@ const fetcher = (url) => fetch(url).then((res) => res.json())
function App (props) {
const uuid = props;
const { data, error } = useSwr(
uuid.uuid ? `/api/PlayerName/${uuid.uuid}` : null,
uuid.uuid ? `https://api.ashcon.app/mojang/v2/user/${uuid.uuid}` : null,
fetcher
)

View File

@ -11,7 +11,7 @@ function App () {
useEffect(() => {
const fetchData = async () => {
const result = await axios(
'/api/Spotify',
'https://vercel-spotify-api.vercel.app/api/Spotify',
);
setData(result.data);
};

View File

@ -5,7 +5,6 @@
import { useRouter } from 'next/router'
// Data fetching
import Players from '../../components/Minecraft/Players'
import useSwr from 'swr'
const fetcher = (url) => fetch(url).then((res) => res.json())

View File

@ -16,7 +16,7 @@ export default function UUID() {
const router = useRouter()
const { uuid } = router.query
const { data, error } = useSwr(
uuid ? `/api/PlayerName/${uuid}` : null,
uuid ? `https://api.ashcon.app/mojang/v2/user/${uuid}` : null,
fetcher
)
if (error) {

View File

@ -25,8 +25,6 @@ import PublicKeys from './components/Profile/PublicKeys'
import Button from './components/Profile/Button'
import Contact from './components/Profile/Contact'
import NintendoSW from "./components/Profile/NintendoSW"
import FitbitSleep from "./components/Fitbit/Sleep"
import FitbitHeartrate from "./components/Fitbit/Heartrate"
// next-seo
import { NextSeo } from 'next-seo';
@ -63,8 +61,6 @@ export default function Profile(props) {
<div>
<DiscordPlaying />
<Spotify />
{/* <FitbitSleep />
<FitbitHeartrate /> */}
</div>
</div>