Fix: bypass 512MB postMessage limit for file transfer and add file integrity checksum - #310
Merged
Merged
Conversation
LiuLikeQian
reviewed
May 11, 2026
| auto& server = wxGetApp().m_page_http_server; | ||
| std::string b64 = base64_encode(file_path.data(), file_path.size()); | ||
| for (auto& c : b64) { | ||
| if (c == '+') c = '-'; |
LiuLikeQian
reviewed
May 11, 2026
| std::string b64 = base64_encode(file_path.data(), file_path.size()); | ||
| for (auto& c : b64) { | ||
| if (c == '+') c = '-'; | ||
| else if (c == '/') c = '_'; |
LiuLikeQian
reviewed
May 11, 2026
| else if (c == '_') c = '/'; | ||
| } | ||
| // Pad to multiple of 4 for base64 decode | ||
| while (b64.size() % 4 != 0) b64 += '='; |
LiuLikeQian
reviewed
May 11, 2026
| // Decode URL-safe base64-encoded path: revert '-'→'+', '_'→'/', then pad | ||
| auto b64 = std::string(trimmed_url.substr(strlen(WCP_DOWNLOAD_PREFIX)).ToStdString(wxConvUTF8)); | ||
| for (auto& c : b64) { | ||
| if (c == '-') c = '+'; |
LiuLikeQian
reviewed
May 11, 2026
| auto b64 = std::string(trimmed_url.substr(strlen(WCP_DOWNLOAD_PREFIX)).ToStdString(wxConvUTF8)); | ||
| for (auto& c : b64) { | ||
| if (c == '-') c = '+'; | ||
| else if (c == '_') c = '/'; |
LiuLikeQian
reviewed
May 11, 2026
|
|
||
| // Convert UTF-8 path to filesystem encoding (auto-adapts for Windows UTF-8 mode). | ||
| // If m_native_path is true, the path is already in system encoding (e.g., from base64 decode). | ||
| std::string system_file_path = m_native_path ? file_path : utf8_to_filesystem_encoding(file_path); |
Collaborator
There was a problem hiding this comment.
on system langue setting to close utf8 support global language, and should pass for testing chinese path;
LiuLikeQian
reviewed
May 11, 2026
| std::ifstream file(system_file_path, std::ios::binary); | ||
| if (!file && m_native_path) { | ||
| // Native path failed; retry with UTF-8 → filesystem encoding conversion | ||
| system_file_path = utf8_to_filesystem_encoding(file_path); |
LiuLikeQian
reviewed
May 11, 2026
| static std::string calc_sha256_base64(const std::string& file_path) | ||
| { | ||
| std::ifstream ifs(file_path, std::ios::binary); | ||
| if (!ifs.is_open()) return ""; |
LiuLikeQian
reviewed
May 11, 2026
| std::string zipname = generate_zip_path(oriname, targetname); | ||
| json res = get_or_create_zip_json(oriname, targetname, zipname); | ||
| wxGetApp().CallAfter([weak_self, res]() { | ||
| if (!self) return; |
LiuLikeQian
reviewed
May 11, 2026
| if (name_index == std::string::npos || path_index == std::string::npos) { | ||
| wxGetApp().CallAfter([weak_self]() { | ||
| auto self = weak_self.lock(); | ||
| if (self) self->handle_general_fail(); |
LiuLikeQian
reviewed
May 11, 2026
| if (self) { | ||
| self->m_res_data["name"] = res["zip_name"]; | ||
| self->m_res_data["content"] = res["zip_data"]; | ||
| if (!self) return; |
LiuLikeQian
reviewed
May 11, 2026
| } catch (std::exception&) { | ||
| wxGetApp().CallAfter([weak_self]() { | ||
| auto self = weak_self.lock(); | ||
| if (self) self->handle_general_fail(); |
LiuLikeQian
reviewed
May 11, 2026
| self->handle_general_fail(); | ||
| return; | ||
| } | ||
| if (!self) return; |
Fix: remove try-catch blocks in sw_GetFileStream and refactor file path encoding in ResponseFile - SSWCP: Remove try-catch blocks added by PR Snapmaker#310 inside m_work_thread lambdas in sw_GetFileStream(), letting exceptions propagate naturally - HttpServer: Refactor ResponseFile::write_response to use m_native_path flag for encoding decision, with fallback to raw path when conversion fails @
LiuLikeQian
pushed a commit
that referenced
this pull request
May 22, 2026
…display (#360) * fix: downloadFileFromOrca fails when HTTP server port changes When the default port 13619 is occupied, the HTTP server switches to an alternative port. The C++ side correctly uses the dynamic port for loading the Flutter UI page, but sw_GetActiveFile() did not include the "url" field in its JSON response. The Flutter JS downloadFileFromOrca function falls back to a hardcoded http://127.0.0.1:13619/localfile/... when the url field is null, causing requests to time out. Fix: - Populate the "url" field with the actual port via get_page_http_port() in both the zip and non-zip branches of sw_GetActiveFile() - Normalize Windows backslash path separators to forward slashes - URL-encode the file path to handle spaces and non-ASCII characters consistently across all platforms * @ 1. Add download URL for file transfer, bypassing 512MB postMessage limit 2. Add checksum field for file integrity verification 3. Add origin_size field 4. Use URL-safe base64 for path encoding in /wcp_download/ route @ * @ Fix: remove in-memory fallback and magic number - Replace duplicated in-memory response logic with a simple retry using utf8_to_filesystem_encoding, then fall through to existing streaming path - Replace char buf[64*1024] with static constexpr + std::string @ * @ Fix: add missing line breaks for all if/else statements Ensure consistent code style by adding proper braces and line breaks to single-line if/else-if/else blocks across HttpServer.cpp and SSWCP.cpp. @ * @ Fix: add braces to single-line while statement @ * @ Fix: remove try-catch blocks in sw_GetFileStream and refactor file path encoding in ResponseFile - SSWCP: Remove try-catch blocks added by PR #310 inside m_work_thread lambdas in sw_GetFileStream(), letting exceptions propagate naturally - HttpServer: Refactor ResponseFile::write_response to use m_native_path flag for encoding decision, with fallback to raw path when conversion fails @ * Fix: bypass 512MB postMessage limit for file transfer and add file integrity checksum (#310) * @ 1. Add download URL for file transfer, bypassing 512MB postMessage limit 2. Add checksum field for file integrity verification 3. Add origin_size field 4. Use URL-safe base64 for path encoding in /wcp_download/ route @ * @ Fix: remove in-memory fallback and magic number - Replace duplicated in-memory response logic with a simple retry using utf8_to_filesystem_encoding, then fall through to existing streaming path - Replace char buf[64*1024] with static constexpr + std::string @ * @ Fix: add missing line breaks for all if/else statements Ensure consistent code style by adding proper braces and line breaks to single-line if/else-if/else blocks across HttpServer.cpp and SSWCP.cpp. @ * @ Fix: add braces to single-line while statement @ * @ Fix: remove try-catch blocks in sw_GetFileStream and refactor file path encoding in ResponseFile - SSWCP: Remove try-catch blocks added by PR #310 inside m_work_thread lambdas in sw_GetFileStream(), letting exceptions propagate naturally - HttpServer: Refactor ResponseFile::write_response to use m_native_path flag for encoding decision, with fallback to raw path when conversion fails @ * @ @ Add: cross-platform test scripts for port 13619 fallback verification @ * Fix: update Flutter web resources and SSWCP.cpp refinement - Replace Flutter web package with latest version from Flutter team - Update SSWCP.cpp with related adjustments * delete test case --------- Co-authored-by: YukiMacMini <yukimacmini@YukiMacMinideMac-mini.local>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR addresses the file transfer failure for files larger than ~512MB. Previously,
both sw_GetFileStream and sw_GetActiveFile read entire file content into memory and
passed it through the WebView postMessage bridge, which has a hard limit around 512MB.
Files exceeding this size get silently truncated.
Changes
sw_GetFileStream
sw_GetActiveFile
HttpServer
Checksum Algorithm
Tests