feat: KB 列表返回 coverUrl(coverKey → 预签名下载URL)
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 43s
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 43s
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
28caf1297f
commit
4f59569b7c
@ -2,6 +2,7 @@ import { Injectable, BadRequestException, NotFoundException, ForbiddenException,
|
||||
import { KnowledgeBaseRepository } from './knowledge-base.repository';
|
||||
import { PrismaService } from '../../infrastructure/database/prisma.service';
|
||||
import { ContentSafetyService } from '../content-safety/content-safety.service';
|
||||
import { StorageService } from '../../infrastructure/storage/storage.service';
|
||||
import { MAX_KNOWLEDGE_BASE_COUNT } from './constants/knowledge-base.constants';
|
||||
|
||||
@Injectable()
|
||||
@ -9,6 +10,7 @@ export class KnowledgeBaseService {
|
||||
constructor(
|
||||
private readonly repository: KnowledgeBaseRepository,
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly storage: StorageService,
|
||||
@Optional() private readonly safety?: ContentSafetyService,
|
||||
) {}
|
||||
|
||||
@ -21,11 +23,25 @@ export class KnowledgeBaseService {
|
||||
const check = await this.safety?.check(dto.title, { userId, contentType: 'kb-title' });
|
||||
if (check && !check.safe) throw new ForbiddenException('知识库名称包含违规内容');
|
||||
}
|
||||
return this.repository.create(userId, dto);
|
||||
return this.enrichWithCoverUrl(await this.repository.create(userId, dto));
|
||||
}
|
||||
|
||||
async findAll(userId: string, pagination: { page?: number; limit?: number }) {
|
||||
return this.repository.findAllByUserId(userId, pagination);
|
||||
const kbs = await this.repository.findAllByUserId(userId, pagination);
|
||||
return Promise.all(kbs.map(kb => this.enrichWithCoverUrl(kb)));
|
||||
}
|
||||
|
||||
private async enrichWithCoverUrl(kb: any) {
|
||||
if (kb.coverKey) {
|
||||
try {
|
||||
kb.coverUrl = await this.storage.getDownloadUrl(kb.coverKey, 86400);
|
||||
} catch {
|
||||
kb.coverUrl = null;
|
||||
}
|
||||
} else {
|
||||
kb.coverUrl = null;
|
||||
}
|
||||
return kb;
|
||||
}
|
||||
|
||||
async findOne(userId: string, id: string) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user