From 750b16b6ee0dc7f50f1db1ce0248a225367c7f20 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Thu, 27 Mar 2025 15:54:23 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20add=20demo=20mode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/__init__.py | 1 + astrbot/dashboard/routes/auth.py | 9 +++++- astrbot/dashboard/routes/plugin.py | 50 ++++++++++++++++++++++++++++++ astrbot/dashboard/routes/stat.py | 8 +++++ astrbot/dashboard/routes/update.py | 8 +++++ 5 files changed, 75 insertions(+), 1 deletion(-) diff --git a/astrbot/core/__init__.py b/astrbot/core/__init__.py index 9749dee24..cfedf92e5 100644 --- a/astrbot/core/__init__.py +++ b/astrbot/core/__init__.py @@ -24,3 +24,4 @@ pip_installer = PipInstaller(astrbot_config.get("pip_install_arg", "")) web_chat_queue = asyncio.Queue(maxsize=32) web_chat_back_queue = asyncio.Queue(maxsize=32) WEBUI_SK = "Advanced_System_for_Text_Response_and_Bot_Operations_Tool" +DEMO_MODE = os.getenv("DEMO_MODE", False) diff --git a/astrbot/dashboard/routes/auth.py b/astrbot/dashboard/routes/auth.py index 34ba8fd3f..896bea4e7 100644 --- a/astrbot/dashboard/routes/auth.py +++ b/astrbot/dashboard/routes/auth.py @@ -2,7 +2,7 @@ import jwt import datetime from .route import Route, Response, RouteContext from quart import request -from astrbot.core import WEBUI_SK +from astrbot.core import WEBUI_SK, DEMO_MODE from astrbot import logger @@ -40,6 +40,13 @@ class AuthRoute(Route): return Response().error("用户名或密码错误").__dict__ async def edit_account(self): + if DEMO_MODE: + return ( + Response() + .error("You are not permitted to do this operation in demo mode") + .__dict__ + ) + password = self.config["dashboard"]["password"] post_data = await request.json diff --git a/astrbot/dashboard/routes/plugin.py b/astrbot/dashboard/routes/plugin.py index 32dc99176..3ffa1c557 100644 --- a/astrbot/dashboard/routes/plugin.py +++ b/astrbot/dashboard/routes/plugin.py @@ -15,6 +15,7 @@ from astrbot.core.star.filter.command_group import CommandGroupFilter from astrbot.core.star.filter.permission import PermissionTypeFilter from astrbot.core.star.filter.regex import RegexFilter from astrbot.core.star.star_handler import EventType +from astrbot.core import DEMO_MODE class PluginRoute(Route): @@ -50,6 +51,13 @@ class PluginRoute(Route): } async def reload_plugins(self): + if DEMO_MODE: + return ( + Response() + .error("You are not permitted to do this operation in demo mode") + .__dict__ + ) + data = await request.json plugin_name = data.get("name", None) try: @@ -187,6 +195,13 @@ class PluginRoute(Route): return handlers async def install_plugin(self): + if DEMO_MODE: + return ( + Response() + .error("You are not permitted to do this operation in demo mode") + .__dict__ + ) + post_data = await request.json repo_url = post_data["url"] @@ -205,6 +220,13 @@ class PluginRoute(Route): return Response().error(str(e)).__dict__ async def install_plugin_upload(self): + if DEMO_MODE: + return ( + Response() + .error("You are not permitted to do this operation in demo mode") + .__dict__ + ) + try: file = await request.files file = file["file"] @@ -220,6 +242,13 @@ class PluginRoute(Route): return Response().error(str(e)).__dict__ async def uninstall_plugin(self): + if DEMO_MODE: + return ( + Response() + .error("You are not permitted to do this operation in demo mode") + .__dict__ + ) + post_data = await request.json plugin_name = post_data["name"] try: @@ -232,6 +261,13 @@ class PluginRoute(Route): return Response().error(str(e)).__dict__ async def update_plugin(self): + if DEMO_MODE: + return ( + Response() + .error("You are not permitted to do this operation in demo mode") + .__dict__ + ) + post_data = await request.json plugin_name = post_data["name"] proxy: str = post_data.get("proxy", None) @@ -247,6 +283,13 @@ class PluginRoute(Route): return Response().error(str(e)).__dict__ async def off_plugin(self): + if DEMO_MODE: + return ( + Response() + .error("You are not permitted to do this operation in demo mode") + .__dict__ + ) + post_data = await request.json plugin_name = post_data["name"] try: @@ -258,6 +301,13 @@ class PluginRoute(Route): return Response().error(str(e)).__dict__ async def on_plugin(self): + if DEMO_MODE: + return ( + Response() + .error("You are not permitted to do this operation in demo mode") + .__dict__ + ) + post_data = await request.json plugin_name = post_data["name"] try: diff --git a/astrbot/dashboard/routes/stat.py b/astrbot/dashboard/routes/stat.py index e73c09455..337e544af 100644 --- a/astrbot/dashboard/routes/stat.py +++ b/astrbot/dashboard/routes/stat.py @@ -8,6 +8,7 @@ from quart import request from astrbot.core.core_lifecycle import AstrBotCoreLifecycle from astrbot.core.db import BaseDatabase from astrbot.core.config import VERSION +from astrbot.core import DEMO_MODE class StatRoute(Route): @@ -29,6 +30,13 @@ class StatRoute(Route): self.core_lifecycle = core_lifecycle async def restart_core(self): + if DEMO_MODE: + return ( + Response() + .error("You are not permitted to do this operation in demo mode") + .__dict__ + ) + await self.core_lifecycle.restart() return Response().ok().__dict__ diff --git a/astrbot/dashboard/routes/update.py b/astrbot/dashboard/routes/update.py index e9ada18f5..bd0782088 100644 --- a/astrbot/dashboard/routes/update.py +++ b/astrbot/dashboard/routes/update.py @@ -6,6 +6,7 @@ from astrbot.core.updator import AstrBotUpdator from astrbot.core import logger, pip_installer from astrbot.core.utils.io import download_dashboard, get_dashboard_version from astrbot.core.config.default import VERSION +from astrbot.core import DEMO_MODE class UpdateRoute(Route): @@ -126,6 +127,13 @@ class UpdateRoute(Route): return Response().error(e.__str__()).__dict__ async def install_pip_package(self): + if DEMO_MODE: + return ( + Response() + .error("You are not permitted to do this operation in demo mode") + .__dict__ + ) + data = await request.json package = data.get("package", "") if not package: