修复代码质量问题并更新任务进度
修复内容: - API 采集器添加 30 秒超时控制 (AbortController) - 采集服务优化批量插入,修复 URL 为空时的去重逻辑 - 整理类型定义,将 ProcessedContent 移至 types/index.ts - 添加 ReportStatus 和 ReportGenerationOptions 类型 更新任务进度: - 任务 01-05 标记为已完成 - 任务 06-09 待开发 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d8553c06fa
commit
bb9d691f7a
5 files changed
+64
-61
No files matched your search
@@ -49,37 +49,42 @@ export class CollectorService {
|
||||
throw new Error(result.error || 'Collection failed');
|
||||
}
|
||||
|
||||
// 保存资讯(去重)
|
||||
// 保存资讯(批量去重)
|
||||
const articlesToCreate = [];
|
||||
for (const article of result.articles) {
|
||||
try {
|
||||
// 检查是否已存在(通过 URL 或标题去重)
|
||||
const existing = await prisma.article.findFirst({
|
||||
where: {
|
||||
sourceId: source.id,
|
||||
OR: [
|
||||
{ url: article.url || undefined },
|
||||
{ title: article.title },
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
if (!existing) {
|
||||
await prisma.article.create({
|
||||
data: {
|
||||
sourceId: source.id,
|
||||
title: article.title,
|
||||
content: article.content,
|
||||
url: article.url,
|
||||
publishedAt: article.publishedAt,
|
||||
collectedAt: new Date(),
|
||||
rawData: article.rawData,
|
||||
},
|
||||
});
|
||||
articlesCount++;
|
||||
}
|
||||
} catch (error) {
|
||||
logger.warn('保存资讯失败', { title: article.title, error });
|
||||
// 检查是否已存在(通过 URL 或标题去重)
|
||||
const whereConditions: any[] = [{ title: article.title }];
|
||||
if (article.url) {
|
||||
whereConditions.push({ url: article.url });
|
||||
}
|
||||
|
||||
const existing = await prisma.article.findFirst({
|
||||
where: {
|
||||
sourceId: source.id,
|
||||
OR: whereConditions,
|
||||
},
|
||||
});
|
||||
|
||||
if (!existing) {
|
||||
articlesToCreate.push({
|
||||
sourceId: source.id,
|
||||
title: article.title,
|
||||
content: article.content,
|
||||
url: article.url,
|
||||
publishedAt: article.publishedAt,
|
||||
collectedAt: new Date(),
|
||||
rawData: article.rawData,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 批量插入
|
||||
if (articlesToCreate.length > 0) {
|
||||
await prisma.article.createMany({
|
||||
data: articlesToCreate,
|
||||
skipDuplicates: true,
|
||||
});
|
||||
articlesCount = articlesToCreate.length;
|
||||
}
|
||||
|
||||
// 更新数据源的最后采集时间
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
import { Article } from '@prisma/client';
|
||||
import { LlmClient } from '../utils/llm-client';
|
||||
import { LlmClientConfig } from '../types/llm';
|
||||
import { ProcessMode } from '../types';
|
||||
import { ProcessMode, ProcessedContent } from '../types';
|
||||
import logger from '../utils/logger';
|
||||
|
||||
export interface ProcessedContent {
|
||||
content: string;
|
||||
mode: ProcessMode;
|
||||
articlesCount: number;
|
||||
}
|
||||
|
||||
export class ProcessorService {
|
||||
/**
|
||||
* 处理资讯列表
|
||||
|
||||
Reference in new issue
Block a user