🔥 Tremora del Terra: ultimate hmac-file-server fix – final push before the drop 💾🔐

This commit is contained in:
2025-07-18 14:46:50 +00:00
parent 6d5d134b77
commit 347f9b1ede
25 changed files with 97 additions and 1 deletions

View File

@ -105,6 +105,34 @@ func handleChunkedUpload(w http.ResponseWriter, r *http.Request) {
}
}
// Pre-upload deduplication check for chunked uploads
if conf.Server.DeduplicationEnabled {
finalPath := filepath.Join(conf.Server.StoragePath, filename)
if existingFileInfo, err := os.Stat(finalPath); err == nil {
// File already exists - return success immediately for deduplication hit
duration := time.Since(startTime)
uploadDuration.Observe(duration.Seconds())
uploadsTotal.Inc()
uploadSizeBytes.Observe(float64(existingFileInfo.Size()))
filesDeduplicatedTotal.Inc()
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
response := map[string]interface{}{
"success": true,
"filename": filename,
"size": existingFileInfo.Size(),
"completed": true,
"message": "File already exists (deduplication hit)",
}
writeJSONResponse(w, response)
log.Infof("Chunked upload deduplication hit: file %s already exists (%s), returning success immediately",
filename, formatBytes(existingFileInfo.Size()))
return
}
}
// Create new session
clientIP := getClientIP(r)
session := uploadSessionStore.CreateSession(filename, totalSize, clientIP)

View File

@ -1515,6 +1515,32 @@ func handleUpload(w http.ResponseWriter, r *http.Request) {
absFilename := filepath.Join(storagePath, filename)
// Pre-upload deduplication check: if file already exists and deduplication is enabled, return success immediately
if conf.Server.DeduplicationEnabled {
if existingFileInfo, err := os.Stat(absFilename); err == nil {
// File already exists - return success immediately for deduplication hit
duration := time.Since(startTime)
uploadDuration.Observe(duration.Seconds())
uploadsTotal.Inc()
uploadSizeBytes.Observe(float64(existingFileInfo.Size()))
filesDeduplicatedTotal.Inc()
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
response := map[string]interface{}{
"success": true,
"filename": filename,
"size": existingFileInfo.Size(),
"message": "File already exists (deduplication hit)",
}
json.NewEncoder(w).Encode(response)
log.Infof("Deduplication hit: file %s already exists (%s), returning success immediately",
filename, formatBytes(existingFileInfo.Size()))
return
}
}
// Create the file
dst, err := os.Create(absFilename)
if err != nil {
@ -1752,6 +1778,32 @@ func handleV3Upload(w http.ResponseWriter, r *http.Request) {
absFilename := filepath.Join(storagePath, filename)
// Pre-upload deduplication check: if file already exists and deduplication is enabled, return success immediately
if conf.Server.DeduplicationEnabled {
if existingFileInfo, err := os.Stat(absFilename); err == nil {
// File already exists - return success immediately for deduplication hit
duration := time.Since(startTime)
uploadDuration.Observe(duration.Seconds())
uploadsTotal.Inc()
uploadSizeBytes.Observe(float64(existingFileInfo.Size()))
filesDeduplicatedTotal.Inc()
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
response := map[string]interface{}{
"success": true,
"filename": filename,
"size": existingFileInfo.Size(),
"message": "File already exists (deduplication hit)",
}
json.NewEncoder(w).Encode(response)
log.Infof("Deduplication hit: file %s already exists (%s), returning success immediately",
filename, formatBytes(existingFileInfo.Size()))
return
}
}
// Create the file
dst, err := os.Create(absFilename)
if err != nil {
@ -1907,6 +1959,23 @@ func handleLegacyUpload(w http.ResponseWriter, r *http.Request) {
return
}
// Pre-upload deduplication check: if file already exists and deduplication is enabled, return success immediately
if conf.Server.DeduplicationEnabled {
if existingFileInfo, err := os.Stat(absFilename); err == nil {
// File already exists - return success immediately for deduplication hit
duration := time.Since(startTime)
uploadDuration.Observe(duration.Seconds())
uploadsTotal.Inc()
uploadSizeBytes.Observe(float64(existingFileInfo.Size()))
filesDeduplicatedTotal.Inc()
w.WriteHeader(http.StatusCreated) // 201 Created for legacy compatibility
log.Infof("Deduplication hit: file %s already exists (%s), returning success immediately",
filename, formatBytes(existingFileInfo.Size()))
return
}
}
// Create the file
dst, err := os.Create(absFilename)
if err != nil {

View File

@ -5,7 +5,6 @@ package main
import (
"context"
"errors"
"fmt"
"sync"
"sync/atomic"
"time"