Skip to content

Commit

Permalink
Amend Hondana http internals to only send auth headers to endpoints e…
Browse files Browse the repository at this point in the history
…xplicitly requiring it (#45)

* change hondana to only authenticate when the endpoint requires it

* remove CustomRoute from docs to match prior cleanup

* fix documentation entry on now removed CustomRoute

* add another test to check new method of requiring auth at http request level
  • Loading branch information
AbstractUmbra authored Oct 3, 2024
1 parent 60968b8 commit 1269b05
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 138 deletions.
3 changes: 0 additions & 3 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,6 @@ Utilities
.. autoclass:: hondana.utils.Route
:members:

.. autoclass:: hondana.utils.CustomRoute
:members:

.. autoclass:: hondana.utils.MANGADEX_TIME_REGEX
:members:

Expand Down
21 changes: 13 additions & 8 deletions hondana/chapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
from .user import User
from .utils import (
MISSING,
CustomRoute,
RelationshipResolver,
Route,
as_chunks,
Expand Down Expand Up @@ -571,10 +570,10 @@ async def _pages(
_pages = at_home_data.data_saver if data_saver else at_home_data.data
_actual_pages = _pages[start:] if end is None else _pages[start:end]
for i, url in enumerate(_actual_pages, start=1):
route = CustomRoute(
route = Route(
"GET",
self._at_home_url,
f"/{'data-saver' if data_saver else 'data'}/{at_home_data.hash}/{url}",
base=self._at_home_url,
)
LOGGER.debug("Attempting to download: %s", route.url)
_start = time.monotonic()
Expand Down Expand Up @@ -895,7 +894,7 @@ def __repr__(self) -> str:
return f"<ChapterUpload id={self.upload_session_id!r} current_uploads={len(self.uploaded)}>"

async def _check_for_session(self) -> None:
route = Route("GET", "/upload")
route = Route("GET", "/upload", authenticate=True)
try:
data: GetUploadSessionResponse = await self._http.request(route)
except NotFound:
Expand Down Expand Up @@ -968,7 +967,7 @@ async def upload_images(
If ``sorting_key`` is provided, then it must be a callable that takes a single parameter of ``pathlib.Path`` and returns a sortable value.
This means that the return value of ``sorting_key`` must be richly comparable, with ``__lt__`` and ``__gt__``.
"""
route = Route("POST", "/upload/{session_id}", session_id=self.upload_session_id)
route = Route("POST", "/upload/{session_id}", session_id=self.upload_session_id, authenticate=True)
success: list[UploadedChapterResponse] = []

if sort:
Expand Down Expand Up @@ -1018,11 +1017,17 @@ async def delete_images(self, image_ids: list[str], /) -> None:
"""
if len(image_ids) == 1:
image_id = image_ids[0]
route = Route("DELETE", "/upload/{session_id}/{image_id}", session_id=self.upload_session_id, image_id=image_id)
route = Route(
"DELETE",
"/upload/{session_id}/{image_id}",
session_id=self.upload_session_id,
image_id=image_id,
authenticate=True,
)
await self._http.request(route)
return

route = Route("DELETE", "/upload/{session_id}/batch", session_id=self.upload_session_id)
route = Route("DELETE", "/upload/{session_id}/batch", session_id=self.upload_session_id, authenticate=True)
await self._http.request(route, json=image_ids)

if self.uploaded:
Expand Down Expand Up @@ -1073,7 +1078,7 @@ async def commit(self) -> Chapter:
if self.publish_at:
payload["chapterDraft"]["publishAt"] = clean_isoformat(self.publish_at)

route = Route("POST", "/upload/{session_id}/commit", session_id=self.upload_session_id)
route = Route("POST", "/upload/{session_id}/commit", session_id=self.upload_session_id, authenticate=True)
data: GetSingleChapterResponse = await self._http.request(route, json=payload)

self.__committed = True
Expand Down
Loading

0 comments on commit 1269b05

Please sign in to comment.