🔥 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

0
CLAMAV_LARGE_FILE_FIX.md Normal file
View File

0
CLAMAV_SCANNING_FIX.md Normal file
View File

View File

0
CLUSTER_RESTART_GUIDE.md Normal file
View File

View File

View File

View File

0
FINAL_STATUS_REPORT.md Normal file
View File

0
INSTALL.MD Normal file
View File

0
LARGE_FILE_UPLOAD_FIX.md Normal file
View File

View File

View File

View File

View File

0
README.MD Normal file
View File

View File

0
UPLOAD_COMPLETION_FIX.md Normal file
View File

View File

0
VIDEO_EXTENSION_FIX.md Normal file
View File

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 // Create new session
clientIP := getClientIP(r) clientIP := getClientIP(r)
session := uploadSessionStore.CreateSession(filename, totalSize, clientIP) 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) 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 // Create the file
dst, err := os.Create(absFilename) dst, err := os.Create(absFilename)
if err != nil { if err != nil {
@ -1752,6 +1778,32 @@ func handleV3Upload(w http.ResponseWriter, r *http.Request) {
absFilename := filepath.Join(storagePath, filename) 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 // Create the file
dst, err := os.Create(absFilename) dst, err := os.Create(absFilename)
if err != nil { if err != nil {
@ -1907,6 +1959,23 @@ func handleLegacyUpload(w http.ResponseWriter, r *http.Request) {
return 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 // Create the file
dst, err := os.Create(absFilename) dst, err := os.Create(absFilename)
if err != nil { if err != nil {

View File

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

0
config-clean.toml Normal file
View File

0
tests/README.md Normal file
View File

0
verify_xmpp_upload.sh Normal file
View File