Skip to content

Commit ea0ebcd

Browse files
committed
fix: Add support for categories in upload
1 parent 8f34c4f commit ea0ebcd

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

pylookyloo/api.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,8 @@ def upload_capture(self, *, quiet: Literal[True],
678678
har: Path | BytesIO | str | None = None,
679679
html: Path | BytesIO | str | None = None,
680680
last_redirected_url: str | None = None,
681-
screenshot: Path | BytesIO | str | None = None) -> str:
681+
screenshot: Path | BytesIO | str | None = None,
682+
categories: list[str] | None=None) -> str:
682683
...
683684

684685
@overload
@@ -688,7 +689,8 @@ def upload_capture(self, *, quiet: Literal[False]=False,
688689
har: Path | BytesIO | str | None = None,
689690
html: Path | BytesIO | str | None = None,
690691
last_redirected_url: str | None = None,
691-
screenshot: Path | BytesIO | str | None = None) -> tuple[str, dict[str, str]]:
692+
screenshot: Path | BytesIO | str | None = None,
693+
categories: list[str] | None=None) -> tuple[str, dict[str, str]]:
692694
...
693695

694696
def upload_capture(self, *, quiet: bool = False,
@@ -697,7 +699,8 @@ def upload_capture(self, *, quiet: bool = False,
697699
har: Path | BytesIO | str | None = None,
698700
html: Path | BytesIO | str | None = None,
699701
last_redirected_url: str | None = None,
700-
screenshot: Path | BytesIO | str | None = None) -> str | tuple[str, dict[str, str]]:
702+
screenshot: Path | BytesIO | str | None = None,
703+
categories: list[str] | None=None) -> str | tuple[str, dict[str, str]]:
701704
'''Upload a capture via har-file and others
702705
703706
:param quiet: Returns the UUID only, instead of the the UUID and the potential error / warning messages
@@ -707,6 +710,7 @@ def upload_capture(self, *, quiet: bool = False,
707710
:param html: rendered HTML of the capture
708711
:param last_redirected_url: The landing page of the capture
709712
:param screenshot: Screenshot of the capture
713+
:param categories: The categories assigned to the capture
710714
'''
711715
def encode_document(document: Path | BytesIO | str) -> str:
712716
if isinstance(document, str):
@@ -719,6 +723,8 @@ def encode_document(document: Path | BytesIO | str) -> str:
719723
return base64.b64encode(document.getvalue()).decode()
720724

721725
to_send: dict[str, Any] = {'listing': listing}
726+
if categories:
727+
to_send['categories'] = categories
722728

723729
if full_capture:
724730
b64_full_capture = encode_document(full_capture)
@@ -740,9 +746,13 @@ def encode_document(document: Path | BytesIO | str) -> str:
740746
else:
741747
raise PyLookylooError("Full capture or at least har-file are required")
742748

743-
r = self.session.post(urljoin(self.root_url, str(PurePosixPath('json', 'upload'))), json=to_send)
744-
r.raise_for_status()
745-
json_response = r.json()
749+
try:
750+
r = self.session.post(urljoin(self.root_url, str(PurePosixPath('json', 'upload'))), json=to_send)
751+
r.raise_for_status()
752+
json_response = r.json()
753+
except Exception as e:
754+
raise PyLookylooError(f'Unable to upload capture: {e}.')
755+
746756
uuid = json_response['uuid']
747757
messages = json_response['messages']
748758

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "pylookyloo"
3-
version = "1.36.1"
3+
version = "1.36.2"
44
description = "Python CLI and module for Lookyloo"
55
authors = [
66
{name="Raphaël Vinot", email="raphael.vinot@circl.lu"}

0 commit comments

Comments
 (0)