Fix: 超出连接池上限无法释放、webui中cookie文件显示错误 (#834)
* Fix: 超出连接池上限无法释放 * 确保Session正常关闭 * 优化pre获取cookie方式 * 修复cookie文件失效表现形式
This commit is contained in:
6 files changed
+53
-26
No files matched your search
@@ -32,15 +32,26 @@ export function useBiliUsers() {
|
||||
}
|
||||
|
||||
const updateList = async (item: User) => {
|
||||
const res = await fetcher(`/bili/space/myinfo?user=${item.value}`, undefined);
|
||||
const pRes = await proxy(`/bili/proxy?url=${res.data.face}`);
|
||||
const myBlob = await pRes.blob();
|
||||
|
||||
return {
|
||||
...item,
|
||||
name: res.data.name,
|
||||
face: URL.createObjectURL(myBlob),
|
||||
};
|
||||
try {
|
||||
const res = await fetcher(`/bili/space/myinfo?user=${item.value}`, undefined);
|
||||
const pRes = await proxy(`/bili/proxy?url=${res.data.face}`);
|
||||
const myBlob = await pRes.blob();
|
||||
|
||||
return {
|
||||
...item,
|
||||
name: res.data.name,
|
||||
face: URL.createObjectURL(myBlob),
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
const pRes = await proxy("/bili/proxy?url=https://i0.hdslb.com/bfs/face/member/noface.jpg");
|
||||
const myBlob = await pRes.blob();
|
||||
return {
|
||||
...item,
|
||||
name: "Cookie已失效",
|
||||
face: URL.createObjectURL(myBlob),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const updateData = async (data: User[]) => {
|
||||
|
||||
@@ -50,6 +50,7 @@ def arg_parser():
|
||||
except FileNotFoundError:
|
||||
print(f'新版本不依赖配置文件,请访问 WebUI 修改配置')
|
||||
config.load_from_db()
|
||||
db.remove()
|
||||
LOG_CONF.update(config.get('LOGGING', {}))
|
||||
if args.verbose:
|
||||
LOG_CONF['loggers']['biliup']['level'] = args.verbose
|
||||
|
||||
@@ -47,6 +47,16 @@ class DB:
|
||||
cls.migrate_via_alembic()
|
||||
return run or no_http
|
||||
|
||||
@classmethod
|
||||
def close(cls):
|
||||
""" 关闭 Session, 释放连接到连接池 """
|
||||
Session.close()
|
||||
|
||||
@classmethod
|
||||
def remove(cls):
|
||||
""" 释放连接, 并删除注册表中的 Session """
|
||||
Session.remove()
|
||||
|
||||
@classmethod
|
||||
def get_stream_info(cls, name: str) -> dict:
|
||||
"""根据 streamer 获取下载信息, 若不存在则返回空字典"""
|
||||
|
||||
@@ -186,6 +186,7 @@ class DownloadBase:
|
||||
# 将文件名和直播标题存储到数据库
|
||||
db.update_file_list(self.database_row_id, file_name)
|
||||
db.update_room_title(self.database_row_id, self.room_title)
|
||||
db.close()
|
||||
retval = self.download(file_name)
|
||||
self.rename(f'{file_name}.{self.suffix}')
|
||||
return retval
|
||||
@@ -208,6 +209,7 @@ class DownloadBase:
|
||||
'date': date,
|
||||
}
|
||||
self.database_row_id = db.add_stream_info(**stream_info) # 返回数据库中此行记录的 id
|
||||
db.close()
|
||||
|
||||
while True:
|
||||
ret = False
|
||||
@@ -264,6 +266,7 @@ class DownloadBase:
|
||||
self.download_cover(time.strftime(self.get_filename().encode("unicode-escape").decode(), date).encode().decode("unicode-escape"))
|
||||
# 更新数据库中封面存储路径
|
||||
db.update_cover_path(self.database_row_id, self.live_cover_path)
|
||||
db.remove()
|
||||
logger.info(f'退出下载:{self.__class__.__name__} - {self.fname}')
|
||||
stream_info = {
|
||||
'name': self.fname,
|
||||
|
||||
@@ -132,6 +132,7 @@ def process_upload(stream_info):
|
||||
data, _ = fmt_title_and_desc({
|
||||
**DB.get_stream_info_by_filename(os.path.splitext(file_list[0].video)[0]),
|
||||
"name": name}) # 如果 restart, data 中会缺失 name 项
|
||||
DB.remove()
|
||||
stream_info.update(data)
|
||||
filelist = upload(stream_info)
|
||||
if filelist:
|
||||
|
||||
+18
-17
@@ -422,15 +422,21 @@ async def dump_config(request):
|
||||
|
||||
@routes.get('/bili/archive/pre')
|
||||
async def pre_archive(request):
|
||||
path = 'cookies.json'
|
||||
# path = 'cookies.json'
|
||||
# conf = Configuration.get_or_none(Configuration.key == 'bilibili-cookies')
|
||||
conf = Session.scalars(
|
||||
select(Configuration).where(Configuration.key == 'bilibili-cookies')).first()
|
||||
if conf is not None:
|
||||
confs = Session.scalars(
|
||||
select(Configuration).where(Configuration.key == 'bilibili-cookies'))
|
||||
# if conf is not None:
|
||||
# path = conf.value
|
||||
for conf in confs:
|
||||
path = conf.value
|
||||
config.load_cookies(path)
|
||||
cookies = config.data['user']['cookies']
|
||||
return web.json_response(BiliBili.tid_archive(cookies))
|
||||
try:
|
||||
config.load_cookies(path)
|
||||
cookies = config.data['user']['cookies']
|
||||
return web.json_response(BiliBili.tid_archive(cookies))
|
||||
except:
|
||||
continue
|
||||
return web.json_response({"status": 500, 'error': "无可用 cookie 文件"}, status=500)
|
||||
|
||||
|
||||
@routes.get('/bili/space/myinfo')
|
||||
@@ -457,14 +463,6 @@ def find_all_folders(directory):
|
||||
return result
|
||||
|
||||
|
||||
@web.middleware
|
||||
async def get_session(request, handler):
|
||||
""" 中间件,用来在请求结束时关闭对应线程会话 """
|
||||
resp = await handler(request)
|
||||
Session.remove()
|
||||
return resp
|
||||
|
||||
|
||||
async def service(args):
|
||||
try:
|
||||
from importlib.resources import files
|
||||
@@ -472,7 +470,7 @@ async def service(args):
|
||||
# Try backported to PY<37 `importlib_resources`.
|
||||
from importlib_resources import files
|
||||
|
||||
app = web.Application(middlewares=[get_session])
|
||||
app = web.Application()
|
||||
app.add_routes([
|
||||
web.get('/api/check_tag', tag_check),
|
||||
web.get('/url-status', url_status),
|
||||
@@ -559,6 +557,8 @@ def create_error_middleware(overrides):
|
||||
except Exception:
|
||||
request.protocol.logger.exception("Error handling request")
|
||||
return await overrides[500](request)
|
||||
finally:
|
||||
Session.remove()
|
||||
|
||||
return error_middleware
|
||||
|
||||
@@ -596,6 +596,7 @@ def log_startup(host, port) -> None:
|
||||
|
||||
print("\n".join(messages))
|
||||
|
||||
|
||||
def get_interface_ip(family: socket.AddressFamily) -> str:
|
||||
"""Get the IP address of an external interface. Used when binding to
|
||||
0.0.0.0 or ::1 to show a more useful URL.
|
||||
@@ -611,4 +612,4 @@ def get_interface_ip(family: socket.AddressFamily) -> str:
|
||||
except OSError:
|
||||
return "::1" if family == socket.AF_INET6 else "127.0.0.1"
|
||||
|
||||
return s.getsockname()[0] # type: ignore
|
||||
return s.getsockname()[0] # type: ignore
|
||||
Reference in new issue
Block a user