This commit is contained in:
Archer
2023-11-09 09:46:57 +08:00
committed by GitHub
parent 661ee79943
commit 8bb5588305
402 changed files with 9899 additions and 5967 deletions

View File

@@ -0,0 +1,14 @@
import { GET, POST, PUT } from '@/web/common/api/request';
import type { PromotionRecordType } from '@/global/support/api/userRes.d';
import type { RequestPaging } from '@/types';
/* get promotion init data */
export const getPromotionInitData = () =>
GET<{
invitedAmount: number;
earningsAmount: number;
}>('/plusApi/support/activity/promotion/getPromotionData');
/* promotion records */
export const getPromotionRecords = (data: RequestPaging) =>
POST<PromotionRecordType>(`/plusApi/support/activity/promotion/getPromotions`, data);

View File

@@ -1,26 +1,26 @@
import { GET, POST, DELETE } from '@/web/common/api/request';
import type { EditApiKeyProps, GetApiKeyProps } from '@/global/support/api/openapiReq.d';
import { GET, POST, DELETE, PUT } from '@/web/common/api/request';
import type { EditApiKeyProps, GetApiKeyProps } from '@/global/support/openapi/api.d';
import type { OpenApiSchema } from '@fastgpt/global/support/openapi/type';
/**
* crete a api key
*/
export const createAOpenApiKey = (data: EditApiKeyProps) =>
POST<string>('/support/openapi/postKey', data);
POST<string>('/support/openapi/create', data);
/**
* update a api key
*/
export const putOpenApiKey = (data: EditApiKeyProps & { _id: string }) =>
POST<string>('/support/openapi/putKey', data);
PUT<string>('/support/openapi/update', data);
/**
* get api keys
*/
export const getOpenApiKeys = (params?: GetApiKeyProps) =>
GET<OpenApiSchema[]>('/support/openapi/getKeys', params);
GET<OpenApiSchema[]>('/support/openapi/list', params);
/**
* delete api by id
*/
export const delOpenApiById = (id: string) => DELETE(`/support/openapi/delKey?id=${id}`);
export const delOpenApiById = (id: string) => DELETE(`/support/openapi/delete`, { id });

View File

@@ -1,5 +1,5 @@
import { GET, POST, DELETE } from '@/web/common/api/request';
import type { InitShareChatResponse } from '@/global/support/api/outLinkRes.d';
import type { InitShareChatResponse } from '@fastgpt/global/support/outLink/api.d';
import type { OutLinkEditType, OutLinkSchema } from '@fastgpt/global/support/outLink/type.d';
/**

View File

@@ -1,11 +1,10 @@
import { GET, POST, PUT } from '@/web/common/api/request';
import { hashStr } from '@fastgpt/global/common/string/tools';
import type { ResLogin, PromotionRecordType } from '@/global/support/api/userRes.d';
import type { ResLogin } from '@/global/support/api/userRes.d';
import { UserAuthTypeEnum } from '@/constants/common';
import { UserType, UserUpdateParams } from '@/types/user';
import type { PagingData, RequestPaging } from '@/types';
import type { UserInformSchema } from '@fastgpt/global/support/user/type';
import { OAuthEnum } from '@/constants/user';
import { UserUpdateParams } from '@/types/user';
import { UserType } from '@fastgpt/global/support/user/type.d';
import type { OauthLoginProps, PostLoginProps } from '@fastgpt/global/support/user/api.d';
export const sendAuthCode = (data: {
username: string;
@@ -14,12 +13,8 @@ export const sendAuthCode = (data: {
}) => POST(`/plusApi/support/user/inform/sendAuthCode`, data);
export const getTokenLogin = () => GET<UserType>('/user/account/tokenLogin');
export const oauthLogin = (params: {
type: `${OAuthEnum}`;
code: string;
callbackUrl: string;
inviterId?: string;
}) => POST<ResLogin>('/plusApi/support/user/account/login/oauth', params);
export const oauthLogin = (params: OauthLoginProps) =>
POST<ResLogin>('/plusApi/support/user/account/login/oauth', params);
export const postRegister = ({
username,
@@ -60,29 +55,12 @@ export const updatePasswordByOld = ({ oldPsw, newPsw }: { oldPsw: string; newPsw
newPsw: hashStr(newPsw)
});
export const postLogin = ({ username, password }: { username: string; password: string }) =>
export const postLogin = ({ password, ...props }: PostLoginProps) =>
POST<ResLogin>('/user/account/loginByPassword', {
username,
...props,
password: hashStr(password)
});
export const loginOut = () => GET('/user/account/loginout');
export const putUserInfo = (data: UserUpdateParams) => PUT('/user/account/update', data);
export const getInforms = (data: RequestPaging) =>
POST<PagingData<UserInformSchema>>(`/user/inform/list`, data);
export const getUnreadCount = () => GET<number>(`/user/inform/countUnread`);
export const readInform = (id: string) => GET(`/user/inform/read`, { id });
/* get promotion init data */
export const getPromotionInitData = () =>
GET<{
invitedAmount: number;
earningsAmount: number;
}>('/user/promotion/getPromotionData');
/* promotion records */
export const getPromotionRecords = (data: RequestPaging) =>
POST<PromotionRecordType>(`/user/promotion/getPromotions`, data);

