Skip to content

Commit

Permalink
Support for the video content type
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed May 31, 2023
1 parent 3c27d72 commit 932aaaf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/h_vialib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class ContentType(str, Enum):
PDF = "pdf"
HTML = "html"
VIDEO = "video"


class ViaDoc:
Expand Down Expand Up @@ -102,8 +103,12 @@ def _url_for(self, doc, query):
if self._service_url is None:
raise ValueError("Cannot rewrite URLs without a service URL")

# Optimisation to skip routing for documents we know are PDFs
path = "/pdf" if doc.content_type == ContentType.PDF else "/route"
# Optimisation to skip routing for documents we know the type of
content_type_paths = {
ContentType.PDF: "/pdf",
ContentType.VIDEO: "/video",
}
path = content_type_paths.get(doc.content_type, "/route")

query["url"] = doc.url

Expand Down
4 changes: 3 additions & 1 deletion tests/unit/h_vialib/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class TestViaClient:
"via.external_link_mode": "new-tab",
}

@pytest.mark.parametrize("content_type,path", ((None, "/route"), ("pdf", "/pdf")))
@pytest.mark.parametrize(
"content_type,path", ((None, "/route"), ("pdf", "/pdf"), ("video", "/video"))
)
def test_url_for(self, client, content_type, path):
url = "http://example.com&a=1&a=2"

Expand Down

0 comments on commit 932aaaf

Please sign in to comment.