feat: implement chunked upload handler and update config validation for session timeout
This commit is contained in:
@ -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
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
1
test_upload.txt
Normal file
1
test_upload.txt
Normal file
@ -0,0 +1 @@
|
||||
Hello, HMAC File Server! Do 17. Jul 18:05:48 CEST 2025
|
Reference in New Issue
Block a user