View File

@@ -11,8 +11,10 @@ export const clearToken = () => {
};
export const setToken = (token: string) => {
if (typeof window === 'undefined') return '';
localStorage.setItem(tokenKey, token);
};
export const getToken = () => {
if (typeof window === 'undefined') return '';
return localStorage.getItem(tokenKey) || '';
};

View File

@@ -0,0 +1,9 @@
import { GET, POST, PUT } from '@/web/common/api/request';
import type { PagingData, RequestPaging } from '@/types';
import type { UserInformSchema } from '@fastgpt/global/support/user/inform/type';
export const getInforms = (data: RequestPaging) =>
POST<PagingData<UserInformSchema>>(`/plusApi/support/user/inform/list`, data);
export const getUnreadCount = () => GET<number>(`/plusApi/support/user/inform/countUnread`);
export const readInform = (id: string) => GET(`/plusApi/support/user/inform/read`, { id });

View File

@@ -0,0 +1,40 @@
import { GET, POST, PUT, DELETE } from '@/web/common/api/request';
import {
CreateTeamProps,
DelMemberProps,
InviteMemberProps,
InviteMemberResponse,
UpdateInviteProps,
UpdateTeamMemberProps,
UpdateTeamProps
} from '@fastgpt/global/support/user/team/controller.d';
import {
TeamItemType,
TeamMemberItemType,
TeamMemberSchema
} from '@fastgpt/global/support/user/team/type.d';
/* --------------- team ---------------- */
export const getTeamList = (status: `${TeamMemberSchema['status']}`) =>
GET<TeamItemType[]>(`/plusApi/support/user/team/list`, { status });
export const postCreateTeam = (data: CreateTeamProps) =>
POST<string>(`/plusApi/support/user/team/create`, data);
export const putUpdateTeam = (data: UpdateTeamProps) =>
PUT(`/plusApi/support/user/team/update`, data);
export const deleteTeam = (id: number) => DELETE(`/plusApi/support/user/team/delete`, { id });
export const putSwitchTeam = (teamId: string) =>
PUT<string>(`/plusApi/support/user/team/switch`, { teamId });
/* --------------- team member ---------------- */
export const getTeamMembers = (teamId: string) =>
GET<TeamMemberItemType[]>(`/plusApi/support/user/team/member/list`, { teamId });
export const postInviteTeamMember = (data: InviteMemberProps) =>
POST<InviteMemberResponse>(`/plusApi/support/user/team/member/invite`, data);
export const putUpdateMember = (data: UpdateTeamMemberProps) =>
PUT(`/plusApi/support/user/team/member/update`, data);
export const delRemoveMember = (props: DelMemberProps) =>
DELETE(`/plusApi/support/user/team/member/delete`, props);
export const updateInviteResult = (data: UpdateInviteProps) =>
PUT('/plusApi/support/user/team/member/updateInvite', data);
export const delLeaveTeam = (teamId: string) =>
DELETE('/plusApi/support/user/team/member/leave', { teamId });

