mirror of
https://github.com/labring/FastGPT.git
synced 2025-08-03 13:38:00 +00:00
feat: kb ui
This commit is contained in:
@@ -5,6 +5,13 @@ import { authUser } from '@/service/utils/auth';
|
||||
import { PgClient } from '@/service/pg';
|
||||
import type { KbDataItemType } from '@/types/plugin';
|
||||
|
||||
export type Response = {
|
||||
id: string;
|
||||
q: string;
|
||||
a: string;
|
||||
source: string;
|
||||
};
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
|
||||
try {
|
||||
let { dataId } = req.query as {
|
||||
|
@@ -18,10 +18,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
||||
|
||||
await connectToDatabase();
|
||||
|
||||
const data = await KB.findOne({
|
||||
_id: id,
|
||||
userId
|
||||
});
|
||||
const data = await KB.findOne(
|
||||
{
|
||||
_id: id,
|
||||
userId
|
||||
},
|
||||
'_id avatar name userId tags'
|
||||
);
|
||||
|
||||
if (!data) {
|
||||
throw new Error('kb is not exist');
|
||||
@@ -33,7 +36,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
||||
avatar: data.avatar,
|
||||
name: data.name,
|
||||
userId: data.userId,
|
||||
updateTime: data.updateTime,
|
||||
tags: data.tags.join(' ')
|
||||
}
|
||||
});
|
||||
|
@@ -2,8 +2,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { jsonRes } from '@/service/response';
|
||||
import { connectToDatabase, KB } from '@/service/mongo';
|
||||
import { authUser } from '@/service/utils/auth';
|
||||
import { PgClient } from '@/service/pg';
|
||||
import { KbItemType } from '@/types/plugin';
|
||||
import { KbListItemType } from '@/types/plugin';
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
|
||||
try {
|
||||
@@ -12,25 +11,23 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
||||
|
||||
await connectToDatabase();
|
||||
|
||||
const kbList = await KB.find({
|
||||
userId
|
||||
}).sort({ updateTime: -1 });
|
||||
const kbList = await KB.find(
|
||||
{
|
||||
userId
|
||||
},
|
||||
'_id avatar name tags'
|
||||
).sort({ updateTime: -1 });
|
||||
|
||||
const data = await Promise.all(
|
||||
kbList.map(async (item) => ({
|
||||
_id: item._id,
|
||||
avatar: item.avatar,
|
||||
name: item.name,
|
||||
userId: item.userId,
|
||||
updateTime: item.updateTime,
|
||||
tags: item.tags.join(' '),
|
||||
totalData: await PgClient.count('modelData', {
|
||||
where: [['user_id', userId], 'AND', ['kb_id', item._id]]
|
||||
})
|
||||
tags: item.tags
|
||||
}))
|
||||
);
|
||||
|
||||
jsonRes<KbItemType[]>(res, {
|
||||
jsonRes<KbListItemType[]>(res, {
|
||||
data
|
||||
});
|
||||
} catch (err) {
|
||||
|
Reference in New Issue
Block a user