feat: API access key management #2846 (#2865)

### What problem does this PR solve?

feat: API access key management #2846
feat: Render markdown file with remark-loader #2846

### Type of change

- [ ] Bug Fix (non-breaking change which fixes an issue)
- [x] New Feature (non-breaking change which adds functionality)
- [ ] Documentation Update
- [ ] Refactoring
- [ ] Performance Improvement
- [ ] Other (please describe):
This commit is contained in:
balibabu
2024-10-16 15:57:39 +08:00
committed by GitHub
parent 4991107822
commit e5d3ab0332
32 changed files with 1303 additions and 165 deletions

View File

@ -1,5 +1,6 @@
import { LanguageTranslationMap } from '@/constants/common';
import { ResponseGetType } from '@/interfaces/database/base';
import { IToken } from '@/interfaces/database/chat';
import { ITenantInfo } from '@/interfaces/database/knowledge';
import { ISystemStatus, IUserInfo } from '@/interfaces/database/user-setting';
import userService from '@/services/user-service';
@ -152,3 +153,65 @@ export const useFetchSystemStatus = () => {
loading,
};
};
export const useFetchSystemTokenList = (params: Record<string, any>) => {
const {
data,
isFetching: loading,
refetch,
} = useQuery<IToken[]>({
queryKey: ['fetchSystemTokenList', params],
initialData: [],
gcTime: 0,
queryFn: async () => {
const { data } = await userService.listToken(params);
return data?.data ?? [];
},
});
return { data, loading, refetch };
};
export const useRemoveSystemToken = () => {
const queryClient = useQueryClient();
const { t } = useTranslation();
const {
data,
isPending: loading,
mutateAsync,
} = useMutation({
mutationKey: ['removeSystemToken'],
mutationFn: async (token: string) => {
const { data } = await userService.removeToken({}, token);
if (data.retcode === 0) {
message.success(t('message.deleted'));
queryClient.invalidateQueries({ queryKey: ['fetchSystemTokenList'] });
}
return data?.data ?? [];
},
});
return { data, loading, removeToken: mutateAsync };
};
export const useCreateSystemToken = () => {
const queryClient = useQueryClient();
const {
data,
isPending: loading,
mutateAsync,
} = useMutation({
mutationKey: ['createSystemToken'],
mutationFn: async (params: Record<string, any>) => {
const { data } = await userService.createToken(params);
if (data.retcode === 0) {
queryClient.invalidateQueries({ queryKey: ['fetchSystemTokenList'] });
}
return data?.data ?? [];
},
});
return { data, loading, createToken: mutateAsync };
};