2023-09-09 03:11:42 +08:00
|
|
|
|
import React, { useContext, useEffect, useState } from 'react';
|
2024-03-02 14:56:32 +08:00
|
|
|
|
import { Card, Col, Row } from '@douyinfe/semi-ui';
|
2023-09-09 03:11:42 +08:00
|
|
|
|
import { API, showError, showNotice, timestamp2string } from '../../helpers';
|
|
|
|
|
|
import { StatusContext } from '../../context/Status';
|
|
|
|
|
|
import { marked } from 'marked';
|
2024-12-11 17:19:03 +08:00
|
|
|
|
import { StyleContext } from '../../context/Style/index.js';
|
2024-12-14 12:58:10 +08:00
|
|
|
|
import { useTranslation } from 'react-i18next';
|
2023-04-22 20:39:27 +08:00
|
|
|
|
|
|
|
|
|
|
const Home = () => {
|
2024-12-16 21:10:46 +08:00
|
|
|
|
const { t, i18n } = useTranslation();
|
2024-03-05 23:16:35 +08:00
|
|
|
|
const [statusState] = useContext(StatusContext);
|
|
|
|
|
|
const [homePageContentLoaded, setHomePageContentLoaded] = useState(false);
|
|
|
|
|
|
const [homePageContent, setHomePageContent] = useState('');
|
2024-12-11 17:19:03 +08:00
|
|
|
|
const [styleState, styleDispatch] = useContext(StyleContext);
|
2023-04-23 20:00:47 +08:00
|
|
|
|
|
2024-03-05 23:16:35 +08:00
|
|
|
|
const displayNotice = async () => {
|
|
|
|
|
|
const res = await API.get('/api/notice');
|
|
|
|
|
|
const { success, message, data } = res.data;
|
|
|
|
|
|
if (success) {
|
|
|
|
|
|
let oldNotice = localStorage.getItem('notice');
|
|
|
|
|
|
if (data !== oldNotice && data !== '') {
|
|
|
|
|
|
const htmlNotice = marked(data);
|
|
|
|
|
|
showNotice(htmlNotice, true);
|
|
|
|
|
|
localStorage.setItem('notice', data);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
showError(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2023-04-22 20:39:27 +08:00
|
|
|
|
|
2024-03-05 23:16:35 +08:00
|
|
|
|
const displayHomePageContent = async () => {
|
|
|
|
|
|
setHomePageContent(localStorage.getItem('home_page_content') || '');
|
|
|
|
|
|
const res = await API.get('/api/home_page_content');
|
|
|
|
|
|
const { success, message, data } = res.data;
|
|
|
|
|
|
if (success) {
|
|
|
|
|
|
let content = data;
|
|
|
|
|
|
if (!data.startsWith('https://')) {
|
|
|
|
|
|
content = marked.parse(data);
|
|
|
|
|
|
}
|
|
|
|
|
|
setHomePageContent(content);
|
|
|
|
|
|
localStorage.setItem('home_page_content', content);
|
2024-09-22 14:09:03 +00:00
|
|
|
|
|
|
|
|
|
|
// 如果内容是 URL,则发送主题模式
|
|
|
|
|
|
if (data.startsWith('https://')) {
|
|
|
|
|
|
const iframe = document.querySelector('iframe');
|
|
|
|
|
|
if (iframe) {
|
|
|
|
|
|
const theme = localStorage.getItem('theme-mode') || 'light';
|
|
|
|
|
|
// 测试是否正确传递theme-mode给iframe
|
|
|
|
|
|
// console.log('Sending theme-mode to iframe:', theme);
|
|
|
|
|
|
iframe.onload = () => {
|
|
|
|
|
|
iframe.contentWindow.postMessage({ themeMode: theme }, '*');
|
2024-12-16 21:10:46 +08:00
|
|
|
|
iframe.contentWindow.postMessage({ lang: i18n.language }, '*');
|
2024-09-22 14:09:03 +00:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-03-05 23:16:35 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
showError(message);
|
|
|
|
|
|
setHomePageContent('加载首页内容失败...');
|
|
|
|
|
|
}
|
|
|
|
|
|
setHomePageContentLoaded(true);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const getStartTimeString = () => {
|
|
|
|
|
|
const timestamp = statusState?.status?.start_time;
|
|
|
|
|
|
return statusState.status ? timestamp2string(timestamp) : '';
|
|
|
|
|
|
};
|
2023-05-13 21:27:49 +08:00
|
|
|
|
|
2024-03-05 23:16:35 +08:00
|
|
|
|
useEffect(() => {
|
2025-04-03 18:57:15 +08:00
|
|
|
|
if (statusState.status?.setup === false) {
|
|
|
|
|
|
window.location.href = '/setup';
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-03-05 23:16:35 +08:00
|
|
|
|
displayNotice().then();
|
|
|
|
|
|
displayHomePageContent().then();
|
2024-12-14 14:09:30 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2024-03-05 23:16:35 +08:00
|
|
|
|
return (
|
|
|
|
|
|
<>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
{homePageContentLoaded && homePageContent === '' ? (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<Card
|
|
|
|
|
|
bordered={false}
|
|
|
|
|
|
headerLine={false}
|
2024-12-14 12:58:10 +08:00
|
|
|
|
title={t('系统状况')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
bodyStyle={{ padding: '10px 20px' }}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Row gutter={16}>
|
|
|
|
|
|
<Col span={12}>
|
|
|
|
|
|
<Card
|
2024-12-14 12:58:10 +08:00
|
|
|
|
title={t('系统信息')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
headerExtraContent={
|
|
|
|
|
|
<span
|
|
|
|
|
|
style={{
|
|
|
|
|
|
fontSize: '12px',
|
|
|
|
|
|
color: 'var(--semi-color-text-1)',
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2024-12-14 12:58:10 +08:00
|
|
|
|
{t('系统信息总览')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
}
|
|
|
|
|
|
>
|
2024-12-14 12:58:10 +08:00
|
|
|
|
<p>{t('名称')}:{statusState?.status?.system_name}</p>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
<p>
|
2024-12-14 12:58:10 +08:00
|
|
|
|
{t('版本')}:
|
2024-03-23 21:24:39 +08:00
|
|
|
|
{statusState?.status?.version
|
|
|
|
|
|
? statusState?.status?.version
|
|
|
|
|
|
: 'unknown'}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p>
|
2024-12-14 12:58:10 +08:00
|
|
|
|
{t('源码')}:
|
2024-03-23 21:24:39 +08:00
|
|
|
|
<a
|
2024-05-24 21:27:13 +08:00
|
|
|
|
href='https://github.com/Calcium-Ion/new-api'
|
2024-03-23 21:24:39 +08:00
|
|
|
|
target='_blank'
|
|
|
|
|
|
rel='noreferrer'
|
|
|
|
|
|
>
|
2024-05-24 21:27:13 +08:00
|
|
|
|
https://github.com/Calcium-Ion/new-api
|
|
|
|
|
|
</a>
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p>
|
2024-12-14 12:58:10 +08:00
|
|
|
|
{t('协议')}:
|
2024-05-24 21:27:13 +08:00
|
|
|
|
<a
|
|
|
|
|
|
href='https://www.apache.org/licenses/LICENSE-2.0'
|
|
|
|
|
|
target='_blank'
|
|
|
|
|
|
rel='noreferrer'
|
|
|
|
|
|
>
|
|
|
|
|
|
Apache-2.0 License
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</a>
|
|
|
|
|
|
</p>
|
2024-12-14 12:58:10 +08:00
|
|
|
|
<p>{t('启动时间')}:{getStartTimeString()}</p>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</Card>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
<Col span={12}>
|
|
|
|
|
|
<Card
|
2024-12-14 12:58:10 +08:00
|
|
|
|
title={t('系统配置')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
headerExtraContent={
|
|
|
|
|
|
<span
|
|
|
|
|
|
style={{
|
|
|
|
|
|
fontSize: '12px',
|
|
|
|
|
|
color: 'var(--semi-color-text-1)',
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2024-12-14 12:58:10 +08:00
|
|
|
|
{t('系统配置总览')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
}
|
|
|
|
|
|
>
|
|
|
|
|
|
<p>
|
2024-12-14 12:58:10 +08:00
|
|
|
|
{t('邮箱验证')}:
|
2024-03-23 21:24:39 +08:00
|
|
|
|
{statusState?.status?.email_verification === true
|
2024-12-14 12:58:10 +08:00
|
|
|
|
? t('已启用')
|
|
|
|
|
|
: t('未启用')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</p>
|
|
|
|
|
|
<p>
|
2024-12-14 12:58:10 +08:00
|
|
|
|
{t('GitHub 身份验证')}:
|
2024-03-23 21:24:39 +08:00
|
|
|
|
{statusState?.status?.github_oauth === true
|
2024-12-14 12:58:10 +08:00
|
|
|
|
? t('已启用')
|
|
|
|
|
|
: t('未启用')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</p>
|
2025-02-28 15:18:03 +08:00
|
|
|
|
<p>
|
|
|
|
|
|
{t('OIDC 身份验证')}:
|
|
|
|
|
|
{statusState?.status?.oidc === true
|
|
|
|
|
|
? t('已启用')
|
|
|
|
|
|
: t('未启用')}
|
|
|
|
|
|
</p>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
<p>
|
2024-12-14 12:58:10 +08:00
|
|
|
|
{t('微信身份验证')}:
|
2024-03-23 21:24:39 +08:00
|
|
|
|
{statusState?.status?.wechat_login === true
|
2024-12-14 12:58:10 +08:00
|
|
|
|
? t('已启用')
|
|
|
|
|
|
: t('未启用')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</p>
|
|
|
|
|
|
<p>
|
2024-12-14 12:58:10 +08:00
|
|
|
|
{t('Turnstile 用户校验')}:
|
2024-03-23 21:24:39 +08:00
|
|
|
|
{statusState?.status?.turnstile_check === true
|
2024-12-14 12:58:10 +08:00
|
|
|
|
? t('已启用')
|
|
|
|
|
|
: t('未启用')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</p>
|
|
|
|
|
|
<p>
|
2024-12-14 12:58:10 +08:00
|
|
|
|
{t('Telegram 身份验证')}:
|
2024-03-23 21:24:39 +08:00
|
|
|
|
{statusState?.status?.telegram_oauth === true
|
2024-12-14 12:58:10 +08:00
|
|
|
|
? t('已启用')
|
|
|
|
|
|
: t('未启用')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</p>
|
2024-11-10 23:56:22 +08:00
|
|
|
|
<p>
|
2024-12-14 12:58:10 +08:00
|
|
|
|
{t('Linux DO 身份验证')}:
|
2024-11-10 23:56:22 +08:00
|
|
|
|
{statusState?.status?.linuxdo_oauth === true
|
2024-12-14 12:58:10 +08:00
|
|
|
|
? t('已启用')
|
|
|
|
|
|
: t('未启用')}
|
2024-11-10 23:56:22 +08:00
|
|
|
|
</p>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</Card>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
</Row>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
</>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<>
|
|
|
|
|
|
{homePageContent.startsWith('https://') ? (
|
|
|
|
|
|
<iframe
|
|
|
|
|
|
src={homePageContent}
|
|
|
|
|
|
style={{ width: '100%', height: '100vh', border: 'none' }}
|
|
|
|
|
|
/>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<div
|
|
|
|
|
|
style={{ fontSize: 'larger' }}
|
|
|
|
|
|
dangerouslySetInnerHTML={{ __html: homePageContent }}
|
|
|
|
|
|
></div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
2024-03-05 23:16:35 +08:00
|
|
|
|
</>
|
|
|
|
|
|
);
|
2023-04-22 20:39:27 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-03-23 21:24:39 +08:00
|
|
|
|
export default Home;
|