mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-21 11:43:56 +00:00
54 lines
1.2 KiB
TypeScript
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) {}
|
|
};
|