mirror of
https://github.com/ngthanhvu/kr-phim.git
synced 2026-08-10 14:27:47 +00:00
feat: implement movie player page with HLS and embedded streaming support, navigation, and watch history tracking
This commit is contained in:
@@ -1,33 +1,18 @@
|
||||
import { getKkphimDetail, getNguoncDetail, getOphimDetail } from '../../utils/movies'
|
||||
import { getMovieDetailGroup, parseSourceRefs } from '../../utils/movies'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const slug = getRouterParam(event, 'slug')
|
||||
const source = getQuery(event).source
|
||||
const query = getQuery(event)
|
||||
const source = query.source
|
||||
|
||||
if (!slug) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'Thiếu slug phim' })
|
||||
}
|
||||
|
||||
const detailBySource = {
|
||||
ophim: getOphimDetail,
|
||||
nguonc: getNguoncDetail,
|
||||
kkphim: getKkphimDetail,
|
||||
}
|
||||
const requestedSource = typeof source === 'string' && ['ophim', 'nguonc', 'kkphim'].includes(source)
|
||||
? source as 'ophim' | 'nguonc' | 'kkphim'
|
||||
: 'ophim'
|
||||
const refs = parseSourceRefs(query.sources || query.srcs, requestedSource, slug)
|
||||
|
||||
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 detailBySource[sourceName](slug)
|
||||
} catch (error) {
|
||||
lastError = error
|
||||
}
|
||||
}
|
||||
|
||||
throw lastError
|
||||
return await getMovieDetailGroup(refs)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user