mirror of
https://github.com/yude-jp/yude.jp
synced 2024-11-17 02:52:38 +09:00
Add UUID lookup function
Now player's profile page works on IGN query too
This commit is contained in:
parent
979bbe2a7f
commit
9e2f51eb5f
@ -7,8 +7,8 @@ const rewrites = async () => {
|
|||||||
destination: '/minecraft/players/:uuid'
|
destination: '/minecraft/players/:uuid'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
source: '/minecraft/players/:uuid',
|
source: '/minecraft/players/:ign',
|
||||||
destination: '/404'
|
destination: '/minecraft/lookup/:ign'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
57
pages/minecraft/lookup/[ign].js
Normal file
57
pages/minecraft/lookup/[ign].js
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
// Base layout
|
||||||
|
import Layout from "../../components/Layout"
|
||||||
|
|
||||||
|
// React
|
||||||
|
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())
|
||||||
|
|
||||||
|
// Components
|
||||||
|
import WrongUUID from '../../components/Minecraft/WrongUUID'
|
||||||
|
|
||||||
|
export default function UUID() {
|
||||||
|
const router = useRouter()
|
||||||
|
const { ign } = router.query
|
||||||
|
const { data, error } = useSwr(
|
||||||
|
ign ? `https://api.ashcon.app/mojang/v2/user/${ign}` : null,
|
||||||
|
fetcher
|
||||||
|
)
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Layout title="エラー - プレイヤー情報">
|
||||||
|
<p className="text-2xl">エラーが発生しました。</p>
|
||||||
|
</Layout>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
if (!data) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Layout title="読み込み中... - プレイヤー情報">
|
||||||
|
<p className="text-2xl">読み込み中</p>
|
||||||
|
</Layout>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
if (data.code) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Layout title="404 - プレイヤー情報">
|
||||||
|
<WrongUUID />
|
||||||
|
</Layout>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
router.push('/minecraft/players/' + data.uuid)
|
||||||
|
return (
|
||||||
|
<p>リダイレクトしています...</p>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user