mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 13:03:50 +00:00
perf: logs, auth root as super admin, etc (#2615)
* chore: usePagination hook type * feat: chat log show outlinkuid or tmb avatar and name * fix: ts error for pagination * feat: auth root
This commit is contained in:
@@ -20,7 +20,6 @@ import { getPromotionInitData, getPromotionRecords } from '@/web/support/activit
|
||||
import { useUserStore } from '@/web/support/user/useUserStore';
|
||||
|
||||
import { useCopyData } from '@/web/common/hooks/useCopyData';
|
||||
import type { PromotionRecordType } from '@/global/support/api/userRes.d';
|
||||
import dayjs from 'dayjs';
|
||||
import { usePagination } from '@fastgpt/web/hooks/usePagination';
|
||||
import { useLoading } from '@fastgpt/web/hooks/useLoading';
|
||||
@@ -40,7 +39,7 @@ const Promotion = () => {
|
||||
total,
|
||||
pageSize,
|
||||
Pagination
|
||||
} = usePagination<PromotionRecordType>({
|
||||
} = usePagination({
|
||||
api: getPromotionRecords,
|
||||
pageSize: 20
|
||||
});
|
||||
|
@@ -62,7 +62,7 @@ const BillTable = () => {
|
||||
Pagination,
|
||||
getData,
|
||||
total
|
||||
} = usePagination<BillSchemaType>({
|
||||
} = usePagination({
|
||||
api: getBills,
|
||||
pageSize: 20,
|
||||
params: {
|
||||
|
@@ -31,7 +31,7 @@ const InvoiceTable = () => {
|
||||
Pagination,
|
||||
getData,
|
||||
total
|
||||
} = usePagination<InvoiceSchemaType>({
|
||||
} = usePagination({
|
||||
api: getInvoiceRecords,
|
||||
pageSize: 20,
|
||||
defaultRequest: false
|
||||
|
@@ -13,7 +13,7 @@ import { readFromSecondary } from '@fastgpt/service/common/mongo/utils';
|
||||
|
||||
async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse
|
||||
_res: NextApiResponse
|
||||
): Promise<PagingData<AppLogsListItemType>> {
|
||||
const {
|
||||
pageNum = 1,
|
||||
@@ -131,7 +131,9 @@ async function handler(
|
||||
userGoodFeedbackCount: 1,
|
||||
userBadFeedbackCount: 1,
|
||||
customFeedbacksCount: 1,
|
||||
markCount: 1
|
||||
markCount: 1,
|
||||
outLinkUid: 1,
|
||||
tmbId: 1
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@@ -6,7 +6,6 @@ import { connectToDatabase } from '@/service/mongo';
|
||||
import { getUserDetail } from '@fastgpt/service/support/user/controller';
|
||||
import type { PostLoginProps } from '@fastgpt/global/support/user/api.d';
|
||||
import { UserStatusEnum } from '@fastgpt/global/support/user/constant';
|
||||
import { checkTeamAiPointsAndLock } from '@/service/events/utils';
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
try {
|
||||
@@ -50,7 +49,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
lastLoginTmbId: userDetail.team.tmbId
|
||||
});
|
||||
|
||||
const token = createJWT(userDetail);
|
||||
const token = createJWT({
|
||||
...userDetail,
|
||||
isRoot: username === 'root'
|
||||
});
|
||||
|
||||
setCookie(res, token);
|
||||
|
||||
jsonRes(res, {
|
||||
|
@@ -13,13 +13,12 @@ import {
|
||||
ModalBody,
|
||||
HStack
|
||||
} from '@chakra-ui/react';
|
||||
import Avatar from '@fastgpt/web/components/common/Avatar';
|
||||
import MyIcon from '@fastgpt/web/components/common/Icon';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import { getAppChatLogs } from '@/web/core/app/api';
|
||||
import dayjs from 'dayjs';
|
||||
import { ChatSourceMap } from '@fastgpt/global/core/chat/constants';
|
||||
import { AppLogsListItemType } from '@/types/app';
|
||||
import { useSystemStore } from '@/web/common/system/useSystemStore';
|
||||
import MyModal from '@fastgpt/web/components/common/MyModal';
|
||||
import { addDays } from 'date-fns';
|
||||
import { usePagination } from '@fastgpt/web/hooks/usePagination';
|
||||
@@ -32,6 +31,8 @@ import { cardStyles } from '../constants';
|
||||
|
||||
import dynamic from 'next/dynamic';
|
||||
import { useSystem } from '@fastgpt/web/hooks/useSystem';
|
||||
import { useUserStore } from '@/web/support/user/useUserStore';
|
||||
import Tag from '@fastgpt/web/components/common/Tag';
|
||||
const DetailLogsModal = dynamic(() => import('./DetailLogsModal'));
|
||||
|
||||
const Logs = () => {
|
||||
@@ -40,6 +41,7 @@ const Logs = () => {
|
||||
const { isPc } = useSystem();
|
||||
|
||||
const appId = useContextSelector(AppContext, (v) => v.appId);
|
||||
const { teamMembers } = useUserStore();
|
||||
|
||||
const [dateRange, setDateRange] = useState<DateRangeType>({
|
||||
from: addDays(new Date(), -7),
|
||||
@@ -58,7 +60,7 @@ const Logs = () => {
|
||||
Pagination,
|
||||
getData,
|
||||
pageNum
|
||||
} = usePagination<AppLogsListItemType>({
|
||||
} = usePagination({
|
||||
api: getAppChatLogs,
|
||||
pageSize: 20,
|
||||
params: {
|
||||
@@ -107,11 +109,12 @@ const Logs = () => {
|
||||
<Thead>
|
||||
<Tr>
|
||||
<Th>{t('common:core.app.logs.Source And Time')}</Th>
|
||||
<Th>{appT('logs_title')}</Th>
|
||||
<Th>{appT('logs_message_total')}</Th>
|
||||
<Th>{appT('feedback_count')}</Th>
|
||||
<Th>{t('app:logs_chat_user')}</Th>
|
||||
<Th>{t('app:logs_title')}</Th>
|
||||
<Th>{t('app:logs_message_total')}</Th>
|
||||
<Th>{t('app:feedback_count')}</Th>
|
||||
<Th>{t('common:core.app.feedback.Custom feedback')}</Th>
|
||||
<Th>{appT('mark_count')}</Th>
|
||||
<Th>{t('app:mark_count')}</Th>
|
||||
</Tr>
|
||||
</Thead>
|
||||
<Tbody fontSize={'xs'}>
|
||||
@@ -127,6 +130,23 @@ const Logs = () => {
|
||||
<Box>{t(ChatSourceMap[item.source]?.name || ('UnKnow' as any))}</Box>
|
||||
<Box color={'myGray.500'}>{dayjs(item.time).format('YYYY/MM/DD HH:mm')}</Box>
|
||||
</Td>
|
||||
<Td>
|
||||
<Box>
|
||||
{item.source === 'share' ? (
|
||||
item.outLinkUid
|
||||
) : (
|
||||
<Tag key={item._id} type={'fill'} colorSchema="white">
|
||||
<Avatar
|
||||
src={teamMembers.find((v) => v.tmbId === item.tmbId)?.avatar}
|
||||
w="1.25rem"
|
||||
/>
|
||||
<Box fontSize={'sm'} ml={1}>
|
||||
{teamMembers.find((v) => v.tmbId === item.tmbId)?.memberName}
|
||||
</Box>
|
||||
</Tag>
|
||||
)}
|
||||
</Box>
|
||||
</Td>
|
||||
<Td className="textEllipsis" maxW={'250px'}>
|
||||
{item.title}
|
||||
</Td>
|
||||
|
@@ -1,22 +1,11 @@
|
||||
import React, { useState, useRef, useMemo, useCallback } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Card,
|
||||
IconButton,
|
||||
Flex,
|
||||
Grid,
|
||||
Button,
|
||||
useTheme,
|
||||
useDisclosure,
|
||||
HStack
|
||||
} from '@chakra-ui/react';
|
||||
import React, { useState, useRef, useMemo } from 'react';
|
||||
import { Box, Card, IconButton, Flex, Button, useTheme } from '@chakra-ui/react';
|
||||
import {
|
||||
getDatasetDataList,
|
||||
delOneDatasetDataById,
|
||||
getDatasetCollectionById,
|
||||
putDatasetDataById
|
||||
} from '@/web/core/dataset/api';
|
||||
import { DeleteIcon } from '@chakra-ui/icons';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useToast } from '@fastgpt/web/hooks/useToast';
|
||||
import { getErrText } from '@fastgpt/global/common/error/utils';
|
||||
@@ -27,16 +16,8 @@ import MyIcon from '@fastgpt/web/components/common/Icon';
|
||||
import MyInput from '@/components/MyInput';
|
||||
import InputDataModal from '../components/InputDataModal';
|
||||
import RawSourceBox from '@/components/core/dataset/RawSourceBox';
|
||||
import type { DatasetDataListItemType } from '@/global/core/dataset/type.d';
|
||||
import { TabEnum } from '..';
|
||||
import { DatasetCollectionTypeMap, TrainingTypeMap } from '@fastgpt/global/core/dataset/constants';
|
||||
import { formatTime2YMDHM } from '@fastgpt/global/common/string/time';
|
||||
import { formatFileSize } from '@fastgpt/global/common/file/tools';
|
||||
import { getCollectionSourceAndOpen } from '@/web/core/dataset/hooks/readCollectionSource';
|
||||
import MyTooltip from '@fastgpt/web/components/common/MyTooltip';
|
||||
import { usePagination } from '@fastgpt/web/hooks/usePagination';
|
||||
import { getCollectionSourceData } from '@fastgpt/global/core/dataset/collection/utils';
|
||||
import { useI18n } from '@/web/context/I18n';
|
||||
import EmptyTip from '@fastgpt/web/components/common/EmptyTip';
|
||||
import { DatasetPageContext } from '@/web/core/dataset/context/datasetPageContext';
|
||||
import { useContextSelector } from 'use-context-selector';
|
||||
@@ -78,7 +59,7 @@ const DataCard = () => {
|
||||
pageNum,
|
||||
pageSize,
|
||||
isLoading: isRequesting
|
||||
} = usePagination<DatasetDataListItemType>({
|
||||
} = usePagination({
|
||||
api: getDatasetDataList,
|
||||
pageSize: 24,
|
||||
defaultRequest: false,
|
||||
@@ -125,7 +106,7 @@ const DataCard = () => {
|
||||
|
||||
const canWrite = useMemo(() => datasetDetail.permission.hasWritePer, [datasetDetail]);
|
||||
|
||||
const { run: onUpdate, loading } = useRequest2(putDatasetDataById, {
|
||||
const { loading } = useRequest2(putDatasetDataById, {
|
||||
onSuccess() {
|
||||
getData(pageNum);
|
||||
}
|
||||
|
2
projects/app/src/types/app.d.ts
vendored
2
projects/app/src/types/app.d.ts
vendored
@@ -43,4 +43,6 @@ export type AppLogsListItemType = {
|
||||
userBadFeedbackCount: number;
|
||||
customFeedbacksCount: number;
|
||||
markCount: number;
|
||||
outLinkUid?: string;
|
||||
tmbId: string;
|
||||
};
|
||||
|
@@ -4,6 +4,8 @@ import type { GetAppChatLogsParams } from '@/global/core/api/appReq.d';
|
||||
import { AppUpdateParams, AppChangeOwnerBody } from '@/global/core/app/api';
|
||||
import type { CreateAppBody } from '@/pages/api/core/app/create';
|
||||
import type { ListAppBody } from '@/pages/api/core/app/list';
|
||||
import { AppLogsListItemType } from '@/types/app';
|
||||
import { PagingData } from '@/types';
|
||||
|
||||
/**
|
||||
* 获取模型列表
|
||||
@@ -36,7 +38,8 @@ export const putAppById = (id: string, data: AppUpdateParams) =>
|
||||
PUT(`/core/app/update?appId=${id}`, data);
|
||||
|
||||
// =================== chat logs
|
||||
export const getAppChatLogs = (data: GetAppChatLogsParams) => POST(`/core/app/getChatLogs`, data);
|
||||
export const getAppChatLogs = (data: GetAppChatLogsParams) =>
|
||||
POST<PagingData<AppLogsListItemType>>(`/core/app/getChatLogs`, data);
|
||||
|
||||
export const resumeInheritPer = (appId: string) =>
|
||||
GET(`/core/app/resumeInheritPermission`, { appId });
|
||||
|
@@ -34,7 +34,10 @@ import type { CreateDatasetParams, InsertOneDatasetDataProps } from '@/global/co
|
||||
import type { DatasetCollectionItemType } from '@fastgpt/global/core/dataset/type';
|
||||
import { DatasetCollectionSyncResultEnum } from '@fastgpt/global/core/dataset/constants';
|
||||
import type { DatasetDataItemType } from '@fastgpt/global/core/dataset/type';
|
||||
import type { DatasetCollectionsListItemType } from '@/global/core/dataset/type.d';
|
||||
import type {
|
||||
DatasetCollectionsListItemType,
|
||||
DatasetDataListItemType
|
||||
} from '@/global/core/dataset/type.d';
|
||||
import { PagingData } from '@/types';
|
||||
import type { getDatasetTrainingQueueResponse } from '@/pages/api/core/dataset/training/getDatasetTrainingQueue';
|
||||
import type { rebuildEmbeddingBody } from '@/pages/api/core/dataset/training/rebuildEmbedding';
|
||||
@@ -153,7 +156,7 @@ export const getScrollCollectionList = (data: GetScrollCollectionsProps) =>
|
||||
/* =============================== data ==================================== */
|
||||
/* get dataset list */
|
||||
export const getDatasetDataList = (data: GetDatasetDataListProps) =>
|
||||
POST(`/core/dataset/data/list`, data);
|
||||
POST<PagingData<DatasetDataListItemType>>(`/core/dataset/data/list`, data);
|
||||
|
||||
export const getDatasetDataItemById = (id: string) =>
|
||||
GET<DatasetDataItemType>(`/core/dataset/data/detail`, { id });
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { GET, POST, PUT } from '@/web/common/api/request';
|
||||
import type { PromotionRecordType } from '@/global/support/api/userRes.d';
|
||||
import type { RequestPaging } from '@/types';
|
||||
import { PagingData, type RequestPaging } from '@/types';
|
||||
|
||||
/* get promotion init data */
|
||||
export const getPromotionInitData = () =>
|
||||
@@ -11,4 +11,4 @@ export const getPromotionInitData = () =>
|
||||
|
||||
/* promotion records */
|
||||
export const getPromotionRecords = (data: RequestPaging) =>
|
||||
POST<PromotionRecordType>(`/proApi/support/activity/promotion/getPromotions`, data);
|
||||
POST<PagingData<PromotionRecordType>>(`/proApi/support/activity/promotion/getPromotions`, data);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { RequestPaging } from '@/types';
|
||||
import { PagingData, RequestPaging } from '@/types';
|
||||
import { GET, POST } from '@/web/common/api/request';
|
||||
import { CreateBillProps, CreateBillResponse } from '@fastgpt/global/support/wallet/bill/api';
|
||||
import { BillTypeEnum } from '@fastgpt/global/support/wallet/bill/constants';
|
||||
@@ -8,7 +8,7 @@ export const getBills = (
|
||||
data: RequestPaging & {
|
||||
type?: BillTypeEnum;
|
||||
}
|
||||
) => POST<BillSchemaType[]>(`/proApi/support/wallet/bill/list`, data);
|
||||
) => POST<PagingData<BillSchemaType>>(`/proApi/support/wallet/bill/list`, data);
|
||||
|
||||
export const getWxPayQRCode = (data: CreateBillProps) =>
|
||||
POST<CreateBillResponse>(`/proApi/support/wallet/bill/create`, data);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { RequestPaging } from '@/types';
|
||||
import { PagingData, RequestPaging } from '@/types';
|
||||
import { GET, POST } from '@/web/common/api/request';
|
||||
import { BillTypeEnum } from '@fastgpt/global/support/wallet/bill/constants';
|
||||
import { InvoiceType } from '@fastgpt/global/support/wallet/bill/type';
|
||||
@@ -17,4 +17,4 @@ export const submitInvoice = (data: InvoiceType) =>
|
||||
POST(`/proApi/support/wallet/bill/invoice/submit`, data);
|
||||
|
||||
export const getInvoiceRecords = (data: RequestPaging) =>
|
||||
POST<InvoiceSchemaType[]>(`/proApi/support/wallet/bill/invoice/records`, data);
|
||||
POST<PagingData<InvoiceSchemaType>>(`/proApi/support/wallet/bill/invoice/records`, data);
|
||||
|
Reference in New Issue
Block a user