优化图文页

This commit is contained in:
2026-04-28 17:11:42 +08:00
parent 674c202264
commit 040273586b
69 changed files with 3939 additions and 2302 deletions
+44 -44
View File
@@ -1,51 +1,51 @@
export const runtime = 'nodejs'
export const runtime = "nodejs";
import { NextRequest, NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
import { scrapeDouyin, ScrapeError } from '.';
import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
import { scrapeDouyin, ScrapeError } from ".";
async function handleDouyinScrape(req: NextRequest) {
const { searchParams } = new URL(req.url);
const videoUrl = searchParams.get('url');
if (!videoUrl) {
return NextResponse.json(
{ error: '缺少视频URL', code: 'MISSING_URL' },
{ status: 400 }
);
const { searchParams } = new URL(req.url);
const videoUrl = searchParams.get("url");
if (!videoUrl) {
return NextResponse.json(
{ error: "缺少视频URL", code: "MISSING_URL" },
{ status: 400 },
);
}
try {
// 调用爬虫函数
const result = await scrapeDouyin(videoUrl);
return NextResponse.json({
success: true,
data: result,
});
} catch (error) {
// 处理自定义的 ScrapeError
if (error instanceof ScrapeError) {
return NextResponse.json(
{
success: false,
error: error.message,
code: error.code,
},
{ status: error.statusCode },
);
}
try {
// 调用爬虫函数
const result = await scrapeDouyin(videoUrl);
return NextResponse.json({
success: true,
data: result
});
} catch (error) {
// 处理自定义的 ScrapeError
if (error instanceof ScrapeError) {
return NextResponse.json(
{
success: false,
error: error.message,
code: error.code
},
{ status: error.statusCode }
);
}
// 处理未知错误
console.error('未捕获的错误:', error);
return NextResponse.json(
{
success: false,
error: '服务器内部错误',
code: 'INTERNAL_ERROR'
},
{ status: 500 }
);
}
// 处理未知错误
console.error("未捕获的错误:", error);
return NextResponse.json(
{
success: false,
error: "服务器内部错误",
code: "INTERNAL_ERROR",
},
{ status: 500 },
);
}
}
export const GET = handleDouyinScrape
export const GET = handleDouyinScrape;