-
Notifications
You must be signed in to change notification settings - Fork 0
feat(hoster): resolve MediaFire, PixelDrain and Gofile downloads #172
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5d420fa
test(hoster): define MAT-133 acceptance coverage
mpiton 08289cc
feat(hoster): resolve direct sources before download
mpiton 4cc643a
test(hoster): cover adversarial resolution cases
mpiton 9428b51
fix(hoster): harden protected source lifecycle
mpiton eb11340
fix: address PR review comments
mpiton 52ad861
fix: address PR review comments
mpiton 1d9352d
fix: address PR review comments
mpiton 54cfb1e
fix: address PR review comments
mpiton 1b6433c
fix: address PR review comments
mpiton 96bc775
fix: address PR review comments
mpiton 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
Some comments aren't visible on the classic Files Changed page.
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
121 changes: 121 additions & 0 deletions
121
src-tauri/src/adapters/driven/network/download_artifact_lifecycle.rs
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,121 @@ | ||
| use std::path::Path; | ||
| use std::sync::Arc; | ||
|
|
||
| use crate::domain::error::DomainError; | ||
| use crate::domain::model::download::DownloadId; | ||
| use crate::domain::model::meta::DownloadMeta; | ||
| use crate::domain::ports::driven::FileStorage; | ||
|
|
||
| pub(super) struct AttemptFailure { | ||
| pub(super) message: String, | ||
| pub(super) owns_artifacts: bool, | ||
| pub(super) retryable_with_mirror: bool, | ||
| } | ||
|
|
||
| pub(super) enum AttemptOutcome { | ||
| Completed, | ||
| Cancelled, | ||
| Failed(AttemptFailure), | ||
| } | ||
|
|
||
| impl AttemptFailure { | ||
| pub(super) fn retryable(message: String, owns_artifacts: bool) -> Self { | ||
| Self { | ||
| message, | ||
| owns_artifacts, | ||
| retryable_with_mirror: true, | ||
| } | ||
| } | ||
|
|
||
| pub(super) fn terminal(message: String, owns_artifacts: bool) -> Self { | ||
| Self { | ||
| message, | ||
| owns_artifacts, | ||
| retryable_with_mirror: false, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub(super) fn resume_metadata_matches( | ||
| metadata: &DownloadMeta, | ||
| download_id: DownloadId, | ||
| stable_url: &str, | ||
| destination: &Path, | ||
| total_size: u64, | ||
| ) -> bool { | ||
| let filename_matches = destination | ||
| .file_name() | ||
| .and_then(|name| name.to_str()) | ||
| .is_some_and(|filename| metadata.file_name == filename); | ||
| let size_matches = total_size == 0 || metadata.total_bytes == Some(total_size); | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
Outdated
|
||
| metadata.download_id == download_id | ||
| && metadata.url == stable_url | ||
| && filename_matches | ||
| && size_matches | ||
| } | ||
|
|
||
| pub(super) fn ownership_metadata( | ||
| download_id: DownloadId, | ||
| stable_url: String, | ||
| destination: &Path, | ||
| total_size: u64, | ||
| ) -> DownloadMeta { | ||
| let now = std::time::SystemTime::now() | ||
| .duration_since(std::time::UNIX_EPOCH) | ||
| .map(|duration| duration.as_secs()) | ||
| .unwrap_or(0); | ||
| DownloadMeta { | ||
| download_id, | ||
| url: stable_url, | ||
| file_name: destination | ||
| .file_name() | ||
| .and_then(|name| name.to_str()) | ||
| .unwrap_or_default() | ||
| .to_string(), | ||
| total_bytes: (total_size > 0).then_some(total_size), | ||
| segments: Vec::new(), | ||
|
mpiton marked this conversation as resolved.
Outdated
|
||
| checksum_expected: None, | ||
| created_at: now, | ||
| updated_at: now, | ||
| } | ||
| } | ||
|
|
||
| pub(super) async fn cleanup_download_artifacts( | ||
| file_storage: &Arc<dyn FileStorage>, | ||
| dest_path: &Path, | ||
| ) -> Result<(), DomainError> { | ||
| let storage = file_storage.clone(); | ||
| let path = dest_path.to_path_buf(); | ||
| tokio::task::spawn_blocking(move || storage.delete_download_artifacts(&path)) | ||
| .await | ||
| .map_err(|_| DomainError::StorageError("download artifact cleanup stopped".into()))? | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| fn metadata(total_bytes: Option<u64>) -> DownloadMeta { | ||
| DownloadMeta { | ||
| download_id: DownloadId(7), | ||
| url: "https://example.com/file.bin".into(), | ||
| file_name: "file.bin".into(), | ||
| total_bytes, | ||
| segments: Vec::new(), | ||
| checksum_expected: None, | ||
| created_at: 0, | ||
| updated_at: 0, | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn unknown_remote_size_does_not_invalidate_same_owner_metadata() { | ||
| assert!(resume_metadata_matches( | ||
| &metadata(Some(42)), | ||
| DownloadId(7), | ||
| "https://example.com/file.bin", | ||
| Path::new("/tmp/file.bin"), | ||
| 0, | ||
| )); | ||
| } | ||
| } | ||
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.