View File

@@ -1,27 +1,16 @@
import { create } from 'zustand';
import { devtools, persist } from 'zustand/middleware';
import { immer } from 'zustand/middleware/immer';
import type { UserType, UserUpdateParams } from '@/types/user';
import { getMyApps, getModelById, putAppById } from '@/web/core/app/api';
import { formatPrice } from '@fastgpt/global/common/bill/tools';
import type { UserUpdateParams } from '@/types/user';
import type { UserType } from '@fastgpt/global/support/user/type.d';
import { formatPrice } from '@fastgpt/global/support/wallet/bill/tools';
import { getTokenLogin, putUserInfo } from '@/web/support/user/api';
import { defaultApp } from '@/constants/model';
import { AppListItemType, AppUpdateParams } from '@/types/app';
import type { AppSchema } from '@/types/mongoSchema';
type State = {
userInfo: UserType | null;
initUserInfo: () => Promise<UserType>;
setUserInfo: (user: UserType | null) => void;
updateUserInfo: (user: UserUpdateParams) => Promise<void>;
myApps: AppListItemType[];
myCollectionApps: AppListItemType[];
loadMyApps: (init?: boolean) => Promise<AppListItemType[]>;
appDetail: AppSchema;
loadAppDetail: (id: string, init?: boolean) => Promise<AppSchema>;
updateAppDetail(appId: string, data: AppUpdateParams): Promise<void>;
clearAppModules(): void;
};
export const useUserStore = create<State>()(
@@ -32,6 +21,7 @@ export const useUserStore = create<State>()(
async initUserInfo() {
const res = await getTokenLogin();
get().setUserInfo(res);
return res;
},
setUserInfo(user: UserType | null) {
@@ -61,43 +51,6 @@ export const useUserStore = create<State>()(
});
return Promise.reject(error);
}
},
myApps: [],
myCollectionApps: [],
async loadMyApps(init = true) {
if (get().myApps.length > 0 && !init) return [];
const res = await getMyApps();
set((state) => {
state.myApps = res;
});
return res;
},
appDetail: defaultApp,
async loadAppDetail(id: string, init = false) {
if (id === get().appDetail._id && !init) return get().appDetail;
const res = await getModelById(id);
set((state) => {
state.appDetail = res;
});
return res;
},
async updateAppDetail(appId: string, data: AppUpdateParams) {
await putAppById(appId, data);
set((state) => {
state.appDetail = {
...state.appDetail,
...data
};
});
},
clearAppModules() {
set((state) => {
state.appDetail = {
...state.appDetail,
modules: []
};
});
}
})),
{

View File

@@ -0,0 +1,10 @@
import { GET, POST } from '@/web/common/api/request';
import { CreateTrainingBillProps } from '@fastgpt/global/support/wallet/bill/api.d';
import type { PagingData, RequestPaging } from '@/types';
import type { BillItemType } from '@fastgpt/global/support/wallet/bill/type';
export const getUserBills = (data: RequestPaging) =>
POST<PagingData<BillItemType>>(`/plusApi/support/wallet/bill/getBill`, data);
export const postCreateTrainingBill = (data: CreateTrainingBillProps) =>
POST<string>(`/support/wallet/bill/createTrainingBill`, data);

View File

@@ -0,0 +1,25 @@
import { GET } from '@/web/common/api/request';
import type { PaySchema } from '@fastgpt/global/support/wallet/pay/type.d';
import { delay } from '@/utils/tools';
export const getPayOrders = () => GET<PaySchema[]>(`/plusApi/support/wallet/pay/getPayOrders`);
export const getPayCode = (amount: number) =>
GET<{
codeUrl: string;
payId: string;
}>(`/plusApi/support/wallet/pay/getPayCode`, { amount });
export const checkPayResult = (payId: string) =>
GET<number>(`/plusApi/support/wallet/pay/checkPayResult`, { payId }).then(() => {
async function startQueue() {
try {
await GET('/common/system/unlockTask');
} catch (error) {
await delay(1000);
startQueue();
}
}
startQueue();
return 'success';
});