mirror of
https://github.com/KuekHaoYang/KVideo.git
synced 2026-08-16 17:23:43 +08:00
Refactor code structure for improved readability and maintainability
This commit is contained in:
+8
-42
@@ -61,30 +61,13 @@ export async function GET(request: NextRequest) {
|
||||
);
|
||||
}
|
||||
|
||||
// Fetch video detail with automatic episode validation
|
||||
// Fetch video detail without validation (already validated during search)
|
||||
try {
|
||||
const videoDetail = await getVideoDetail(id, sourceConfig);
|
||||
|
||||
// Validate episodes to filter out broken sources
|
||||
if (videoDetail.episodes && videoDetail.episodes.length > 0) {
|
||||
console.log(`[GET] Validating ${videoDetail.episodes.length} episodes for video ${id}...`);
|
||||
const validatedEpisodes = await filterValidEpisodes(videoDetail.episodes);
|
||||
const workingEpisodes = validatedEpisodes.filter(ep => ep.isValid);
|
||||
|
||||
console.log(`[GET] Found ${workingEpisodes.length} working episodes out of ${videoDetail.episodes.length}`);
|
||||
|
||||
if (workingEpisodes.length === 0) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'No playable episodes found from this source. Please try another source.',
|
||||
},
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
videoDetail.episodes = workingEpisodes;
|
||||
}
|
||||
// Skip validation - videos are already checked during search
|
||||
// Just return the episodes as-is
|
||||
console.log(`[GET] Fetching video details for ${id} from ${sourceConfig.name}`);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
@@ -165,30 +148,13 @@ export async function POST(request: NextRequest) {
|
||||
);
|
||||
}
|
||||
|
||||
// Fetch video detail with automatic episode validation
|
||||
// Fetch video detail without validation (already validated during search)
|
||||
try {
|
||||
const videoDetail = await getVideoDetail(id, sourceConfig);
|
||||
|
||||
// Validate episodes to filter out broken sources
|
||||
if (videoDetail.episodes && videoDetail.episodes.length > 0) {
|
||||
console.log(`[POST] Validating ${videoDetail.episodes.length} episodes for video ${id}...`);
|
||||
const validatedEpisodes = await filterValidEpisodes(videoDetail.episodes);
|
||||
const workingEpisodes = validatedEpisodes.filter(ep => ep.isValid);
|
||||
|
||||
console.log(`[POST] Found ${workingEpisodes.length} working episodes out of ${videoDetail.episodes.length}`);
|
||||
|
||||
if (workingEpisodes.length === 0) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'No playable episodes found from this source. Please try another source.',
|
||||
},
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
videoDetail.episodes = workingEpisodes;
|
||||
}
|
||||
// Skip validation - videos are already checked during search
|
||||
// Just return the episodes as-is
|
||||
console.log(`[POST] Fetching video details for ${id} from ${sourceConfig.name}`);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
|
||||
@@ -102,9 +102,9 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
const availableVideos: any[] = [];
|
||||
let checkedCount = 0;
|
||||
const concurrency = 5; // Smaller batches for faster response
|
||||
const concurrency = 10; // Check 10 videos at a time
|
||||
|
||||
// Process videos in smaller batches for immediate feedback
|
||||
// Process videos in batches for immediate feedback
|
||||
for (let i = 0; i < allVideos.length; i += concurrency) {
|
||||
const batch = allVideos.slice(i, i + concurrency);
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 25 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 598 KiB |
@@ -16,9 +16,6 @@ const geistMono = Geist_Mono({
|
||||
export const metadata: Metadata = {
|
||||
title: "KVideo - 视频聚合平台",
|
||||
description: "Multi-source video aggregation platform with beautiful Liquid Glass UI",
|
||||
icons: {
|
||||
icon: '/favicon.ico',
|
||||
},
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
|
||||
+1
-1
@@ -224,7 +224,7 @@ export default function Home() {
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 relative flex items-center justify-center">
|
||||
<Image
|
||||
src="/favicon.ico"
|
||||
src="/icon.png"
|
||||
alt="KVideo"
|
||||
width={40}
|
||||
height={40}
|
||||
|
||||
+6
-6
@@ -156,11 +156,11 @@ function PlayerContent() {
|
||||
<div className="flex items-center justify-between">
|
||||
<Button
|
||||
variant="secondary"
|
||||
onClick={() => router.push('/')}
|
||||
onClick={() => router.back()}
|
||||
className="flex items-center gap-2"
|
||||
>
|
||||
<Icons.ChevronLeft size={20} />
|
||||
<span>返回首页</span>
|
||||
<span>返回</span>
|
||||
</Button>
|
||||
<ThemeSwitcher />
|
||||
</div>
|
||||
@@ -182,11 +182,11 @@ function PlayerContent() {
|
||||
<div className="flex gap-3 justify-center">
|
||||
<Button
|
||||
variant="primary"
|
||||
onClick={() => router.push('/')}
|
||||
onClick={() => router.back()}
|
||||
className="flex items-center gap-2"
|
||||
>
|
||||
<Icons.ChevronLeft size={20} />
|
||||
<span>返回搜索其他源</span>
|
||||
<span>返回</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
@@ -229,11 +229,11 @@ function PlayerContent() {
|
||||
</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
onClick={() => router.push('/')}
|
||||
onClick={() => router.back()}
|
||||
className="flex items-center gap-2"
|
||||
>
|
||||
<Icons.ChevronLeft size={16} />
|
||||
<span>选择其他源</span>
|
||||
<span>返回</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 598 KiB |
Reference in New Issue
Block a user