feat: implement admin interface for managing custom movie sources and servers with new API endpoint and database schema updates

This commit is contained in:
ngthanhvu
2026-07-28 03:29:55 -04:00
parent 5ee45151ba
commit 72bc657d86
19 changed files with 1423 additions and 229 deletions
+28
View File
@@ -32,6 +32,34 @@ export default defineEventHandler(async (event) => {
: null
}
if ('actors' in body) {
updates.actors = Array.isArray(body.actors) && body.actors.length
? body.actors.filter((a: any) => a.name?.trim()).map((a: any) => ({
name: a.name.trim(),
originalName: a.originalName?.trim() || undefined,
role: a.role?.trim() || undefined,
avatar: a.avatar?.trim() || undefined,
}))
: null
}
if ('customServers' in body) {
updates.customServers = Array.isArray(body.customServers) && body.customServers.length
? body.customServers
.filter((server: any) => server.name?.trim())
.map((server: any) => ({
name: server.name.trim(),
episodes: Array.isArray(server.episodes)
? server.episodes.filter((ep: any) => ep.name?.trim()).map((ep: any) => ({
name: ep.name.trim(),
linkEmbed: ep.linkEmbed?.trim() || null,
linkM3u8: ep.linkM3u8?.trim() || null,
}))
: [],
}))
: null
}
if (!Object.keys(updates).length) {
throw createError({ statusCode: 400, message: 'Không có dữ liệu cập nhật' })
}
@@ -0,0 +1,59 @@
import { movies } from '../../../../database/schema'
import { eq } from 'drizzle-orm'
import { getOphimDetail, getNguoncDetail, getKkphimDetail, type NormalizedServer, type NormalizedActor } from '../../../../utils/movies'
const detailFetchers = {
ophim: getOphimDetail,
nguonc: getNguoncDetail,
kkphim: getKkphimDetail,
}
export default defineEventHandler(async (event) => {
const db = useDb()
const id = Number(getRouterParam(event, 'id'))
if (!id) {
throw createError({ statusCode: 400, message: 'Thiếu ID phim' })
}
const result = await db.select().from(movies).where(eq(movies.id, id)).limit(1)
if (!result.length) {
throw createError({ statusCode: 404, message: 'Không tìm thấy phim' })
}
const movie = result[0]
const sourceRefs = (movie.sources || []).filter((ref: any) => ref.source && ref.slug)
if (!sourceRefs.length) {
return { movie, sources: [] }
}
const results = await Promise.allSettled(
sourceRefs.map((ref: any) => detailFetchers[ref.source as keyof typeof detailFetchers](ref.slug)),
)
const sourceServers: { source: string, slug: string, name: string, content: string, actors: NormalizedActor[], servers: NormalizedServer[] }[] = []
results.forEach((result, index) => {
const ref = sourceRefs[index]
if (result.status === 'fulfilled') {
sourceServers.push({
source: ref.source,
slug: ref.slug,
name: ref.name || result.value.name,
content: result.value.content || '',
actors: result.value.actors || [],
servers: (result.value.servers || []).map((server: NormalizedServer) => ({
...server,
source: ref.source,
sourceSlug: ref.slug,
})),
})
}
})
return {
movie,
sources: sourceServers,
}
})