From 85fd6b49775244abb903a7fd377221aee360b8d5 Mon Sep 17 00:00:00 2001 From: ForgQi <34411314+ForgQi@users.noreply.github.com> Date: Sun, 17 Dec 2023 23:54:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=AF=E5=8A=A8bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- app/dashboard/page.tsx | 181 +++++++++++++++++++++++++++--------- biliup/__main__.py | 7 +- biliup/app.py | 11 ++- biliup/engine/decorators.py | 2 + biliup/web/__init__.py | 14 ++- 6 files changed, 162 insertions(+), 55 deletions(-) diff --git a/.gitignore b/.gitignore index f407776..83d744b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ venv./ .venv/ pdm.lock .pdm-python -config*.yaml +config.*.* !public/config.yaml /configlog.ini ds_update.log* diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx index e514bb2..58feefe 100644 --- a/app/dashboard/page.tsx +++ b/app/dashboard/page.tsx @@ -13,7 +13,7 @@ const Dashboard: React.FC = () => { const {Header, Content} = Layout; const { data: entity, error, isLoading } = useSWR("/v1/configuration", fetcher); const { trigger } = useSWRMutation("/v1/configuration", put); - const api = useRef(); + const formRef = useRef(); const [labelPosition, setLabelPosition] = useState<'top' | 'left' | 'inset'>('inset'); useEffect(() => { @@ -27,7 +27,10 @@ const Dashboard: React.FC = () => { }) return () => unRegister(); }, []); - +// const handleSelectChange = (value) => { +// let text = value === 'male' ? 'Hi male' : 'Hi female!'; +// formRef.current?.setValue('Note', text); +// }; return <>
@@ -42,7 +45,7 @@ const Dashboard: React.FC = () => { padding: '6px' }}>

空间配置

} - footer={} + footer={} mode="horizontal" >
@@ -51,119 +54,172 @@ const Dashboard: React.FC = () => { onSubmit={async (values) => { await trigger(values) }} - getFormApi={formApi => api.current = formApi} + getFormApi={formApi => formRef.current = formApi} style={{padding: '10px', marginLeft: '30px'}} labelPosition={labelPosition} labelWidth='300px'> - - - + bili_web + biliup-rs + Noop + + - + bda2 + kodo + ws + qn + + - - - - - - - - - - @@ -174,77 +230,110 @@ const Dashboard: React.FC = () => { /> - - - - - - diff --git a/biliup/__main__.py b/biliup/__main__.py index 6f06d87..0cf3dd2 100644 --- a/biliup/__main__.py +++ b/biliup/__main__.py @@ -44,8 +44,11 @@ def arg_parser(): biliup.common.reload.program_args = args.__dict__ # 初始化数据库 if db.init(): - config.load(args.config) - config.save_to_db() + try: + config.load(args.config) + config.save_to_db() + except FileNotFoundError: + print("新版本不依赖配置文件") config.load_from_db() LOG_CONF.update(config.get('LOGGING', {})) if args.verbose: diff --git a/biliup/app.py b/biliup/app.py index 8f20695..ab57174 100644 --- a/biliup/app.py +++ b/biliup/app.py @@ -1,11 +1,12 @@ import asyncio +import logging from . import plugins from biliup.config import config from biliup.engine import Plugin, invert_dict from biliup.engine.event import EventManager from .common.timer import Timer - +logger = logging.getLogger('biliup') def create_event_manager(): pool1_size = config.get('pool1_size', 3) @@ -26,6 +27,9 @@ async def shot(event): from biliup.handler import CHECK index = 0 while True: + if len(event.url_list): + logger.info(f"{event}没有任务,退出") + return if index >= len(event.url_list): index = 0 continue @@ -47,7 +51,6 @@ class PluginInfo: self.init_tasks() def add(self, name, url): - from .plugins.twitch import Twitch temp = Plugin(plugins).inspect_checker(url) key = temp.__name__ if key in self.checker: @@ -55,6 +58,7 @@ class PluginInfo: else: temp.url_list = [url] self.checker[key] = temp + from .plugins.twitch import Twitch if temp == Twitch: # 如果支持批量检测,目前只有一个支持,第一版先写死按照特例处理 self.batch_check_task() @@ -86,9 +90,6 @@ class PluginInfo: for key, plugin in self.checker.items(): if plugin == Twitch: # 如果支持批量检测,目前只有一个支持,第一版先写死按照特例处理 - print(getattr(plugin, DownloadBase.batch_check.__name__)) - print(DownloadBase.batch_check) - print('???????') self.batch_check_task() continue self.coroutines[key] = asyncio.create_task(shot(plugin)) diff --git a/biliup/engine/decorators.py b/biliup/engine/decorators.py index abbd0c7..1a8428f 100644 --- a/biliup/engine/decorators.py +++ b/biliup/engine/decorators.py @@ -40,6 +40,8 @@ class Plugin: @classmethod def sorted_checker(cls, urls): + if not urls: + return {} from ..plugins import general curls = urls.copy() checker_plugins = {} diff --git a/biliup/web/__init__.py b/biliup/web/__init__.py index 6dd9b95..5d07a9f 100644 --- a/biliup/web/__init__.py +++ b/biliup/web/__init__.py @@ -4,6 +4,7 @@ import os import aiohttp_cors import requests from aiohttp import web +from peewee import DoesNotExist from playhouse.shortcuts import model_to_dict from .aiohttp_basicauth_middleware import basic_auth_middleware @@ -228,7 +229,10 @@ async def lives(request): @routes.delete('/v1/streamers/{id}') async def streamers(request): + from biliup.app import context + org = LiveStreamers.get_by_id(request.match_info['id']) LiveStreamers.delete_by_id(request.match_info['id']) + context['PluginInfo'].delete(org.url) return web.HTTPOk() @routes.get('/v1/upload/streamers') @@ -242,6 +246,7 @@ async def get_streamers(request): async def streamers_id(request): id = request.match_info['id'] return web.json_response(UploadStreamers.get_dict(id=id)) + @routes.delete('/v1/upload/streamers/{id}') async def streamers(request): UploadStreamers.delete_by_id(request.match_info['id']) @@ -252,6 +257,7 @@ async def streamers_post(request): json_data = await request.json() to_save = UploadStreamers(**json_data) to_save.save() + config.load_from_db() res = model_to_dict(to_save) return web.json_response(res) @@ -259,6 +265,7 @@ async def streamers_post(request): async def streamers_put(request): json_data = await request.json() UploadStreamers.update(**json_data) + config.load_from_db() return web.json_response(UploadStreamers.get_dict(id=json_data['id'])) @routes.get('/v1/users') @@ -272,13 +279,18 @@ async def users(request): @routes.get('/v1/configuration') async def users(request): - return web.json_response(json.loads(Configuration.get(Configuration.key == 'config').value)) + try: + record = Configuration.get(Configuration.key == 'config') + except DoesNotExist: + return web.json_response({}) + return web.json_response(json.loads(record.value)) @routes.put('/v1/configuration') async def users(request): json_data = await request.json() to_save = Configuration(key='config', value=json.dumps(json_data)) to_save.save() + config.load_from_db() return web.json_response(model_to_dict(to_save)) @routes.get('/bili/archive/pre')