feat(API-AI-082): add POST /sources/:id/parse trigger endpoint
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 46s
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 46s
Allows users to manually retry source parsing by creating a new DocumentImport job and enqueuing it. Returns jobId for polling. Route: POST /knowledge-bases/:kbId/sources/:id/parse Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
939adcebd3
commit
0867b4f39a
@ -32,6 +32,15 @@ export class KnowledgeSourceController {
|
|||||||
return this.service.findOne(id);
|
return this.service.findOne(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post(':id/parse')
|
||||||
|
@ApiOperation({ summary: '手动触发资料解析' })
|
||||||
|
async triggerParse(
|
||||||
|
@CurrentUser() user: UserPayload,
|
||||||
|
@Param('id') id: string,
|
||||||
|
) {
|
||||||
|
return this.service.triggerParse(id, user.id);
|
||||||
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
@ApiOperation({ summary: '删除资料来源' })
|
@ApiOperation({ summary: '删除资料来源' })
|
||||||
async remove(@CurrentUser() user: UserPayload, @Param('id') id: string) {
|
async remove(@CurrentUser() user: UserPayload, @Param('id') id: string) {
|
||||||
|
|||||||
@ -68,6 +68,37 @@ export class KnowledgeSourceService {
|
|||||||
return this.repository.softDelete(id);
|
return this.repository.softDelete(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async triggerParse(sourceId: string, userId: string) {
|
||||||
|
const source = await this.repository.findById(sourceId);
|
||||||
|
if (!source) throw new NotFoundException('资料来源不存在');
|
||||||
|
|
||||||
|
// 创建新的 import 任务
|
||||||
|
const importJob = await this.importRepo.create({
|
||||||
|
userId,
|
||||||
|
knowledgeBaseId: source.knowledgeBaseId,
|
||||||
|
sourceId: source.id,
|
||||||
|
sourceType: source.type ?? 'file',
|
||||||
|
sourceName: source.originalFilename ?? source.title ?? '',
|
||||||
|
status: 'QUEUED',
|
||||||
|
});
|
||||||
|
|
||||||
|
// 设置 Redis 状态
|
||||||
|
await this.redis.set(`job:document-import:${importJob.id}:status`, 'pending', 86400);
|
||||||
|
await this.redis.set(`job:document-import:${importJob.id}:progress`, '0', 86400);
|
||||||
|
await this.redis.set(`job:document-import:${importJob.id}:message`, '手动触发重新解析', 86400);
|
||||||
|
|
||||||
|
// 入队
|
||||||
|
await this.queue.add('document-import', {
|
||||||
|
importId: importJob.id,
|
||||||
|
userId,
|
||||||
|
knowledgeBaseId: source.knowledgeBaseId,
|
||||||
|
sourceId: source.id,
|
||||||
|
fileName: source.originalFilename ?? source.title,
|
||||||
|
});
|
||||||
|
|
||||||
|
return { jobId: importJob.id, status: 'queued' };
|
||||||
|
}
|
||||||
|
|
||||||
async updateParseStatus(id: string, parseStatus: string, data?: any) {
|
async updateParseStatus(id: string, parseStatus: string, data?: any) {
|
||||||
return this.repository.updateParseStatus(id, parseStatus, data);
|
return this.repository.updateParseStatus(id, parseStatus, data);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user