4.6.4-alpha (#569)
This commit is contained in:
@@ -1,31 +1,74 @@
|
||||
import { authOutLinkLimit } from '@/service/support/outLink/auth';
|
||||
import { AuthLinkChatProps } from '@fastgpt/global/support/outLink/api.d';
|
||||
import { AuthUserTypeEnum } from '@fastgpt/global/support/permission/constant';
|
||||
import { getUserAndAuthBalance } from './user';
|
||||
import { POST } from '@fastgpt/service/common/api/plusRequest';
|
||||
import type {
|
||||
AuthOutLinkChatProps,
|
||||
AuthOutLinkLimitProps,
|
||||
AuthOutLinkInitProps,
|
||||
AuthOutLinkResponse
|
||||
} from '@fastgpt/global/support/outLink/api.d';
|
||||
import { authOutLinkValid } from '@fastgpt/service/support/permission/auth/outLink';
|
||||
import { getUserAndAuthBalance } from '@fastgpt/service/support/user/controller';
|
||||
import { AuthUserTypeEnum } from '@fastgpt/global/support/permission/constant';
|
||||
import { OutLinkErrEnum } from '@fastgpt/global/common/error/code/outLink';
|
||||
import { OutLinkSchema } from '@fastgpt/global/support/outLink/type';
|
||||
|
||||
export async function authOutLinkChat({
|
||||
export function authOutLinkInit(data: AuthOutLinkInitProps): Promise<AuthOutLinkResponse> {
|
||||
if (!global.feConfigs?.isPlus) return Promise.resolve({ uid: data.outLinkUid });
|
||||
return POST<AuthOutLinkResponse>('/support/outLink/authInit', data);
|
||||
}
|
||||
export function authOutLinkChatLimit(data: AuthOutLinkLimitProps): Promise<AuthOutLinkResponse> {
|
||||
if (!global.feConfigs?.isPlus) return Promise.resolve({ uid: data.outLinkUid });
|
||||
return POST<AuthOutLinkResponse>('/support/outLink/authChatStart', data);
|
||||
}
|
||||
|
||||
export const authOutLink = async ({
|
||||
shareId,
|
||||
outLinkUid
|
||||
}: {
|
||||
shareId?: string;
|
||||
outLinkUid?: string;
|
||||
}): Promise<{
|
||||
uid: string;
|
||||
appId: string;
|
||||
shareChat: OutLinkSchema;
|
||||
}> => {
|
||||
if (!outLinkUid) {
|
||||
return Promise.reject(OutLinkErrEnum.linkUnInvalid);
|
||||
}
|
||||
const result = await authOutLinkValid({ shareId });
|
||||
|
||||
const { uid } = await authOutLinkInit({
|
||||
outLinkUid,
|
||||
tokenUrl: result.shareChat.limit?.hookUrl
|
||||
});
|
||||
|
||||
return {
|
||||
...result,
|
||||
uid
|
||||
};
|
||||
};
|
||||
|
||||
export async function authOutLinkChatStart({
|
||||
shareId,
|
||||
ip,
|
||||
authToken,
|
||||
outLinkUid,
|
||||
question
|
||||
}: AuthLinkChatProps & {
|
||||
}: AuthOutLinkChatProps & {
|
||||
shareId: string;
|
||||
}) {
|
||||
// get outLink
|
||||
const { shareChat, app } = await authOutLinkValid({ shareId });
|
||||
// get outLink and app
|
||||
const { shareChat, appId } = await authOutLinkValid({ shareId });
|
||||
|
||||
const [user] = await Promise.all([
|
||||
// check balance and chat limit
|
||||
const [user, { uid }] = await Promise.all([
|
||||
getUserAndAuthBalance({ tmbId: shareChat.tmbId, minBalance: 0 }),
|
||||
global.feConfigs?.isPlus
|
||||
? authOutLinkLimit({ outLink: shareChat, ip, authToken, question })
|
||||
: undefined
|
||||
authOutLinkChatLimit({ outLink: shareChat, ip, outLinkUid, question })
|
||||
]);
|
||||
|
||||
return {
|
||||
authType: AuthUserTypeEnum.token,
|
||||
responseDetail: shareChat.responseDetail,
|
||||
user,
|
||||
app
|
||||
appId,
|
||||
uid
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user