Refactor code structure for improved readability and maintainability

This commit is contained in:
kuekhaoyang
2025-11-16 19:14:12 +08:00
parent d0790d1307
commit d97a8b7aec
8 changed files with 17 additions and 54 deletions
+8 -42
View File
@@ -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,
+2 -2
View File
@@ -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);
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 598 KiB

-3
View File
@@ -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
View File
@@ -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
View File
@@ -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>
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 598 KiB