Files
FastGPT/packages/service/support/outLink/tools.ts
Archer bf14506603 perf: add outlink usage (#4691)
* update doc

* perf: add outlink usage

* feat: jina provider
2025-04-28 10:41:32 +08:00

54 lines
1.2 KiB
TypeScript

import axios from 'axios';
import { MongoOutLink } from './schema';
import { FastGPTProUrl } from '../../common/system/constants';
import { ChatHistoryItemResType } from '@fastgpt/global/core/chat/type';
export const addOutLinkUsage = ({
shareId,
totalPoints
}: {
shareId: string;
totalPoints: number;
}) => {
return MongoOutLink.findOneAndUpdate(
{ shareId },
{
$inc: { usagePoints: totalPoints },
lastTime: new Date()
}
).catch((err) => {
console.log('update shareChat error', err);
});
};
export const pushResult2Remote = async ({
outLinkUid,
shareId,
appName,
flowResponses
}: {
outLinkUid?: string; // raw id, not parse
shareId?: string;
appName: string;
flowResponses?: ChatHistoryItemResType[];
}) => {
if (!shareId || !outLinkUid || !FastGPTProUrl) return;
try {
const outLink = await MongoOutLink.findOne({
shareId
});
if (!outLink?.limit?.hookUrl) return;
axios({
method: 'post',
baseURL: outLink.limit.hookUrl,
url: '/shareAuth/finish',
data: {
token: outLinkUid,
appName,
responseData: flowResponses
}
});
} catch (error) {}
};