-
-
Notifications
You must be signed in to change notification settings - Fork 402
Support Range requests for multi-file ROM downloads #3167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tmgast
wants to merge
8
commits into
rommapp:master
Choose a base branch
from
tmgast:fix/mod-zip-range-requests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0273d58
Support Range requests for multi-file ROM downloads
tmgast 476f3ef
Add tests, fix streaming write and code standards
tmgast 18864a5
Add bulk download caching, LRU eviction, tiered TTL
tmgast 4ffa94c
Fix mypy method-assign in cleanup task test
tmgast 3f47af1
Work around zipfile monkey-patch breaking writestr on CPython 3.13
tmgast 6ffb8ac
Address Copilot review feedback
tmgast 10f3b25
Merge branch 'master' into fix/mod-zip-range-requests
gantoine 462cdb1
run fmt
gantoine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| from logger.logger import log | ||
| from tasks.tasks import PeriodicTask, TaskType | ||
| from utils.zip_cache import cleanup_stale_zips | ||
|
|
||
|
|
||
| class CleanupZipCacheTask(PeriodicTask): | ||
| def __init__(self): | ||
| super().__init__( | ||
| title="Scheduled ZIP cache cleanup", | ||
| description="Removes stale cached ZIP files based on tiered TTL", | ||
| task_type=TaskType.CLEANUP, | ||
| enabled=True, | ||
| manual_run=False, | ||
| cron_string="0 4 * * *", | ||
| func="tasks.scheduled.cleanup_zip_cache.cleanup_zip_cache_task.run", | ||
| ) | ||
|
|
||
| async def run(self) -> None: | ||
| if not self.enabled: | ||
| self.unschedule() | ||
| return | ||
|
|
||
| deleted = cleanup_stale_zips() | ||
| if deleted: | ||
| log.info(f"Cleaned up {deleted} stale cached ZIP files") | ||
|
|
||
|
|
||
| cleanup_zip_cache_task = CleanupZipCacheTask() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| from unittest.mock import MagicMock | ||
|
|
||
| from tasks.scheduled.cleanup_zip_cache import CleanupZipCacheTask | ||
|
|
||
|
|
||
| class TestCleanupZipCacheTask: | ||
| def test_configuration(self): | ||
| task = CleanupZipCacheTask() | ||
| assert task.enabled is True | ||
| assert task.cron_string == "0 4 * * *" | ||
| assert "cleanup_zip_cache" in task.func | ||
|
|
||
| async def test_run_calls_cleanup(self, mocker): | ||
| task = CleanupZipCacheTask() | ||
| mock_cleanup = mocker.patch( | ||
| "tasks.scheduled.cleanup_zip_cache.cleanup_stale_zips", | ||
| return_value=3, | ||
| ) | ||
| await task.run() | ||
| mock_cleanup.assert_called_once_with() | ||
|
|
||
| async def test_run_disabled_unschedules(self, mocker): | ||
| task = CleanupZipCacheTask() | ||
| task.enabled = False | ||
| mocker.patch.object(task, "unschedule", MagicMock()) | ||
| mock_cleanup = mocker.patch( | ||
| "tasks.scheduled.cleanup_zip_cache.cleanup_stale_zips", | ||
| ) | ||
| await task.run() | ||
| mock_cleanup.assert_not_called() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| from unittest.mock import MagicMock | ||
|
|
||
| from utils.m3u import generate_m3u_content | ||
|
|
||
|
|
||
| def _make_file(name: str, extension: str, download_name: str | None = None): | ||
| f = MagicMock() | ||
| f.file_extension = extension | ||
| f.file_name_for_download.return_value = download_name or name | ||
| return f | ||
|
|
||
|
|
||
| class TestGenerateM3uContent: | ||
| def test_single_file(self): | ||
| files = [_make_file("game.bin", "bin")] | ||
| result = generate_m3u_content(files, hidden_folder=False) | ||
| assert result == b"game.bin" | ||
| files[0].file_name_for_download.assert_called_once_with(False) | ||
|
|
||
| def test_multiple_files(self): | ||
| files = [ | ||
| _make_file("disc1.chd", "chd"), | ||
| _make_file("disc2.chd", "chd"), | ||
| _make_file("disc3.chd", "chd"), | ||
| ] | ||
| result = generate_m3u_content(files, hidden_folder=False) | ||
| assert result == b"disc1.chd\ndisc2.chd\ndisc3.chd" | ||
|
|
||
| def test_cue_files_preferred_over_bin(self): | ||
| files = [ | ||
| _make_file("track01.bin", "bin"), | ||
| _make_file("track02.bin", "bin"), | ||
| _make_file("game.cue", "cue"), | ||
| ] | ||
| result = generate_m3u_content(files, hidden_folder=False) | ||
| assert result == b"game.cue" | ||
|
|
||
| def test_cue_case_insensitive(self): | ||
| files = [ | ||
| _make_file("track.bin", "bin"), | ||
| _make_file("game.CUE", "CUE", download_name="game.CUE"), | ||
| ] | ||
| result = generate_m3u_content(files, hidden_folder=False) | ||
| assert result == b"game.CUE" | ||
|
|
||
| def test_hidden_folder_passed_through(self): | ||
| files = [_make_file("game.chd", "chd", download_name=".hidden/game.chd")] | ||
| result = generate_m3u_content(files, hidden_folder=True) | ||
| assert result == b".hidden/game.chd" | ||
| files[0].file_name_for_download.assert_called_once_with(True) | ||
|
|
||
| def test_no_cue_files_lists_all(self): | ||
| files = [ | ||
| _make_file("disc1.chd", "chd"), | ||
| _make_file("disc2.chd", "chd"), | ||
| ] | ||
| result = generate_m3u_content(files, hidden_folder=False) | ||
| lines = result.decode().split("\n") | ||
| assert len(lines) == 2 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.