From 2ca2b5f87b8abb669e62f4f98f05cccac53b8cba Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Wed, 15 Dec 2021 06:11:05 -0800 Subject: [PATCH] update Signed-off-by: Jess Frazelle --- kittycad/api/file/file_convert.py | 4 ++ .../file/file_convert_with_base64_helper.py | 56 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 kittycad/api/file/file_convert_with_base64_helper.py diff --git a/kittycad/api/file/file_convert.py b/kittycad/api/file/file_convert.py index db2fa26e8..fcfdbbb90 100644 --- a/kittycad/api/file/file_convert.py +++ b/kittycad/api/file/file_convert.py @@ -114,12 +114,14 @@ def sync( async def asyncio_detailed( source_format: ValidFileTypes, output_format: ValidFileTypes, + content: bytes, *, client: AuthenticatedClient, ) -> Response[Union[Any, FileConversion]]: kwargs = _get_kwargs( source_format=source_format, output_format=output_format, + content=content, client=client, ) @@ -132,6 +134,7 @@ async def asyncio_detailed( async def asyncio( source_format: ValidFileTypes, output_format: ValidFileTypes, + content: bytes, *, client: AuthenticatedClient, ) -> Optional[Union[Any, FileConversion]]: @@ -141,6 +144,7 @@ async def asyncio( await asyncio_detailed( source_format=source_format, output_format=output_format, + content=content, client=client, ) ).parsed diff --git a/kittycad/api/file/file_convert_with_base64_helper.py b/kittycad/api/file/file_convert_with_base64_helper.py new file mode 100644 index 000000000..094f48bf7 --- /dev/null +++ b/kittycad/api/file/file_convert_with_base64_helper.py @@ -0,0 +1,56 @@ +from typing import Any, Dict, Optional, Union + +import httpx + +from ...client import AuthenticatedClient +from ...models.file_conversion import FileConversion +from ...models.valid_file_types import ValidFileTypes +from ...types import Response +from ...api.file.file_convert import sync as fc_sync, asyncio as fc_asyncio + +def sync( + source_format: ValidFileTypes, + output_format: ValidFileTypes, + content: bytes, + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, FileConversion]]: + """Convert a CAD file from one format to another. If the file being converted is larger than a certain size it will be performed asynchronously. This function automatically base64 encodes the request body and base64 decodes the request output.""" + + encoded = base64.b64encode(content) + + fc = fc_sync( + source_format=source_format, + output_format=output_format, + content=encoded, + client=client, + ) + + if fc.output != "": + fc.output = base64.b64decode(fc.output) + + return fc + + +async def asyncio( + source_format: ValidFileTypes, + output_format: ValidFileTypes, + content: bytes, + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, FileConversion]]: + """Convert a CAD file from one format to another. If the file being converted is larger than a certain size it will be performed asynchronously. This function automatically base64 encodes the request body and base64 decodes the request output.""" + + encoded = base64.b64encode(content) + + fc = await fc_asyncio_detailed( + source_format=source_format, + output_format=output_format, + content=encoded, + client=client, + ) + + if fc.output != "": + fc.output = base64.b64decode(fc.output) + + return fc