Skip to content

fix: Fixes #36#48

Open
r1thk4 wants to merge 8 commits intomerledu:mainfrom
r1thk4:fix-chunked-file-upload
Open

fix: Fixes #36#48
r1thk4 wants to merge 8 commits intomerledu:mainfrom
r1thk4:fix-chunked-file-upload

Conversation

@r1thk4
Copy link
Contributor

@r1thk4 r1thk4 commented Feb 5, 2026

Due to PyWebView GUI dependencies in WSL, I was unable to run the full UI locally. The changes were validated by tracing the upload flow from upload.html - uploadFile() - pywebview.api.save_file and implementing chunked handling accordingly. Please review and let me know if any adjustments are needed after testing.

Copy link
Collaborator

@Shehrozkashif Shehrozkashif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d suggest moving these changes into a separate JS file at frontend/script and removing the <script> tag from upload.html.

const arrayBuffer = await chunk.arrayBuffer();

const base64Chunk = await arrayBufferToBase64(arrayBuffer);
const result = await window.pywebview.api.save_file_chunk(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a guard to ensure the pywebview API exists before calling it. If the bridge fails to initialize, this will crash the upload instead of showing a helpful error.

offset += CHUNK_SIZE;
chunkIndex++;

const progress = Math.min((offset/file.size)*100, 100);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can produce floating-point percentages like 37.333333%. Please round to integers for cleaner UI.

frontend/main.py Outdated
except Exception as e:
return f"error: {str(e)}"

def save_file_chunk(self, filename, chunk_data, chunk_index, is_last):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a full docstring explaining purpose, parameters, side-effects, and return type

Comment on lines +1 to +6
//Define Maximum File Size as 50MB
const MAX_FILE_SIZE = 50 * 1024 * 1024;

//Define Upload Chunk Size as 1MB
const CHUNK_SIZE = 1024 * 1024;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct the indentation plz!

Comment on lines +67 to +71
if (!window.pywebview || !window.pywebview.api || typeof window.pywebview.api.save_file_chunk !== "function") {
alert("Upload service is not available. Please try again.");
resetUploadUI();
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct intendation !

@Shehrozkashif
Copy link
Collaborator

@r1thk4 I’d encourage you to add test coverage for your changes and extend the existing unit tests where applicable. Also, as a best practice, try to squash this into a single commit with a clear, detailed commit message describing the changes you made.

@Shehrozkashif Shehrozkashif force-pushed the main branch 2 times, most recently from 9858304 to 7f6e102 Compare February 10, 2026 10:41
@r1thk4
Copy link
Contributor Author

r1thk4 commented Feb 10, 2026

Thanks for the suggestion! I’ve updated the PR by fixing the formatting issues and adding unit tests for the changes.
I’ve also run the checks locally and they’re passing. Please let me know if everything looks good or if any further changes are needed.

@Shehrozkashif
Copy link
Collaborator

@r1thk4 Have you pulled the changes from main?

@r1thk4 r1thk4 force-pushed the fix-chunked-file-upload branch from c797aab to fff4928 Compare February 11, 2026 11:25
@r1thk4
Copy link
Contributor Author

r1thk4 commented Feb 11, 2026

After rebasing this branch onto the latest main, I’m seeing a test failure in evaluate_classifier related to handling empty inputs.

It looks similar to an issue that was previously addressed, but the empty-input guard doesn’t seem to be present in the current main.

Could you please advise on the best way to proceed? I’m happy to either open a separate PR to address it or include the fix in this branch to keep CI passing.

@Shehrozkashif
Copy link
Collaborator

@r1thk4 The CI failure you’re seeing isn’t caused by your upload changes. It’s happening because frontend.main imports pywebview, which isn’t available in the headless CI environment. When pytest imports that module, it crashes before tests even run.

To keep tests independent from GUI dependencies, please make the webview import optional in frontend/main.py, e.g.:

try:
    import webview
except ImportError:
    webview = None

This allows CI to run without requiring GUI libraries while keeping the app functional locally.

Regarding the empty-input issue you noticed after rebasing: good catch. Let’s keep this PR focused on the upload feature. If the classifier bug still exists on main, please open a small separate PR to fix it that’ll make review and history cleaner.

Once the optional import change is in, CI should pass and we can move forward with merging.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants