mirror of
https://github.com/yude-jp/yude.jp
synced 2024-12-22 12:10:11 +09:00
Compare commits
6 Commits
6eb140fc0a
...
c856a34867
Author | SHA1 | Date | |
---|---|---|---|
c856a34867 | |||
d3283b12b2 | |||
8513ee795f | |||
49bd87b276 | |||
a095e20b6b | |||
33dbec3339 |
@ -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
2
.gitignore
vendored
@ -11,5 +11,5 @@ yarn-error.log
|
||||
.vimrc~
|
||||
..vimrc.un~
|
||||
.env.local
|
||||
|
||||
out
|
||||
.vercel
|
||||
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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"/>
|
||||
|
||||
{data.heartrate.value}
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default App;
|
@ -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"/>
|
||||
|
||||
{hours}:{minutes}
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default App;
|
@ -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
|
||||
)
|
||||
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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())
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user