Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions internal/api/handlers_delta.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"encoding/json"
"strings"
"io"
"net/http"
"time"
Expand Down Expand Up @@ -46,8 +47,15 @@
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
// Validate content type
contentType := r.Header.Get("Content-Type")
if contentType != "application/json" && !strings.HasPrefix(contentType, "application/json;") {
WriteJSONError(w, "Content-Type must be application/json", http.StatusUnsupportedMediaType)
return
}

body, err := io.ReadAll(io.LimitReader(r.Body, 50*1024*1024)) // 50MB limit

start := time.Now()

// Read body
Expand Down Expand Up @@ -101,7 +109,14 @@
WriteJSONError(w, "Failed to apply delta: "+err.Error(), http.StatusInternalServerError)
return
}
// Validate content type
contentType := r.Header.Get("Content-Type")
if contentType != "application/json" && !strings.HasPrefix(contentType, "application/json;") {
WriteJSONError(w, "Content-Type must be application/json", http.StatusUnsupportedMediaType)
return
}

body, err := io.ReadAll(io.LimitReader(r.Body, 50*1024*1024)) // 50MB limit
// Refresh FTS index
if err := s.engine.RefreshFTS(ctx); err != nil {
warnings = append(warnings, "FTS refresh failed: "+err.Error())
Expand All @@ -124,22 +139,22 @@
}

// handleDeltaValidate handles POST /delta/validate - validate a delta without ingesting
func (s *Server) handleDeltaValidate(w http.ResponseWriter, r *http.Request) {

Check failure on line 142 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Analyze

syntax error: unexpected name http in argument list; possibly missing comma or )

Check failure on line 142 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Test

syntax error: unexpected name http in argument list; possibly missing comma or )

Check failure on line 142 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Security Scan

expected operand, found '.'

Check failure on line 142 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Security Scan

missing ',' in argument list

Check failure on line 142 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Lint

missing ',' in argument list (typecheck)

Check failure on line 142 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Lint

syntax error: unexpected name http in argument list; possibly missing comma or ) (typecheck)

Check failure on line 142 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Go SAST / Gosec Security Scan

syntax error: unexpected name http in argument list; possibly missing comma or )

Check failure on line 142 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Dependencies / Dependency Scan

expected operand, found '.'

Check failure on line 142 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Dependencies / Dependency Scan

missing ',' in argument list

Check failure on line 142 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Dependencies / Dependency Scan

expected operand, found '.'

Check failure on line 142 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Dependencies / Dependency Scan

missing ',' in argument list
if r.Method != http.MethodPost {

Check failure on line 143 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Security Scan

missing ',' in argument list

Check failure on line 143 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Lint

missing ',' in argument list (typecheck)

Check failure on line 143 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Dependencies / Dependency Scan

missing ',' in argument list

Check failure on line 143 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Dependencies / Dependency Scan

missing ',' in argument list
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)

Check failure on line 144 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Security Scan

missing ',' before newline in composite literal

Check failure on line 144 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Lint

missing ',' before newline in composite literal (typecheck)

Check failure on line 144 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Dependencies / Dependency Scan

missing ',' before newline in composite literal

Check failure on line 144 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Dependencies / Dependency Scan

missing ',' before newline in composite literal
return

Check failure on line 145 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Security Scan

expected operand, found newline

Check failure on line 145 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Security Scan

missing ',' in composite literal

Check failure on line 145 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Security Scan

expected operand, found 'return'

Check failure on line 145 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Lint

expected operand, found 'return' (typecheck)

Check failure on line 145 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Dependencies / Dependency Scan

expected operand, found newline

Check failure on line 145 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Dependencies / Dependency Scan

missing ',' in composite literal

Check failure on line 145 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Dependencies / Dependency Scan

expected operand, found 'return'

Check failure on line 145 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Dependencies / Dependency Scan

expected operand, found newline

Check failure on line 145 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Dependencies / Dependency Scan

missing ',' in composite literal

Check failure on line 145 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Dependencies / Dependency Scan

expected operand, found 'return'
}

// Read body
body, err := io.ReadAll(io.LimitReader(r.Body, 50*1024*1024)) // 50MB limit
if err != nil {

Check failure on line 150 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Security Scan

missing ',' in composite literal

Check failure on line 150 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Lint

missing ',' in composite literal (typecheck)

Check failure on line 150 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Dependencies / Dependency Scan

missing ',' in composite literal

Check failure on line 150 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Dependencies / Dependency Scan

missing ',' in composite literal
WriteJSONError(w, "Failed to read request body", http.StatusBadRequest)

Check failure on line 151 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Security Scan

missing ',' before newline in composite literal

Check failure on line 151 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Lint

missing ',' before newline in composite literal (typecheck)

Check failure on line 151 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Dependencies / Dependency Scan

missing ',' before newline in composite literal

Check failure on line 151 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Dependencies / Dependency Scan

missing ',' before newline in composite literal
return

Check failure on line 152 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Security Scan

expected operand, found 'return'

Check failure on line 152 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Lint

expected operand, found 'return' (typecheck)

Check failure on line 152 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Dependencies / Dependency Scan

expected operand, found 'return'

Check failure on line 152 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Dependencies / Dependency Scan

expected operand, found 'return'
}
defer r.Body.Close()

Check failure on line 154 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Lint

missing ',' in composite literal (typecheck)

// Parse delta
delta, err := diff.ParseDelta(body)

Check failure on line 157 in internal/api/handlers_delta.go

View workflow job for this annotation

GitHub Actions / Lint

missing ',' in composite literal (typecheck)
if err != nil {
WriteJSONError(w, "Invalid delta format: "+err.Error(), http.StatusBadRequest)
return
Expand Down
Loading