mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-09 18:27:56 +08:00
finish first admin frontend
This commit is contained in:
@@ -18,7 +18,7 @@ import functools
|
||||
|
||||
from starlette.requests import Request
|
||||
|
||||
from .api import del_group_sub, test, get_global_conf, auth, get_subs_info, get_target_name, add_group_sub
|
||||
from .api import del_group_sub, test, get_global_conf, auth, get_subs_info, get_target_name, add_group_sub, update_group_sub
|
||||
from .token_manager import token_manager as tm
|
||||
from .jwt import load_jwt
|
||||
from ..plugin_config import plugin_config
|
||||
@@ -72,7 +72,7 @@ def register_router_fastapi(driver: Driver, socketio):
|
||||
platformName: str
|
||||
target: str
|
||||
targetName: str
|
||||
cats: list[str]
|
||||
cats: list[int]
|
||||
tags: list[str]
|
||||
|
||||
app = driver.server_app
|
||||
@@ -91,7 +91,10 @@ def register_router_fastapi(driver: Driver, socketio):
|
||||
async def _add_group_subs(groupNumber: str, req: AddSubscribeReq):
|
||||
return await add_group_sub(group_number=groupNumber, platform_name=req.platformName,
|
||||
target=req.target, target_name=req.targetName, cats=req.cats, tags=req.tags)
|
||||
|
||||
@app.patch(SUBSCRIBE_URL, dependencies=[Depends(check_group_permission)])
|
||||
async def _update_group_subs(groupNumber: str, req: AddSubscribeReq):
|
||||
return await update_group_sub(group_number=groupNumber, platform_name=req.platformName,
|
||||
target=req.target, target_name=req.targetName, cats=req.cats, tags=req.tags)
|
||||
@app.delete(SUBSCRIBE_URL, dependencies=[Depends(check_group_permission)])
|
||||
async def _del_group_subs(groupNumber: str, target: str, platformName: str):
|
||||
return await del_group_sub(groupNumber, platformName, target)
|
||||
|
||||
@@ -100,3 +100,15 @@ async def del_group_sub(group_number: str, platform_name: str, target: str):
|
||||
except (NoSuchUserException, NoSuchSubscribeException):
|
||||
return { 'status': 400, 'msg': '删除错误' }
|
||||
return { 'status': 200, 'msg': '' }
|
||||
|
||||
|
||||
async def update_group_sub(group_number: str, platform_name: str, target: str,
|
||||
target_name: str, cats: list[str], tags: list[str]):
|
||||
config = Config()
|
||||
try:
|
||||
config.update_subscribe(int(group_number), 'group',
|
||||
target, target_name, platform_name, cats, tags)
|
||||
except (NoSuchUserException, NoSuchSubscribeException):
|
||||
return { 'status': 400, 'msg': '更新错误' }
|
||||
return { 'status': 200, 'msg': '' }
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@ from typing import DefaultDict, Mapping
|
||||
import nonebot
|
||||
from tinydb import Query, TinyDB
|
||||
|
||||
from .platform import platform_manager
|
||||
from .plugin_config import plugin_config
|
||||
from .types import Target, User
|
||||
from .utils import Singleton
|
||||
from .platform import platform_manager
|
||||
|
||||
supported_target_type = platform_manager.keys()
|
||||
|
||||
@@ -86,6 +86,25 @@ class Config(metaclass=Singleton):
|
||||
return
|
||||
raise NoSuchSubscribeException()
|
||||
|
||||
def update_subscribe(self, user, user_type, target, target_name, target_type, cats, tags):
|
||||
user_query = Query()
|
||||
query = (user_query.user == user) & (user_query.user_type == user_type)
|
||||
if (user_data := self.user_target.get(query)):
|
||||
# update
|
||||
subs: list = user_data.get('subs', [])
|
||||
find_flag = False
|
||||
for item in subs:
|
||||
if item['target'] == target and item['target_type'] == target_type:
|
||||
item['target_name'], item['cats'], item['tags'] = \
|
||||
target_name, cats, tags
|
||||
find_flag = True
|
||||
break
|
||||
if not find_flag:
|
||||
raise NoSuchSubscribeException()
|
||||
self.user_target.update({"subs": subs}, query)
|
||||
else:
|
||||
raise NoSuchUserException()
|
||||
|
||||
def update_send_cache(self):
|
||||
res = {target_type: defaultdict(list) for target_type in supported_target_type}
|
||||
cat_res = {target_type: defaultdict(lambda: defaultdict(list)) for target_type in supported_target_type}
|
||||
|
||||
Reference in New Issue
Block a user