实现 Web API 路由
- 添加 LLM 配置 API (llm-configs.ts) - 添加数据源管理 API (sources.ts) - 添加推送渠道管理 API (channels.ts) - 添加主题管理 API (topics.ts) - 添加报告查询 API (reports.ts) - 添加资讯浏览 API (articles.ts) - 添加采集日志 API (collection-logs.ts) - 更新 app.ts 注册所有路由和调度器 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
881bbb64a3
commit
51eb7d4292
8 files changed
+741
No files matched your search
@@ -0,0 +1,55 @@
|
||||
import { FastifyInstance } from 'fastify';
|
||||
import prisma from '../../config/database';
|
||||
import { successResponse, paginatedResponse } from '../../utils/response';
|
||||
|
||||
export async function collectionLogRoutes(app: FastifyInstance): Promise<void> {
|
||||
// 获取采集日志列表
|
||||
app.get('/', async (request, reply) => {
|
||||
const { page = 1, limit = 20, sourceId, status } = request.query as any;
|
||||
|
||||
const where: any = {};
|
||||
if (sourceId) where.sourceId = parseInt(sourceId);
|
||||
if (status) where.status = status;
|
||||
|
||||
const [items, total] = await Promise.all([
|
||||
prisma.collectionLog.findMany({
|
||||
where,
|
||||
include: { source: true },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
skip: (Number(page) - 1) * Number(limit),
|
||||
take: Number(limit),
|
||||
}),
|
||||
prisma.collectionLog.count({ where }),
|
||||
]);
|
||||
|
||||
paginatedResponse(reply, items, total, Number(page), Number(limit));
|
||||
});
|
||||
|
||||
// 获取数据源统计
|
||||
app.get('/stats', async (request, reply) => {
|
||||
const sources = await prisma.source.findMany({
|
||||
include: {
|
||||
collectionLogs: {
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 1,
|
||||
},
|
||||
_count: {
|
||||
select: { articles: true, collectionLogs: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const stats = sources.map((source) => ({
|
||||
id: source.id,
|
||||
name: source.name,
|
||||
type: source.type,
|
||||
enabled: source.enabled,
|
||||
lastCollectedAt: source.lastCollectedAt,
|
||||
lastLog: source.collectionLogs[0] || null,
|
||||
totalArticles: source._count.articles,
|
||||
totalCollections: source._count.collectionLogs,
|
||||
}));
|
||||
|
||||
successResponse(reply, stats);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user