Skip to content

Commit 62f03d4

Browse files
committed
remove redirect params
1 parent 02b509a commit 62f03d4

File tree

1 file changed

+12
-31
lines changed

1 file changed

+12
-31
lines changed

synapseclient/models/wiki.py

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
WikiPageSynchronousProtocol,
4040
)
4141

42+
# File size threshold for using single-threaded vs multi-threaded download (8 MiB)
43+
SINGLE_THREAD_DOWNLOAD_SIZE_LIMIT = 8 * 1024 * 1024 # 8 MiB in bytes
44+
4245

4346
@dataclass
4447
@async_to_sync
@@ -146,6 +149,7 @@ async def get_async(
146149
"""
147150
if not self.owner_id:
148151
raise ValueError("Must provide owner_id to get wiki order hint.")
152+
149153
order_hint_dict = await get_wiki_order_hint(
150154
owner_id=self.owner_id,
151155
synapse_client=synapse_client,
@@ -554,7 +558,7 @@ async def task_of_uploading_attachment(attachment: str) -> tuple[str, str]:
554558
parent_entity_id=self.owner_id,
555559
path=file_path,
556560
)
557-
synapse_client.logger.info(
561+
synapse_client.logger.debug(
558562
f"Uploaded file handle {file_handle.get('id')} for wiki page attachment."
559563
)
560564
return file_handle.get("id")
@@ -851,11 +855,10 @@ async def get_attachment_handles_async(
851855
)
852856
async def get_attachment_async(
853857
self,
854-
file_name: str,
855858
*,
859+
file_name: str,
856860
download_file: bool = True,
857861
download_location: Optional[str] = None,
858-
redirect: Optional[bool] = False,
859862
synapse_client: Optional["Synapse"] = None,
860863
) -> Union[str, None]:
861864
"""
@@ -865,7 +868,6 @@ async def get_attachment_async(
865868
file_name: The name of the file to get.
866869
download_file: Whether associated files should be downloaded. Default is True.
867870
download_location: The directory to download the file to. Required if download_file is True.
868-
redirect: When set to false, the URL will be returned as text/plain instead of redirecting. Default is False.
869871
synapse_client: Optionally provide a Synapse client.
870872
Returns:
871873
If download_file is True, the attachment file will be downloaded to the download_location. Otherwise, the URL will be returned.
@@ -885,7 +887,6 @@ async def get_attachment_async(
885887
wiki_id=self.id,
886888
file_name=file_name,
887889
wiki_version=self.wiki_version,
888-
redirect=redirect,
889890
synapse_client=client,
890891
)
891892

@@ -908,7 +909,7 @@ async def get_attachment_async(
908909
# check the file_size
909910
file_size = int(WikiPage._get_file_size(filehandle_dict, file_name))
910911
# use single thread download if file size < 8 MiB
911-
if file_size < 8388608:
912+
if file_size < SINGLE_THREAD_DOWNLOAD_SIZE_LIMIT:
912913
download_from_url(
913914
url=presigned_url_info.url,
914915
destination=download_location,
@@ -934,7 +935,6 @@ async def get_attachment_preview_async(
934935
*,
935936
download_file: bool = True,
936937
download_location: Optional[str] = None,
937-
redirect: Optional[bool] = False,
938938
synapse_client: Optional["Synapse"] = None,
939939
) -> Union[str, None]:
940940
"""
@@ -944,7 +944,6 @@ async def get_attachment_preview_async(
944944
file_name: The name of the file to get.
945945
download_file: Whether associated files should be downloaded. Default is True.
946946
download_location: The directory to download the file to. Required if download_file is True.
947-
redirect: When set to false, the URL will be returned as text/plain instead of redirecting. Default is False.
948947
synapse_client: Optionally provide a Synapse client.
949948
Returns:
950949
If download_file is True, the attachment preview file will be downloaded to the download_location. Otherwise, the URL will be returned.
@@ -964,7 +963,6 @@ async def get_attachment_preview_async(
964963
wiki_id=self.id,
965964
file_name=file_name,
966965
wiki_version=self.wiki_version,
967-
redirect=redirect,
968966
synapse_client=client,
969967
)
970968
# download the file if download_file is True
@@ -988,7 +986,7 @@ async def get_attachment_preview_async(
988986
# check the file_size
989987
file_size = int(WikiPage._get_file_size(filehandle_dict, file_name))
990988
# use single thread download if file size < 8 MiB
991-
if file_size < 8388608:
989+
if file_size < SINGLE_THREAD_DOWNLOAD_SIZE_LIMIT:
992990
download_from_url(
993991
url=presigned_url_info.url,
994992
destination=download_location,
@@ -997,11 +995,11 @@ async def get_attachment_preview_async(
997995
else:
998996
# download the file
999997
download_from_url_multi_threaded(
1000-
presigned_url=presigned_url_info.url, destination=download_location
1001-
)
1002-
client.logger.debug(
1003-
f"Downloaded the preview file {presigned_url_info.file_name} to {download_location}"
998+
presigned_url=presigned_url_info, destination=download_location
1004999
)
1000+
client.logger.debug(
1001+
f"Downloaded the preview file {presigned_url_info.file_name} to {download_location}"
1002+
)
10051003
else:
10061004
return attachment_preview_url
10071005

@@ -1014,7 +1012,6 @@ async def get_markdown_async(
10141012
download_file_name: Optional[str] = None,
10151013
download_file: bool = True,
10161014
download_location: Optional[str] = None,
1017-
redirect: Optional[bool] = False,
10181015
synapse_client: Optional["Synapse"] = None,
10191016
) -> Union[str, None]:
10201017
"""
@@ -1024,7 +1021,6 @@ async def get_markdown_async(
10241021
download_file_name: The name of the file to download. Required if download_file is True.
10251022
download_file: Whether associated files should be downloaded. Default is True.
10261023
download_location: The directory to download the file to. Required if download_file is True.
1027-
redirect: When set to false, the URL will be returned as text/plain instead of redirecting. Default is False.
10281024
synapse_client: Optionally provide a Synapse client.
10291025
Returns:
10301026
If download_file is True, the markdown file will be downloaded to the download_location. Otherwise, the URL will be returned.
@@ -1041,7 +1037,6 @@ async def get_markdown_async(
10411037
owner_id=self.owner_id,
10421038
wiki_id=self.id,
10431039
wiki_version=self.wiki_version,
1044-
redirect=redirect,
10451040
synapse_client=client,
10461041
)
10471042
# download the file if download_file is True
@@ -1067,17 +1062,3 @@ async def get_markdown_async(
10671062
)
10681063
else:
10691064
return markdown_url
1070-
1071-
@classmethod
1072-
def from_dict(
1073-
cls, synapse_wiki: Dict[str, Union[str, List[str], List[Dict[str, Any]]]]
1074-
) -> "WikiPage":
1075-
"""Create a new WikiPage instance from a dictionary.
1076-
1077-
Arguments:
1078-
synapse_wiki: The dictionary containing wiki page data.
1079-
1080-
Returns:
1081-
A new WikiPage instance filled with the dictionary data.
1082-
"""
1083-
return cls().fill_from_dict(synapse_wiki)

0 commit comments

Comments
 (0)