Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "async-mega.py"
authors = [{name = "NTFSvolume", email = "NTFSvolume@proton.me"}]
classifiers = [
"Development Status :: 4 - Beta",
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Framework :: AsyncIO",
"Intended Audience :: Developers",
Expand Down Expand Up @@ -34,7 +34,7 @@ license = "Apache-2.0"
license-files = ["LICENSE"]
readme = "README.md"
requires-python = ">=3.11"
version = "2.4.0"
version = "2.4.1"

[project.optional-dependencies]
cli = [
Expand Down Expand Up @@ -123,7 +123,7 @@ requires = ["uv_build<=0.10.11"]

[dependency-groups]
dev = [
"prek>=0.3.6",
"prek>=0.4.0",
"pytest-asyncio>=0.25.0",
"pytest>=8.3.5",
"ruff==0.15.6"
Expand Down
19 changes: 14 additions & 5 deletions src/mega/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,27 @@ def parse_folder_url(cls, url: str | yarl.URL) -> tuple[NodeID, str, NodeID | No
return result.public_handle, result.public_key, result.selected_node

@staticmethod
def parse_url(url: str | yarl.URL) -> PublicURLInfo:
"""Parse a public URL"""
def ensure_v2_url(url: str | yarl.URL) -> yarl.URL:
"""Transform an URL in V1 format to v2"""
url = yarl.URL(url)
Site.MEGA.check_host(url)
new_url = transform_v1_url(url)
if new_url != url:
logger.info(f"Transformed v1 URL from {url} to {new_url}")
return new_url

url = new_url
if not url.fragment:
@staticmethod
def parse_url(url: str | yarl.URL, *, check_key: bool = True) -> PublicURLInfo:
"""Parse a public URL"""
url = MegaCore.ensure_v2_url(url)
info = MegaCore._parse_public_v2_url(url)
if check_key and not info.public_key:
raise ValidationError(f"Public key missing from {url}")
return info

@staticmethod
def _parse_public_v2_url(url: yarl.URL, /) -> PublicURLInfo:
"""Parse a public URL"""
match url.parts[1:]:
case ["file", public_handle]:
return PublicURLInfo(False, public_handle, url.fragment)
Expand Down Expand Up @@ -422,7 +431,7 @@ async def import_file(
) -> Node:
"""Import the public file into user account"""
full_key = b64_to_a32(public_key)
key = Crypto.decompose(full_key).key
key = Crypto.decompose(full_key).key # pyright: ignore[reportArgumentType]
file_info = await self.request_file_info(public_handle, is_public=True)
name = self.decrypt_attrs(file_info._at, key, public_handle).name
encrypted_key = a32_to_base64(encrypt_key(full_key, self.vault.master_key))
Expand Down
40 changes: 20 additions & 20 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading