feat: implement chunked upload handler and update config validation for session timeout

This commit is contained in:
2025-07-17 18:05:59 +02:00
parent d8e9974a93
commit 35e4a6fc46
4 changed files with 7 additions and 7 deletions

View File

@ -3,6 +3,7 @@
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
@ -32,8 +33,6 @@ func handleChunkedUpload(w http.ResponseWriter, r *http.Request) {
// Extract headers for chunked upload
sessionID := r.Header.Get("X-Upload-Session-ID")
chunkNumberStr := r.Header.Get("X-Chunk-Number")
totalChunksStr := r.Header.Get("X-Total-Chunks")
contentRange := r.Header.Get("Content-Range")
filename := r.Header.Get("X-Filename")
// Handle session creation for new uploads

View File

@ -301,10 +301,10 @@ func validateUploadsConfig(uploads *UploadsConfig, result *ConfigValidationResul
}
}
// Validate resumable age
if uploads.MaxResumableAge != "" {
if _, err := time.ParseDuration(uploads.MaxResumableAge); err != nil {
result.AddError("uploads.max_resumable_age", uploads.MaxResumableAge, "invalid resumable age format")
// Validate session timeout (renamed from max_resumable_age)
if uploads.SessionTimeout != "" {
if _, err := time.ParseDuration(uploads.SessionTimeout); err != nil {
result.AddError("uploads.session_timeout", uploads.SessionTimeout, "invalid session timeout format")
}
}
}

View File

@ -251,7 +251,7 @@ func RetryableUploadWrapper(originalHandler http.HandlerFunc, maxRetries int) ht
if attempt > 0 {
// Exponential backoff with jitter
delay := time.Duration(attempt*attempt) * time.Second
jitter := time.Duration(float64(delay) * 0.1 * (2*time.Now().UnixNano()%2 - 1))
jitter := time.Duration(float64(delay.Nanoseconds()) * 0.1 * float64((time.Now().UnixNano()%2)*2-1))
time.Sleep(delay + jitter)
log.Infof("Retrying upload attempt %d/%d", attempt+1, maxRetries+1)