Skip to content

Fix gokapi-cli download and add E2E download support#365

Merged
Forceu merged 4 commits intoForceu:masterfrom
Upellift99:fix/cli-download-and-e2e
Feb 15, 2026
Merged

Fix gokapi-cli download and add E2E download support#365
Forceu merged 4 commits intoForceu:masterfrom
Upellift99:fix/cli-download-and-e2e

Conversation

@Upellift99
Copy link
Contributor

Summary

  • Fix silent exit code 2: gokapi-cli download --id XXX silently exited with code 2 without making any network call. The checkRequiredUploadParameter function had no return true path for valid download mode, causing execution to fall through to upload/Docker validation logic.
  • Fix empty file left on disk: When a download HTTP request failed (e.g. 502), an empty file was left on disk because os.Create was called before the HTTP request. Reordered to create the file only after a successful response, and added cleanup on streaming errors.
  • Fix server crash on API file download with S3 storage: serveDecryptedFile unconditionally called encryption.DecryptReader() even for non-encrypted files, causing crypto/aes: invalid key size 0 panic that killed the server process (via log.Fatal in the encryption chain). Added IsEncrypted check and IsDecryptionAvailable() guard.
  • Add E2E encrypted file download support: End-to-end encrypted files could not be downloaded via the CLI. The server API now serves E2E files as raw encrypted bytes (instead of rejecting them), and the CLI retrieves the per-file decryption key from /api/e2e/get, then decrypts in streaming during download.

Test plan

  • Download a non-encrypted file via CLI
  • Download a server-side encrypted file via CLI
  • Download an E2E encrypted file via CLI — file is correctly decrypted with the real filename
  • Verify no empty file is left on disk when download fails
  • Verify server does not crash on any download type

🤖 Generated with Claude Code

Upellift99 and others added 4 commits February 14, 2026 17:46
checkRequiredUploadParameter had no return true path for a valid download
command. When --id was provided, execution fell through to the upload/Docker
logic which returned false, triggering os.Exit(2) with no output.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move HTTP request before file creation so no file is left behind on
server errors (502, 404, etc.). Also clean up partial files on
streaming errors and fix defer placement on os.Create.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
serveDecryptedFile unconditionally called encryption.DecryptReader even
for non-encrypted files, causing crypto/aes: invalid key size 0 panic
that crashed the entire process. Only decrypt when the file is actually
encrypted, matching the existing behavior in Stream().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Server: remove E2E download rejection from API and serve encrypted bytes
without server-side decryption for E2E files. Add IsDecryptionAvailable
guard to prevent server crash on encrypted files with missing master key.

CLI: detect E2E files, retrieve per-file cipher from /api/e2e/get,
restore the real filename, and decrypt in streaming using the E2E key.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Forceu
Copy link
Owner

Forceu commented Feb 14, 2026

Hi please state what percentage of the code was generated with AI

@Upellift99
Copy link
Contributor Author

Hi, thanks for the quick reply, and thanks for Gokapi! it's a great project 👍

The code changes were written with AI assistance (Claude), as reflected by the Co-Authored-By tag on each commit. I identified the bugs during real usage, directed the investigation and fixes, and tested everything manually on my setup (Docker + S3 + Nginx reverse proxy). The AI helped with navigating the codebase and writing the actual patches.

I'd estimate the code writing itself was ~90% AI-assisted, but the debugging direction and testing was all manual.

@Forceu
Copy link
Owner

Forceu commented Feb 14, 2026

Thanks for the info, I will have a look at it in the next couple of days

@Forceu Forceu merged commit 8d562fd into Forceu:master Feb 15, 2026
1 check passed
@Forceu
Copy link
Owner

Forceu commented Feb 15, 2026

Thanks a lot for your contribution! The issues you mentioned had been unnoticed by me and had no code coverage yet.
I will probably try to add more unit tests in the coming weeks to prevent these kind of bugs. :)

@Upellift99
Copy link
Contributor Author

You're welcome, glad I could help! I hit these bugs while using Gokapi in production, so fixing them upstream felt like the natural thing to do.

I won't be much help on the unit testing side, but I do a fair amount of real-world testing on my setup — happy to report anything I find along the way. Great project, keep it up! 🙏

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