Skip to content

Download logic#4

Merged
sumanthd032 merged 5 commits into
mainfrom
download-logic
Feb 12, 2026
Merged

Download logic#4
sumanthd032 merged 5 commits into
mainfrom
download-logic

Conversation

@sumanthd032

Copy link
Copy Markdown
Owner
  • Added CreateDropRequest/Response models
  • Implemented POST /api/v1/drop to initialize upload session
  • Implemented POST /api/v1/drop/{id}/chunk to handle binary chunk upload
  • Added DB insertion for drops and chunks
  • Added S3 upload logic integration"

Copilot AI review requested due to automatic review settings February 12, 2026 18:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds initial download support and completes core “drop” upload flow by introducing metadata models, upload session initialization, chunk upload handling, and new download endpoints backed by Postgres + S3/MinIO.

Changes:

  • Added GetDropMetadataResponse model for download metadata.
  • Implemented upload handlers for creating drops and uploading binary chunks (DB + S3).
  • Added download routes + handlers for drop metadata and chunk retrieval.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 6 comments.

File Description
internal/api/router.go Registers new download endpoints alongside existing upload routes.
internal/api/models.go Adds response model for drop metadata used by CLI before downloading.
internal/api/handlers_upload.go Implements drop creation and chunk upload (S3 upload + DB inserts).
internal/api/handlers.download.go Implements metadata fetch (DB) and chunk download (S3) endpoints.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +30 to +33
if err != nil {
http.Error(w, "Drop not found", http.StatusNotFound)
return
}

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

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

QueryRow(...).Scan(...) errors are all mapped to 404. This will incorrectly return "Drop not found" on transient DB errors. Handle sql.ErrNoRows as 404, but return 500 (and ideally log) for other errors.

Copilot uses AI. Check for mistakes.
Comment on lines +41 to +45
// 3. Get chunk count (to know how many pieces to expect)
err = s.DB.QueryRow("SELECT COUNT(*) FROM chunks WHERE drop_id = $1", dropID).Scan(&resp.ChunkCount)
if err != nil {
http.Error(w, "Database error", http.StatusInternalServerError)
return

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

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

COUNT(*) in Postgres returns BIGINT; scanning into resp.ChunkCount (int) can cause conversion issues and is platform-dependent. Scan into an int64 variable and then convert (with bounds check) before assigning to the response.

Copilot uses AI. Check for mistakes.
Comment thread internal/api/models.go
Comment on lines 27 to +31
// 1. CLI sends CreateDropRequest to /api/v1/drops (POST)
// 2. Server responds with CreateDropResponse (drop ID and expiration time)
// 3. CLI uploads file chunks to /api/v1/drops/{drop_id}/chunks (POST) with ChunkUploadResponse confirming each chunk

// GetDropMetadataResponse is what the server sends back when the CLI requests metadata about a drop

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

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

The upload flow comments still reference /api/v1/drops and /api/v1/drops/{drop_id}/chunks, but the router defines /api/v1/drop and /api/v1/drop/{id}/chunk. Update these comments (or the routes) so the documented API matches the actual endpoints.

Copilot uses AI. Check for mistakes.
Comment on lines +56 to +60
dropID := chi.URLParam(r, "id")
chunkIndex := chi.URLParam(r, "chunkIndex") // We'll add this param to router

// 1. Construct S3 Key
key := fmt.Sprintf("drops/%s/%s", dropID, chunkIndex)

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

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

Download endpoint builds the S3 key directly from the URL chunkIndex without validating it or checking the drop/chunk state in Postgres (expiry, deletion, max/current downloads, chunk existence). Add validation (e.g. numeric index) and enforce drop expiry/download limits before serving data.

Copilot uses AI. Check for mistakes.
func (s *Server) handleDownloadChunk() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
dropID := chi.URLParam(r, "id")
chunkIndex := chi.URLParam(r, "chunkIndex") // We'll add this param to router

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

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

The comment says "We'll add this param to router" but the router already defines {chunkIndex}. Update/remove this comment to avoid misleading future changes.

Suggested change
chunkIndex := chi.URLParam(r, "chunkIndex") // We'll add this param to router
chunkIndex := chi.URLParam(r, "chunkIndex") // chunkIndex is provided as a URL parameter

Copilot uses AI. Check for mistakes.
Comment on lines +63 to +66
data, err := s.Store.DownloadChunk(key)
if err != nil {
http.Error(w, "Chunk not found or storage error", http.StatusNotFound)
return

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

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

This maps any DownloadChunk error to 404, which can hide genuine storage/permission/outage errors. Consider returning 404 only for missing objects and 500 for other errors (and/or log the underlying error).

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

Copilot AI commented Feb 12, 2026

Copy link
Copy Markdown

@sumanthd032 I've opened a new pull request, #5, to work on those changes. Once the pull request is ready, I'll request review from you.

[WIP] Update download logic implementation based on feedback
@sumanthd032 sumanthd032 merged commit 0e13e61 into main Feb 12, 2026
1 check passed
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.

3 participants