mp3 support

This commit is contained in:
skidoodle 2024-05-21 23:27:19 +02:00
parent 64292c2e26
commit bd838c7b3f
8 changed files with 5003 additions and 4022 deletions

View file

@ -1,5 +1,3 @@
import million from 'million/compiler'
const securityHeaders = [ const securityHeaders = [
{ {
key: 'X-DNS-Prefetch-Control', key: 'X-DNS-Prefetch-Control',
@ -49,8 +47,4 @@ const nextConfig = {
swcMinify: true, swcMinify: true,
} }
const millionConfig = { export default nextConfig
auto: true,
}
export default million.next(nextConfig, millionConfig)

View file

@ -11,31 +11,30 @@
"lint": "next lint" "lint": "next lint"
}, },
"dependencies": { "dependencies": {
"@nextui-org/react": "^2.2.9", "@nextui-org/react": "^2.3.6",
"@vercel/analytics": "^1.1.1", "@vercel/analytics": "^1.2.2",
"eslint-config-next": "14.0.4", "eslint-config-next": "14.2.3",
"framer-motion": "^10.16.16", "framer-motion": "^11.2.5",
"million": "^2.6.4", "next": "14.2.3",
"next": "14.0.4", "next-themes": "^0.3.0",
"next-themes": "^0.2.1", "react": "18.3.1",
"react": "18.2.0", "react-dom": "18.3.1",
"react-dom": "18.2.0", "react-icons": "^5.2.1"
"react-icons": "^4.12.0"
}, },
"devDependencies": { "devDependencies": {
"@next/eslint-plugin-next": "^14.0.4", "@next/eslint-plugin-next": "^14.2.3",
"@types/eslint": "^8.44.8", "@types/eslint": "^8.56.10",
"@types/node": "20.10.4", "@types/node": "20.12.12",
"@types/react": "18.2.43", "@types/react": "18.3.2",
"@types/react-dom": "18.2.17", "@types/react-dom": "18.3.0",
"@typescript-eslint/eslint-plugin": "^6.14.0", "@typescript-eslint/eslint-plugin": "^7.10.0",
"@typescript-eslint/parser": "^6.14.0", "@typescript-eslint/parser": "^7.10.0",
"autoprefixer": "10.4.16", "autoprefixer": "10.4.19",
"eslint": "8.55.0", "eslint": "9.3.0",
"postcss": "8.4.32", "postcss": "8.4.38",
"prettier": "^3.1.1", "prettier": "^3.2.5",
"prettier-plugin-tailwindcss": "^0.5.9", "prettier-plugin-tailwindcss": "^0.5.14",
"tailwindcss": "3.3.6", "tailwindcss": "3.4.3",
"typescript": "5.3.3" "typescript": "5.4.5"
} }
} }

8885
pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff

View file

