Skip to content

Commit 928713c

Browse files
authored
优化代码,优化测试工作流触发条件,避免一些fork误触。 (#38)
1 parent 2e151cf commit 928713c

File tree

3 files changed

+40
-27
lines changed

3 files changed

+40
-27
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ on:
44
push:
55
branches: [ "dev", "master" ]
66
paths:
7-
- '.github/workflows/*.yml' # 工作流定义
8-
- 'usage/**/*.py' # 工作流脚本
97
- 'assets/config/*.yml' # option配置文件
108
- 'src/**/*.py' # 源码
119
- 'tests/**/*.py' # 测试代码

src/jmcomic/jm_client_impl.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,30 @@ def check_special_http_code(cls, code, url=None):
249249
class JmApiClient(AbstractJmClient):
250250
API_SEARCH = '/search'
251251

252-
def __init__(self,
253-
base_url,
254-
postman: Postman,
255-
retry_times=5,
256-
):
257-
super().__init__(postman, retry_times)
258-
self.base_url: str = base_url
259-
260252
def search_album(self, search_query: str, main_tag=0) -> JmApiResp:
253+
"""
254+
model_data: {
255+
"search_query": "MANA",
256+
"total": "177",
257+
"content": [
258+
{
259+
"id": "441923",
260+
"author": "MANA",
261+
"description": "",
262+
"name": "[MANA] 神里绫华5",
263+
"image": "",
264+
"category": {
265+
"id": "1",
266+
"title": "同人"
267+
},
268+
"category_sub": {
269+
"id": "1",
270+
"title": "同人"
271+
}
272+
}
273+
]
274+
}
275+
"""
261276
return self.get(
262277
self.API_SEARCH,
263278
params={

src/jmcomic/jm_client_interface.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,29 @@ def __init__(self, resp, key_ts):
6767
self.cache_decode_data = None
6868

6969
@staticmethod
70-
def parseData(text, time):
71-
import hashlib
70+
def parse_data(text, time) -> str:
71+
# 1. base64解码
7272
import base64
73-
from Crypto.Cipher import AES
74-
# key为时间+18comicAPPContent的md5结果
75-
key = hashlib.md5(f"{time}18comicAPPContent".encode()).hexdigest().encode()
76-
cipher = AES.new(key, AES.MODE_ECB)
77-
# 先将数据进行base64解码
7873
data = base64.b64decode(text)
79-
# 再进行AES-ECB解密
80-
paddedPlainText = cipher.decrypt(data)
81-
# 将得到的数据进行Utf8解码
82-
res = paddedPlainText.decode('utf-8')
83-
# 得到的数据再末尾有一些乱码
84-
i = len(res) - 1
85-
while i >= 0 and res[i] == '\x0c':
86-
i -= 1
87-
return res[:i + 1]
74+
75+
# 2. AES-ECB解密
76+
# key = 时间戳拼接 '18comicAPPContent' 的md5
77+
import hashlib
78+
key = hashlib.md5(f"{time}18comicAPPContent".encode("utf-8")).hexdigest().encode("utf-8")
79+
from Crypto.Cipher import AES
80+
data = AES.new(key, AES.MODE_ECB).decrypt(data)
81+
82+
# 3. 移除末尾的一些特殊字符
83+
data = data[:-data[-1]]
84+
85+
# 4. 解码为字符串 (json)
86+
res = data.decode('utf-8')
87+
return res
8888

8989
@property
9090
def decoded_data(self) -> str:
9191
if self.cache_decode_data is None:
92-
self.cache_decode_data = self.parseData(self.encoded_data, self.key_ts)
92+
self.cache_decode_data = self.parse_data(self.encoded_data, self.key_ts)
9393

9494
return self.cache_decode_data
9595

0 commit comments

Comments
 (0)