route.ts
基本信息
- 类型: API 路由
- 路径:
./src/app/api/prompts/route.ts - 路由:
/api/prompts
概述
Prompt 列表和创建接口。支持获取公开 Prompt 列表(支持分页、筛选、搜索)以及创建新的 Prompt。
HTTP 方法
- GET: 获取 Prompt 列表
- POST: 创建新 Prompt
GET - 获取 Prompt 列表
Query 参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| page | number | 否 | 页码,默认 1 |
| perPage | number | 否 | 每页数量,默认 24 |
| type | string | 否 | 按类型筛选 (TEXT, IMAGE, VIDEO, AUDIO, SKILL) |
| category | string | 否 | 按分类 ID 筛选 |
| tag | string | 否 | 按标签 slug 筛选,支持多个(逗号分隔) |
| sort | string | 否 | 排序方式: newest, oldest, upvotes |
| q | string | 否 | 搜索关键词 |
响应
成功 (200)
{
"prompts": [
{
"id": "prompt_id",
"title": "Prompt 标题",
"slug": "prompt-title",
"description": "描述",
"content": "Prompt 内容",
"type": "TEXT",
"mediaUrl": null,
"author": { ... },
"category": { ... },
"tags": [ ... ],
"voteCount": 10,
"contributorCount": 2,
"_count": { ... },
"userExamples": [ ... ]
}
],
"total": 100,
"page": 1,
"perPage": 24,
"totalPages": 5
}
错误 (500)
{
"error": "server_error",
"message": "Something went wrong"
}
POST - 创建新 Prompt
Body 参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| title | string | 是 | 标题,1-200 字符 |
| description | string | 否 | 描述,最多 500 字符 |
| content | string | 是 | Prompt 内容 |
| type | enum | 是 | 类型: TEXT, IMAGE, VIDEO, AUDIO, SKILL |
| structuredFormat | enum | 否 | 结构化格式: JSON, YAML |
| categoryId | string | 否 | 分类 ID |
| tagIds | string[] | 是 | 标签 ID 数组 |
| contributorIds | string[] | 否 | 贡献者用户 ID 数组 |
| isPrivate | boolean | 是 | 是否私有 |
| mediaUrl | string | 否 | 媒体 URL |
| requiresMediaUpload | boolean | 否 | 是否需要媒体上传 |
| requiredMediaType | enum | 否 | 所需媒体类型: IMAGE, VIDEO, DOCUMENT |
| requiredMediaCount | number | 否 | 所需媒体数量 (1-10) |
| bestWithModels | string[] | 否 | 最佳使用模型(最多3个) |
| bestWithMCP | object[] | 否 | MCP 配置 |
| workflowLink | string | 否 | 工作流链接 |
响应
成功 (200)
返回创建的完整 Prompt 对象
错误
未授权 (401)
{
"error": "unauthorized",
"message": "You must be logged in"
}
验证失败 (400)
{
"error": "validation_error",
"message": "Invalid input",
"details": [...]
}
重复内容 (409)
{
"error": "duplicate_prompt",
"message": "You already have a prompt with the same title or content",
"existingPromptId": "...",
"existingPromptSlug": "..."
}
相似内容 (409)
{
"error": "content_exists",
"message": "A prompt with similar content already exists",
"existingPromptId": "...",
"existingPromptSlug": "..."
}
频率限制 (429)
{
"error": "rate_limit",
"message": "Please wait 30 seconds before creating another prompt"
}
每日限制 (429) - 仅标记用户
{
"error": "daily_limit",
"message": "You have reached the daily limit of 5 prompts"
}
依赖
next/server- Next.js 服务器组件next/cache- 缓存重新验证zod- 输入验证@/lib/auth- 认证@/lib/db- Prisma 数据库客户端@/lib/webhook- Webhook 触发@/lib/ai/embeddings- AI 嵌入生成@/lib/slug- Slug 生成@/lib/ai/quality-check- 质量检查@/lib/similarity- 内容相似度检测
权限
- GET: 公开访问(仅返回公开、未删除、未隐藏的 Prompt)
- POST: 需要登录