diff --git a/src/app/game/berry-dash/icon-marketplace/page.tsx b/src/app/game/berry-dash/icon-marketplace/page.tsx index a4c91a2..51f6e1b 100644 --- a/src/app/game/berry-dash/icon-marketplace/page.tsx +++ b/src/app/game/berry-dash/icon-marketplace/page.tsx @@ -4,6 +4,7 @@ import { useEffect, useState } from 'react' import axios from 'axios' import { BackButton } from '@/app/components/BackButton' import { ReloadButton } from '@/app/components/ReloadButton' +import { UploadButton } from '@/app/components/UploadButton' interface MarketplaceIcon { username: string @@ -36,13 +37,14 @@ export default function BerryDashIconMarketplace () { return (
+ { setResponse(null) Refresh() }} /> -

Berry Dash Icon Marketplace

+

Berry Dash Icon Marketplace

A browser for the in game icon marketplace!

{response == null || response == -1 ? ( diff --git a/src/app/game/berry-dash/icon-marketplace/upload/page.tsx b/src/app/game/berry-dash/icon-marketplace/upload/page.tsx new file mode 100644 index 0000000..7686a4b --- /dev/null +++ b/src/app/game/berry-dash/icon-marketplace/upload/page.tsx @@ -0,0 +1,158 @@ +'use client' + +import { BackButton } from '@/app/components/BackButton' +import { ReloadButton } from '@/app/components/ReloadButton' +import { getCookie } from '@/util/cookie' +import { Turnstile } from '@marsidev/react-turnstile' +import axios from 'axios' +import { useRouter } from 'next/navigation' +import { useEffect, useState } from 'react' + +export default function BerryDashSubmitIcon () { + const [token, setToken] = useState(null) + const [result, setResult] = useState(-1) + const [loading, setLoading] = useState(true) + const router = useRouter() + + useEffect(() => { + document.title = 'Lncvrt Games - Berry Dash Icon Submition' + + const token = getCookie('accountToken', '-1') + if (token === '-1') { + router.push( + '/account/login?redirect=/game/berry-dash/icon-marketplace/upload' + ) + } else setLoading(false) + }, []) + + return ( +
+ + window.location.reload()} /> +

+ {loading + ? 'Loading...' + : result == -1 + ? 'Verify you are human to submit a icon' + : 'Berry Dash Icon Submission'} +

+ {!loading && ( + <> + {result == -1 ? ( + { + setToken(token) + setResult(0) + }} + onError={() => setResult(1)} + className='flex justify-center' + /> + ) : result == 0 ? ( +
{ + e.preventDefault() + + const form = e.currentTarget + const formData = new FormData(form) + const text = formData.get('name') as string + const price = formData.get('price') as string + const file = formData.get('bird') as File + + if (!file) { + alert('Please select a bird image!') + return + } + + if (file.type !== 'image/png') { + alert('Please select a PNG file!') + return + } + + const reader = new FileReader() + reader.onload = async () => { + const base64Data = (reader.result as string).split(',')[1] + + try { + const result = await axios.post( + '/api/berrydash/icon-marketplace/upload', + { + token, + fileContent: base64Data, + name: text, + price: Number(price) + }, + { + headers: { + authorization: getCookie('accountToken', '-1') + } + } + ) + + if (result.data.success) { + setResult(2) + } else { + alert( + 'Failed to submit icon, error: ' + + (result.data.message || 'n/a') + ) + } + } catch (err: any) { + if (err.response) { + alert( + 'Failed to submit icon, error: ' + + (err.response.data?.message || + JSON.stringify(err.response.data)) + ) + } else if (err.request) { + alert('Failed to submit icon, no response from server.') + } else { + alert('Failed to submit icon, error: ' + err.message) + } + } + } + reader.readAsDataURL(file) + }} + > + + + + +
+ ) : ( + (result == 1 || result == 2) && ( +

+ {result == 1 + ? 'Unable to verify captcha, please reload page.' + : 'Successfully submitted icon! It will be reviewed soon. Refresh to add more icon, there is no limit after all!'} +

+ ) + )} + + )} +
+ ) +}