MCPcopy Create free account
hub / github.com/chokcoco/iCSS / GET

Function GET

website/app/api/articles/route.ts:4–101  ·  view source on GitHub ↗
(request: NextRequest)

Source from the content-addressed store, hash-verified

2import { GitHubAPI } from '@/app/lib/github';
3
4export async function GET(request: NextRequest) {
5 try {
6 const { searchParams } = new URL(request.url);
7 const page = parseInt(searchParams.get('page') || '1');
8 const perPage = parseInt(searchParams.get('per_page') || '30');
9 const category = searchParams.get('category');
10 const search = searchParams.get('search');
11
12 // 获取所有文章
13 const allArticles = await GitHubAPI.getAllArticles();
14
15 // 确保 allArticles 是数组
16 if (!Array.isArray(allArticles)) {
17 console.error('GitHub API returned non-array data:', allArticles);
18 return NextResponse.json({
19 articles: [],
20 pagination: {
21 page,
22 perPage,
23 total: 0,
24 totalPages: 0,
25 hasNext: false,
26 hasPrev: false
27 },
28 error: '数据格式错误'
29 });
30 }
31
32 // 如果文章列表为空,可能是API限流或网络问题
33 if (allArticles.length === 0) {
34 console.warn('No articles returned from GitHub API, possible rate limiting');
35 return NextResponse.json({
36 articles: [],
37 pagination: {
38 page,
39 perPage,
40 total: 0,
41 totalPages: 0,
42 hasNext: false,
43 hasPrev: false
44 },
45 error: '暂时无法获取文章数据,请稍后再试'
46 });
47 }
48
49 // 应用分类过滤
50 let filteredArticles = allArticles;
51 if (category && category !== '全部') {
52 filteredArticles = allArticles.filter(article =>
53 article.category === category
54 );
55 }
56
57 // 应用搜索过滤
58 if (search) {
59 const searchLower = search.toLowerCase();
60 filteredArticles = filteredArticles.filter(article =>
61 article.title.toLowerCase().includes(searchLower) ||

Callers

nothing calls this directly

Calls 2

getMethod · 0.80
getAllArticlesMethod · 0.80

Tested by

no test coverage detected