Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

New abortDownload function for downloadFile (#4157) #4438

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

Draft
MohabCodeX wants to merge 6 commits into multitheftauto:master
base: master
Choose a base branch
Loading
from MohabCodeX:feat/abort-download

Conversation

@MohabCodeX
Copy link
Contributor

@MohabCodeX MohabCodeX commented Sep 9, 2025
edited
Loading

Warning

(削除) This feature has not been fully tested. Please test thoroughly and report any issues or unexpected behaviors. Your feedback is highly appreciated (削除ここまで).

Sorry if I may have disappointed you, but this will take time and will need a different solution 🫠

New Functionality

  • abortDownload(handlerId)
    Cancels an ongoing download using a unique handler ID.

The function returns false in these cases:

  • Invalid handler ID (download doesn't exist)
  • Download already completed
  • Download already cancelled
  • HTTP cancellation failed
  • It returns true when the download was successfully cancelled.

Usage Example

local download, handlerId = downloadFile("file.txt")
-- ... later ...
local success = abortDownload(handlerId)

🛠️ Changes

  • Added download tracking using unique handler IDs.
  • Integrated proper cancellation logic with the HTTP manager.
  • Implemented input validation for both downloadFile and abortDownload.
  • memory safety and error handling throughout.

Breaking Changes

  • downloadFile() now returns two values (download object, handler ID) instead of a single boolean.

🔗 Resolves

Serius41, Wannacry-ops, ffsPLASMA, bum8hj, and Kinimel reacted with hooray emoji Kinimel reacted with rocket emoji
Copy link
Contributor

I think new feature PRs are on-hold for now. 1.7 release is waiting for fixes first

Either way, this is cool

MohabCodeX, Kinimel, and Fernando-A-Rocha reacted with thumbs up emoji MohabCodeX, Wannacry-ops, Kinimel, and Fernando-A-Rocha reacted with heart emoji

Copy link
Contributor

Thank you for adding this feature, much needed.
If it isnt too much work, could you also add something like:

local numBytesDownloaded, numTotalBytesToDownload = getDownloadProgress(downloadHandler);

Very good addition for UIs to display the download progress.

MohabCodeX, Kinimel, and Fernando-A-Rocha reacted with thumbs up emoji

Copy link
Contributor Author

The main problem is that practical usage is limited due to a fundamental issue with downloadFile.
Currently, downloadFile is blocking (synchronous), it halts script execution until the file is fully downloaded.
This prevents proper asynchronous handling and makes progress tracking ineffective during the actual download.

@MohabCodeX MohabCodeX marked this pull request as draft September 9, 2025 19:01
@FileEX FileEX added the enhancement New feature or request label Sep 13, 2025
Copy link
Contributor

How feasible would it be to create something like asyncDownloadFile function?

Copy link
Contributor

How feasible would it be to create something like asyncDownloadFile function?

Why not just make downloadFile not blocking? I think that wouldn't break scripts. It returns true if file to download was queued successfully - is this the slow operation?

Copy link
Contributor

How feasible would it be to create something like asyncDownloadFile function?

Why not just make downloadFile not blocking? I think that wouldn't break scripts. It returns true if file to download was queued successfully - is this the slow operation?

Yes I see no problem making downloadFile async in general. No one sane would put lua logic after downloadFile call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

enhancement New feature or request

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /