mirror of
https://github.com/ngthanhvu/kr-phim.git
synced 2026-08-10 16:07:47 +00:00
feat: implement movie detail page with multi-source support, library features, and responsive layout
This commit is contained in:
@@ -4,6 +4,9 @@ export default defineEventHandler(async (event) => {
|
||||
const query = getQuery(event)
|
||||
const page = Math.max(Number(query.page || 1), 1)
|
||||
const keyword = typeof query.keyword === 'string' ? query.keyword.trim() : ''
|
||||
const source = typeof query.source === 'string' && ['ophim', 'nguonc', 'kkphim'].includes(query.source)
|
||||
? query.source as 'ophim' | 'nguonc' | 'kkphim'
|
||||
: 'all'
|
||||
|
||||
return await getKoreanMovies(page, keyword)
|
||||
return await getKoreanMovies(page, keyword, source)
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getNguoncDetail, getOphimDetail } from '../../utils/movies'
|
||||
import { getKkphimDetail, getNguoncDetail, getOphimDetail } from '../../utils/movies'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const slug = getRouterParam(event, 'slug')
|
||||
@@ -8,21 +8,26 @@ export default defineEventHandler(async (event) => {
|
||||
throw createError({ statusCode: 400, statusMessage: 'Thiếu slug phim' })
|
||||
}
|
||||
|
||||
if (source === 'nguonc') {
|
||||
const detailBySource = {
|
||||
ophim: getOphimDetail,
|
||||
nguonc: getNguoncDetail,
|
||||
kkphim: getKkphimDetail,
|
||||
}
|
||||
|
||||
const requestedSource = typeof source === 'string' && source in detailBySource ? source as keyof typeof detailBySource : 'ophim'
|
||||
const orderedSources = [
|
||||
requestedSource,
|
||||
...Object.keys(detailBySource).filter((item) => item !== requestedSource) as Array<keyof typeof detailBySource>,
|
||||
]
|
||||
let lastError: unknown
|
||||
|
||||
for (const sourceName of orderedSources) {
|
||||
try {
|
||||
return await getNguoncDetail(slug)
|
||||
} catch {
|
||||
return await getOphimDetail(slug)
|
||||
return await detailBySource[sourceName](slug)
|
||||
} catch (error) {
|
||||
lastError = error
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return await getOphimDetail(slug)
|
||||
} catch (error) {
|
||||
try {
|
||||
return await getNguoncDetail(slug)
|
||||
} catch {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
throw lastError
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user