@@ -106,18 +106,27 @@ def parse_folder_url(cls, url: str | yarl.URL) -> tuple[NodeID, str, NodeID | No
106106 return result .public_handle , result .public_key , result .selected_node
107107
108108 @staticmethod
109- def parse_url (url : str | yarl .URL ) -> PublicURLInfo :
110- """Parse a public URL"""
109+ def ensure_v2_url (url : str | yarl .URL ) -> yarl . URL :
110+ """Transform an URL in V1 format to v2 """
111111 url = yarl .URL (url )
112112 Site .MEGA .check_host (url )
113113 new_url = transform_v1_url (url )
114114 if new_url != url :
115115 logger .info (f"Transformed v1 URL from { url } to { new_url } " )
116+ return new_url
116117
117- url = new_url
118- if not url .fragment :
118+ @staticmethod
119+ def parse_url (url : str | yarl .URL , * , check_key : bool = True ) -> PublicURLInfo :
120+ """Parse a public URL"""
121+ url = MegaCore .ensure_v2_url (url )
122+ info = MegaCore ._parse_public_v2_url (url )
123+ if check_key and not info .public_key :
119124 raise ValidationError (f"Public key missing from { url } " )
125+ return info
120126
127+ @staticmethod
128+ def _parse_public_v2_url (url : yarl .URL , / ) -> PublicURLInfo :
129+ """Parse a public URL"""
121130 match url .parts [1 :]:
122131 case ["file" , public_handle ]:
123132 return PublicURLInfo (False , public_handle , url .fragment )
@@ -422,7 +431,7 @@ async def import_file(
422431 ) -> Node :
423432 """Import the public file into user account"""
424433 full_key = b64_to_a32 (public_key )
425- key = Crypto .decompose (full_key ).key
434+ key = Crypto .decompose (full_key ).key # pyright: ignore[reportArgumentType]
426435 file_info = await self .request_file_info (public_handle , is_public = True )
427436 name = self .decrypt_attrs (file_info ._at , key , public_handle ).name
428437 encrypted_key = a32_to_base64 (encrypt_key (full_key , self .vault .master_key ))
0 commit comments