Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,88 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts
# General
.jarvis
Thumbs.db
*.log
*.tmp
*.swp
*.swo
.idea/
.vscode/

# Python
__pycache__/
*.py[cod]
*$py.class
.Python
env/
venv/
.venv/
build/
dist/
develop-eggs/
downloads/
eggs/
.eggs/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
.mypy_cache/
.pytest_cache/
.ruff_cache/
.tox/
.coverage
.coverage.*
htmlcov/
.hypothesis/
.ipynb_checkpoints
.pyre/
.pytype/

# Rust
target/

# Node
node_modules/
pnpm-debug.log*
lerna-debug.log*
dist/
coverage/
.turbo/
.next/
.nuxt/
out/

# Go
vendor/
coverage.out

# Java
target/
*.class
.gradle/
build/
out/

# C/C++
build/
cmake-build-*/
*.o
*.a
*.so
*.obj
*.dll
*.dylib
*.exe
*.pdb

# .NET
obj/
45 changes: 45 additions & 0 deletions src/app/api/search/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { NextRequest, NextResponse } from "next/server";
import { searchStories } from "@/lib/db";

export async function GET(req: NextRequest) {
try {
const { searchParams } = new URL(req.url);
const query = searchParams.get("q");
const page = parseInt(searchParams.get("page") || "1", 10);
const limit = parseInt(searchParams.get("limit") || "20", 10);

if (!query || query.trim().length === 0) {
return NextResponse.json({
error: "查询参数不能为空",
results: [],
total: 0,
totalPages: 0,
currentPage: 1,
});
}

const result = await searchStories(query.trim(), page, limit);

return NextResponse.json({
success: true,
query: query.trim(),
results: result.stories,
total: result.total,
totalPages: result.totalPages,
currentPage: page,
});
} catch (error) {
console.error("搜索API错误:", error);
return NextResponse.json(
{
error: "Internal Server Error",
message: String(error),
results: [],
total: 0,
totalPages: 0,
currentPage: 1,
},
{ status: 500 },
);
}
}
Loading