Skip to content

Commit

Permalink
fix:115支持Cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Nov 20, 2024
1 parent b1b980f commit 8d5e0b2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/modules/filemanager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def save_config(self, storage: str, conf: Dict) -> None:
return
storage_oper.set_config(conf)

def generate_qrcode(self, storage: str) -> Optional[Dict[str, str]]:
def generate_qrcode(self, storage: str) -> Optional[Tuple[dict, str]]:
"""
生成二维码
"""
Expand Down
4 changes: 2 additions & 2 deletions app/modules/filemanager/storages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import ABCMeta, abstractmethod
from pathlib import Path
from typing import Optional, List, Union, Dict
from typing import Optional, List, Union, Dict, Tuple

from app import schemas
from app.helper.storage import StorageHelper
Expand All @@ -16,7 +16,7 @@ class StorageBase(metaclass=ABCMeta):
def __init__(self):
self.storagehelper = StorageHelper()

def generate_qrcode(self, *args, **kwargs) -> Optional[Dict[str, str]]:
def generate_qrcode(self, *args, **kwargs) -> Optional[Tuple[dict, str]]:
pass

def check_login(self, *args, **kwargs) -> Optional[Dict[str, str]]:
Expand Down
18 changes: 9 additions & 9 deletions app/modules/filemanager/storages/u115.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ def __init_cloud(self, force: bool = False) -> bool:
"""
try:
if not self.client or not self.client.cookies or force:
self.client = P115Client(self.__credential,
check_for_relogin=True, app="alipaymini", console_qrcode=False)
self.client = P115Client(self.__credential, app="alipaymini")
self.fs = P115FileSystem(self.client)
except Exception as err:
logger.error(f"115连接失败,请重新扫码登录{str(err)}")
logger.error(f"115连接失败,请重新登录{str(err)}")
self.__clear_credential()
return False
return True
Expand All @@ -54,8 +53,7 @@ def __credential(self) -> Optional[str]:
return None
if not conf.config:
return None
# 将dict转换为cookie字符串格式
return "; ".join([f"{k}={v}" for k, v in conf.config.items()])
return conf.config.get("cookie")

def __save_credential(self, credential: dict):
"""
Expand All @@ -73,15 +71,14 @@ def generate_qrcode(self) -> Optional[Tuple[dict, str]]:
"""
生成二维码
"""
if not self.__init_cloud():
return None
self.__init_cloud()
try:
resp = self.client.login_qrcode_token()
self.session_info = resp["data"]
qrcode_content = self.session_info.pop("qrcode")
if not qrcode_content:
logger.warn("115生成二维码失败:未获取到二维码数据!")
return None
return {}, ""
return {
"codeContent": qrcode_content
}, ""
Expand Down Expand Up @@ -114,7 +111,10 @@ def check_login(self) -> Optional[Tuple[dict, str]]:
app="alipaymini")
if resp:
# 保存认证信息
self.__save_credential(resp["data"]["cookie"])
cookie_dict = resp["data"]["cookie"]
cookie_str = "; ".join([f"{k}={v}" for k, v in cookie_dict.items()])
cookie_dict.update({"cookie": cookie_str})
self.__save_credential(cookie_dict)
self.__init_cloud(force=True)
result = {
"status": 2,
Expand Down

0 comments on commit 8d5e0b2

Please sign in to comment.