From ddb8be921908c0a085b187dffcbaf883c2385c1a Mon Sep 17 00:00:00 2001 From: Fachuan Bai Date: Fri, 20 Sep 2024 09:49:16 +0800 Subject: [PATCH] Web: Display the icon of the currently used storage. (#2504) https://github.com/infiniflow/ragflow/issues/2503 ### What problem does this PR solve? _Briefly describe what this PR aims to solve. Include background context that will help reviewers understand the purpose of the PR._ ### Type of change - [x] New Feature (non-breaking change which adds functionality) Before: image After: image image --- api/apps/system_app.py | 11 ++++++----- rag/utils/storage_factory.py | 3 ++- web/src/assets/svg/database.svg | 3 +++ web/src/assets/svg/storage.svg | 6 ++++++ web/src/interfaces/database/user-setting.ts | 12 +++++++++--- .../pages/user-setting/setting-system/index.tsx | 14 +++++++++++--- 6 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 web/src/assets/svg/database.svg create mode 100644 web/src/assets/svg/storage.svg diff --git a/api/apps/system_app.py b/api/apps/system_app.py index 6f46d9104..e55a95037 100644 --- a/api/apps/system_app.py +++ b/api/apps/system_app.py @@ -18,11 +18,12 @@ import json from flask_login import login_required from api.db.services.knowledgebase_service import KnowledgebaseService +from api.settings import DATABASE_TYPE from api.utils.api_utils import get_json_result from api.versions import get_rag_version from rag.settings import SVR_QUEUE_NAME from rag.utils.es_conn import ELASTICSEARCH -from rag.utils.storage_factory import STORAGE_IMPL +from rag.utils.storage_factory import STORAGE_IMPL, STORAGE_IMPL_TYPE from timeit import default_timer as timer from rag.utils.redis_conn import REDIS_CONN @@ -48,16 +49,16 @@ def status(): st = timer() try: STORAGE_IMPL.health() - res["minio"] = {"status": "green", "elapsed": "{:.1f}".format((timer() - st)*1000.)} + res["storage"] = {"storage": STORAGE_IMPL_TYPE.lower(), "status": "green", "elapsed": "{:.1f}".format((timer() - st)*1000.)} except Exception as e: - res["minio"] = {"status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)} + res["storage"] = {"storage": STORAGE_IMPL_TYPE.lower(), "status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)} st = timer() try: KnowledgebaseService.get_by_id("x") - res["mysql"] = {"status": "green", "elapsed": "{:.1f}".format((timer() - st)*1000.)} + res["database"] = {"database": DATABASE_TYPE.lower(), "status": "green", "elapsed": "{:.1f}".format((timer() - st)*1000.)} except Exception as e: - res["mysql"] = {"status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)} + res["database"] = {"database": DATABASE_TYPE.lower(), "status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)} st = timer() try: diff --git a/rag/utils/storage_factory.py b/rag/utils/storage_factory.py index 0b50affbe..7c7a4a71d 100644 --- a/rag/utils/storage_factory.py +++ b/rag/utils/storage_factory.py @@ -27,4 +27,5 @@ class StorageFactory: return cls.storage_mapping[storage]() -STORAGE_IMPL = StorageFactory.create(Storage[os.getenv('STORAGE_IMPL', 'MINIO')]) +STORAGE_IMPL_TYPE = os.getenv('STORAGE_IMPL', 'MINIO') +STORAGE_IMPL = StorageFactory.create(Storage[STORAGE_IMPL_TYPE]) diff --git a/web/src/assets/svg/database.svg b/web/src/assets/svg/database.svg new file mode 100644 index 000000000..687326cee --- /dev/null +++ b/web/src/assets/svg/database.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/web/src/assets/svg/storage.svg b/web/src/assets/svg/storage.svg new file mode 100644 index 000000000..0cd231bd4 --- /dev/null +++ b/web/src/assets/svg/storage.svg @@ -0,0 +1,6 @@ + + + storage-solid + + + \ No newline at end of file diff --git a/web/src/interfaces/database/user-setting.ts b/web/src/interfaces/database/user-setting.ts index 75bf563b9..61e16c0ea 100644 --- a/web/src/interfaces/database/user-setting.ts +++ b/web/src/interfaces/database/user-setting.ts @@ -24,8 +24,8 @@ export type TaskExecutorElapsed = Record; export interface ISystemStatus { es: Es; - minio: Minio; - mysql: Minio; + storage: Storage; + database: Database; redis: Redis; task_executor: { error?: string; @@ -41,7 +41,13 @@ interface Redis { pending: number; } -export interface Minio { +export interface Storage { + status: string; + elapsed: number; + error: string; +} + +export interface Database { status: string; elapsed: number; error: string; diff --git a/web/src/pages/user-setting/setting-system/index.tsx b/web/src/pages/user-setting/setting-system/index.tsx index 5ca8d791a..465419430 100644 --- a/web/src/pages/user-setting/setting-system/index.tsx +++ b/web/src/pages/user-setting/setting-system/index.tsx @@ -1,5 +1,6 @@ import SvgIcon from '@/components/svg-icon'; import { useFetchSystemStatus } from '@/hooks/user-setting-hooks'; +import { ISystemStatus, Storage } from '@/interfaces/database/userSetting'; import { ISystemStatus, TaskExecutorElapsed, @@ -24,12 +25,19 @@ enum Status { const TitleMap = { es: 'Elasticsearch', - minio: 'MinIO Object Storage', + storage: 'Object Storage', redis: 'Redis', - mysql: 'Mysql', + database: 'Database', task_executor: 'Task Executor', }; +const IconMap = { + es: 'es', + storage: 'storage', + redis: 'redis', + database: 'database', +}; + const SystemInfo = () => { const { systemStatus, @@ -56,7 +64,7 @@ const SystemInfo = () => { {key === 'task_executor' ? ( ) : ( - + )} {TitleMap[key as keyof typeof TitleMap]}