mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-29 01:40:51 +00:00
v4.6 -1 (#459)
This commit is contained in:
8
projects/app/src/service/support/permission/auth/bill.ts
Normal file
8
projects/app/src/service/support/permission/auth/bill.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { GET } from '@fastgpt/service/common/api/plusRequest';
|
||||
|
||||
export const authTeamBalance = async (teamId: string) => {
|
||||
if (global.systemEnv.pluginBaseUrl) {
|
||||
return GET('/support/permission/authBalance', { teamId });
|
||||
}
|
||||
return true;
|
||||
};
|
36
projects/app/src/service/support/permission/auth/dataset.ts
Normal file
36
projects/app/src/service/support/permission/auth/dataset.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { getDatasetPgData } from '@/service/core/dataset/data/controller';
|
||||
import { PgDataItemType } from '@fastgpt/global/core/dataset/type';
|
||||
import { AuthResponseType } from '@fastgpt/global/support/permission/type';
|
||||
import { authDatasetCollection } from '@fastgpt/service/support/permission/auth/dataset';
|
||||
import { parseHeaderCert } from '@fastgpt/service/support/permission/controller';
|
||||
import { AuthModeType } from '@fastgpt/service/support/permission/type';
|
||||
|
||||
export async function authDatasetData({
|
||||
dataId,
|
||||
...props
|
||||
}: AuthModeType & {
|
||||
dataId: string;
|
||||
}): Promise<
|
||||
AuthResponseType & {
|
||||
datasetData: PgDataItemType;
|
||||
}
|
||||
> {
|
||||
const result = await parseHeaderCert(props);
|
||||
const { tmbId } = result;
|
||||
// get pg data
|
||||
const datasetData = await getDatasetPgData({ id: dataId });
|
||||
|
||||
const isOwner = String(datasetData.tmbId) === tmbId;
|
||||
// data has the same permissions as collection
|
||||
const { canWrite } = await authDatasetCollection({
|
||||
...props,
|
||||
collectionId: datasetData.collectionId
|
||||
});
|
||||
|
||||
return {
|
||||
...result,
|
||||
datasetData,
|
||||
isOwner,
|
||||
canWrite
|
||||
};
|
||||
}
|
31
projects/app/src/service/support/permission/auth/outLink.ts
Normal file
31
projects/app/src/service/support/permission/auth/outLink.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
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 { authOutLinkValid } from '@fastgpt/service/support/permission/auth/outLink';
|
||||
|
||||
export async function authOutLinkChat({
|
||||
shareId,
|
||||
ip,
|
||||
authToken,
|
||||
question
|
||||
}: AuthLinkChatProps & {
|
||||
shareId: string;
|
||||
}) {
|
||||
// get outLink
|
||||
const { shareChat, app } = await authOutLinkValid({ shareId });
|
||||
|
||||
const [user] = await Promise.all([
|
||||
getUserAndAuthBalance({ tmbId: shareChat.tmbId, minBalance: 0 }),
|
||||
global.feConfigs?.isPlus
|
||||
? authOutLinkLimit({ outLink: shareChat, ip, authToken, question })
|
||||
: undefined
|
||||
]);
|
||||
|
||||
return {
|
||||
authType: AuthUserTypeEnum.token,
|
||||
responseDetail: shareChat.responseDetail,
|
||||
user,
|
||||
app
|
||||
};
|
||||
}
|
48
projects/app/src/service/support/permission/auth/user.ts
Normal file
48
projects/app/src/service/support/permission/auth/user.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { AuthResponseType } from '@fastgpt/global/support/permission/type';
|
||||
import { parseHeaderCert } from '@fastgpt/service/support/permission/controller';
|
||||
import { AuthModeType } from '@fastgpt/service/support/permission/type';
|
||||
import { UserErrEnum } from '@fastgpt/global/common/error/code/user';
|
||||
import { UserType } from '@fastgpt/global/support/user/type';
|
||||
import { getUserDetail } from '@/service/support/user/controller';
|
||||
|
||||
export async function getUserAndAuthBalance({
|
||||
tmbId,
|
||||
minBalance
|
||||
}: {
|
||||
tmbId: string;
|
||||
minBalance?: number;
|
||||
}) {
|
||||
const user = await getUserDetail({ tmbId });
|
||||
|
||||
if (!user) {
|
||||
return Promise.reject(UserErrEnum.unAuthUser);
|
||||
}
|
||||
if (minBalance !== undefined && global.feConfigs.isPlus && user.team.balance < minBalance) {
|
||||
return Promise.reject(UserErrEnum.balanceNotEnough);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
/* get user */
|
||||
export async function authUser({
|
||||
minBalance,
|
||||
...props
|
||||
}: AuthModeType & {
|
||||
minBalance?: number;
|
||||
}): Promise<
|
||||
AuthResponseType & {
|
||||
user: UserType;
|
||||
}
|
||||
> {
|
||||
const { userId, teamId, tmbId } = await parseHeaderCert(props);
|
||||
|
||||
return {
|
||||
userId,
|
||||
teamId,
|
||||
tmbId,
|
||||
user: await getUserAndAuthBalance({ tmbId, minBalance }),
|
||||
isOwner: true,
|
||||
canWrite: true
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user