@ -67,3 +67,7 @@ export const PdfButton: React.FC<ButtonProps> = React.memo(
export const ZipButton: React.FC<ButtonProps> = React.memo( export const ZipButton: React.FC<ButtonProps> = React.memo(
({ label, link }) => <CustomButton label={label} link={link} /> ({ label, link }) => <CustomButton label={label} link={link} />
) )
export const Mp3Button: React.FC<ButtonProps> = React.memo(
({ label, link }) => <CustomButton label={label} link={link} />
)

View file

@ -6,6 +6,7 @@ export const useAppState = () => {
const [utPdfLink, setutPdfLink] = useState<string>('') const [utPdfLink, setutPdfLink] = useState<string>('')
const [flZipLink, setflZipLink] = useState<string>('') const [flZipLink, setflZipLink] = useState<string>('')
const [utZipLink, setutZipLink] = useState<string>('') const [utZipLink, setutZipLink] = useState<string>('')
const [flMp3Link, setflMp3Link] = useState<string>('')
const [selectedSubject, setSelectedSubject] = useState<string>('') const [selectedSubject, setSelectedSubject] = useState<string>('')
const [selectedYear, setSelectedYear] = useState<string>('') const [selectedYear, setSelectedYear] = useState<string>('')
const [selectedPeriod, setSelectedPeriod] = useState<string>('') const [selectedPeriod, setSelectedPeriod] = useState<string>('')
@ -23,6 +24,8 @@ export const useAppState = () => {
setflZipLink, setflZipLink,
utZipLink, utZipLink,
setutZipLink, setutZipLink,
flMp3Link,
setflMp3Link,
selectedSubject, selectedSubject,
setSelectedSubject, setSelectedSubject,
selectedYear, selectedYear,

View file

@ -70,7 +70,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
const megoldas = 'meg' const megoldas = 'meg'
const shortev = ev.slice(-2) const shortev = ev.slice(-2)
let flPdfUrl, utPdfUrl, flZipUrl, utZipUrl let flPdfUrl, utPdfUrl, flZipUrl, utZipUrl, flMp3Url
switch (vizsgatargy) { switch (vizsgatargy) {
case 'inf': case 'inf':
case 'infoism': case 'infoism':
@ -80,6 +80,12 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
utZipUrl = `${baseUrl}${prefix}${megoldas}_${shortev}${honap}_${utmutato}.zip` utZipUrl = `${baseUrl}${prefix}${megoldas}_${shortev}${honap}_${utmutato}.zip`
utPdfUrl = `${proxiedUrl}${prefix}_${shortev}${honap}_${utmutato}.pdf` utPdfUrl = `${proxiedUrl}${prefix}_${shortev}${honap}_${utmutato}.pdf`
break break
case 'angol':
case 'nemet':
flPdfUrl = `${proxiedUrl}${prefix}_${shortev}${honap}_${feladat}.pdf`
utPdfUrl = `${proxiedUrl}${prefix}_${shortev}${honap}_${utmutato}.pdf`
flMp3Url = `${baseUrl}${prefix}_${shortev}${honap}_${feladat}.mp3`
break
default: default:
flPdfUrl = `${proxiedUrl}${prefix}_${shortev}${honap}_${feladat}.pdf` flPdfUrl = `${proxiedUrl}${prefix}_${shortev}${honap}_${feladat}.pdf`
utPdfUrl = `${proxiedUrl}${prefix}_${shortev}${honap}_${utmutato}.pdf` utPdfUrl = `${proxiedUrl}${prefix}_${shortev}${honap}_${utmutato}.pdf`
@ -87,7 +93,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
} }
res.setHeader('Cache-Control', 's-maxage=31536000') res.setHeader('Cache-Control', 's-maxage=31536000')
res.status(200).json({ flPdfUrl, utPdfUrl, flZipUrl, utZipUrl }) res.status(200).json({ flPdfUrl, utPdfUrl, flZipUrl, utZipUrl, flMp3Url })
} catch (error) { } catch (error) {
res.status(500).json({ error: 'Internal Server Error', message: error }) res.status(500).json({ error: 'Internal Server Error', message: error })
} }

View file

@ -1,6 +1,6 @@
import React, { useEffect } from 'react' import React, { useEffect } from 'react'
import { ButtonGroup, Divider } from '@nextui-org/react' import { ButtonGroup, Divider } from '@nextui-org/react'
import { PdfButton, ZipButton } from '@/components/Buttons' import { PdfButton, ZipButton, Mp3Button } from '@/components/Buttons'
import { Footer } from '@/components/Footer' import { Footer } from '@/components/Footer'
import { fetchData } from '@/utils/fetch' import { fetchData } from '@/utils/fetch'
import useYears from '@/hooks/useYears' import useYears from '@/hooks/useYears'
@ -23,6 +23,8 @@ export default function Home() {
setflZipLink, setflZipLink,
utZipLink, utZipLink,
setutZipLink, setutZipLink,
flMp3Link,
setflMp3Link,
selectedSubject, selectedSubject,
setSelectedSubject, setSelectedSubject,
selectedYear, selectedYear,
@ -47,7 +49,8 @@ export default function Home() {
setflZipLink, setflZipLink,
setutZipLink, setutZipLink,
setflPdfLink, setflPdfLink,
setutPdfLink setutPdfLink,
setflMp3Link,
) )
} }
}, [selectedLevel, selectedPeriod, selectedSubject, selectedYear]) }, [selectedLevel, selectedPeriod, selectedSubject, selectedYear])
@ -102,6 +105,11 @@ export default function Home() {
</ButtonGroup> </ButtonGroup>
</div> </div>
)} )}
{['angol', 'nemet'].includes(selectedSubject) && (
<div className='space-x-3'>
<Mp3Button label='Hang' link={flMp3Link} />
</div>
)}
</div> </div>
</div> </div>
</div> </div>

View file

@ -6,7 +6,8 @@ export const fetchData = async (
setflZipLink: (link: string) => void, setflZipLink: (link: string) => void,
setutZipLink: (link: string) => void, setutZipLink: (link: string) => void,
setflPdfLink: (link: string) => void, setflPdfLink: (link: string) => void,
setutPdfLink: (link: string) => void setutPdfLink: (link: string) => void,
setflMp3Link: (link: string) => void
) => { ) => {
try { try {
const url = `/api/erettsegi?vizsgatargy=${selectedSubject}&ev=${selectedYear}&idoszak=${selectedPeriod}&szint=${selectedLevel}` const url = `/api/erettsegi?vizsgatargy=${selectedSubject}&ev=${selectedYear}&idoszak=${selectedPeriod}&szint=${selectedLevel}`
@ -19,6 +20,7 @@ export const fetchData = async (
utZipUrl: string utZipUrl: string
flPdfUrl: string flPdfUrl: string
utPdfUrl: string utPdfUrl: string
flMp3Url: string
} }
if (data.utZipUrl && data.flZipUrl) { if (data.utZipUrl && data.flZipUrl) {
@ -30,6 +32,10 @@ export const fetchData = async (
setflPdfLink(data.flPdfUrl) setflPdfLink(data.flPdfUrl)
setutPdfLink(data.utPdfUrl) setutPdfLink(data.utPdfUrl)
} }
if (data.flMp3Url) {
setflMp3Link(data.flMp3Url)
}
} else { } else {
console.error('Hiba történt az API hívás során.') console.error('Hiba történt az API hívás során.')
} }