Skip to content

Commit

Permalink
fix: remove webview_novel raw param
Browse files Browse the repository at this point in the history
  • Loading branch information
asadahimeka committed Mar 9, 2024
1 parent 9408dea commit 634758d
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions hibiapi/api/pixiv/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from hibiapi.utils.cache import cache_config
from hibiapi.utils.decorators import enum_auto_doc
from hibiapi.utils.net import catch_network_error
from hibiapi.utils.routing import BaseEndpoint, dont_route, request_headers, response_headers
from hibiapi.utils.routing import BaseEndpoint, dont_route, request_headers


@enum_auto_doc
Expand Down Expand Up @@ -483,7 +483,7 @@ async def novel_text(self, *, id: int):
return {"novel_text": response["text"] or ""}

Check warning on line 483 in hibiapi/api/pixiv/api.py

View check run for this annotation

Codecov / codecov/patch

hibiapi/api/pixiv/api.py#L483

Added line #L483 was not covered by tests

# 获取小说 HTML 后解析 JSON
async def webview_novel(self, *, id: int, raw: bool = False):
async def webview_novel(self, *, id: int):
response = await self.request(
"webview/v2/novel",
params={
Expand All @@ -492,18 +492,12 @@ async def webview_novel(self, *, id: int, raw: bool = False):
},
return_text=True,
)
if raw:
# 直接返回 HTML
response_headers.get().setdefault("content-type", "text/html; charset=UTF-8")
return response

try:
novel_json = (
re.search(r"novel:\s({.+}),\s+isOwnWork", response).groups()[0].encode()
)
return json.loads(novel_json)
except Exception as e:
return {"error": "Parsing novel error: %s" % e}

novel_match = re.search(r"novel:\s({.+}),\s+isOwnWork", response)

Check failure on line 496 in hibiapi/api/pixiv/api.py

View workflow job for this annotation

GitHub Actions / Lint Code

No overloads for "search" match the provided arguments (reportCallIssue)

Check failure on line 496 in hibiapi/api/pixiv/api.py

View workflow job for this annotation

GitHub Actions / Lint Code

Argument of type "Dict[str, Any]" cannot be assigned to parameter "string" of type "str" in function "search"   "Dict[str, Any]" is incompatible with "str" (reportArgumentType)
if not novel_match:
return json.loads(response)

Check failure on line 498 in hibiapi/api/pixiv/api.py

View workflow job for this annotation

GitHub Actions / Lint Code

Argument of type "Dict[str, Any]" cannot be assigned to parameter "s" of type "str | bytes | bytearray" in function "loads"   Type "Dict[str, Any]" cannot be assigned to type "str | bytes | bytearray"     "Dict[str, Any]" is incompatible with "str"     "Dict[str, Any]" is incompatible with "bytes"     "Dict[str, Any]" is incompatible with "bytearray" (reportArgumentType)

Check warning on line 498 in hibiapi/api/pixiv/api.py

View check run for this annotation

Codecov / codecov/patch

hibiapi/api/pixiv/api.py#L498

Added line #L498 was not covered by tests
novel_json = novel_match.groups()[0].encode()
return json.loads(novel_json)

@cache_config(ttl=timedelta(hours=12))
async def tags_novel(self):
Expand Down

0 comments on commit 634758d

Please sign in to comment.