mirror of https://github.com/msgbyte/tailchat
feat: 增加后端服务状态检测
parent
df28455b87
commit
9ca49d2120
@ -0,0 +1,13 @@
|
|||||||
|
import { fetchAvailableServices } from '../../model/common';
|
||||||
|
import { useAsync } from '../useAsync';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于监测服务是否可用的hooks
|
||||||
|
*/
|
||||||
|
export function useAvailableServices() {
|
||||||
|
const { loading, value: availableServices } = useAsync(() =>
|
||||||
|
fetchAvailableServices()
|
||||||
|
);
|
||||||
|
|
||||||
|
return { loading, availableServices };
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
import { LoadingSpinner } from '@capital/component';
|
||||||
|
import { fetchAvailableServices, useAsync } from '@capital/common';
|
||||||
|
import React from 'react';
|
||||||
|
import { Translate } from '../translate';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务监测
|
||||||
|
*/
|
||||||
|
export const ServiceChecker: React.FC = React.memo((props) => {
|
||||||
|
const { loading, value: enabled } = useAsync(async () => {
|
||||||
|
const services = await fetchAvailableServices();
|
||||||
|
return services.includes('openapi.app');
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return <LoadingSpinner />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!enabled) {
|
||||||
|
return <div>{Translate.noservice}</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <>{props.children}</>;
|
||||||
|
});
|
||||||
|
ServiceChecker.displayName = 'ServiceChecker';
|
Loading…
Reference in New Issue