mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 21:13:50 +00:00
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
import { jsonRes } from '@/service/response';
|
|
import { authToken } from '@/service/utils/auth';
|
|
import { ModelDataStatusEnum } from '@/constants/model';
|
|
import { generateVector } from '@/service/events/generateVector';
|
|
import { PgClient } from '@/service/pg';
|
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
|
|
try {
|
|
const { dataId, a, q } = req.body as { dataId: string; a: string; q?: string };
|
|
const { authorization } = req.headers;
|
|
|
|
if (!authorization) {
|
|
throw new Error('无权操作');
|
|
}
|
|
|
|
if (!dataId) {
|
|
throw new Error('缺少参数');
|
|
}
|
|
|
|
// 凭证校验
|
|
const userId = await authToken(authorization);
|
|
|
|
// 更新 pg 内容
|
|
await PgClient.update('modelData', {
|
|
where: [['id', dataId], 'AND', ['user_id', userId]],
|
|
values: [
|
|
{ key: 'a', value: a },
|
|
...(q
|
|
? [
|
|
{ key: 'q', value: q },
|
|
{ key: 'status', value: ModelDataStatusEnum.waiting }
|
|
]
|
|
: [])
|
|
]
|
|
});
|
|
|
|
q && generateVector();
|
|
|
|
jsonRes(res);
|
|
} catch (err) {
|
|
jsonRes(res, {
|
|
code: 500,
|
|
error: err
|
|
});
|
|
}
|
|
}
|