2.4-stable release

This commit is contained in:
Alexander Renz 2024-12-31 08:03:39 +01:00
parent 7c5432fbe7
commit dccb3e0cd0
4 changed files with 96 additions and 22 deletions

View File

@ -513,6 +513,14 @@ func main() {
if err := os.MkdirAll(conf.Thumbnails.Directory, os.ModePerm); err != nil {
log.Fatalf("Failed to create thumbnail directory: %v", err)
}
// Verify and repair thumbnails
thumbnailPaths, err := filepath.Glob(filepath.Join(conf.Thumbnails.Directory, "*"))
if err != nil {
log.Errorf("Error listing thumbnail files: %v", err)
} else {
go verifyAndRepairThumbnails(thumbnailPaths, redisClient, conf.Server.StoragePath)
}
}
err = checkFreeSpaceWithRetry(storagePath, 3, 5*time.Second)
@ -3079,4 +3087,84 @@ func handleThumbnails(w http.ResponseWriter, r *http.Request) {
if _, err := io.Copy(w, file); err != nil {
log.WithError(err).Errorf("Failed to serve thumbnail for user_id: %s", userID)
}
}
// verifyAndRepairThumbnails verifies the integrity of thumbnail files and repairs them if necessary
func verifyAndRepairThumbnails(thumbnailPaths []string, redisClient *redis.Client, originalDir string) {
// Check if redisClient is nil
if redisClient == nil {
log.Error("Redis client is nil. Cannot verify and repair thumbnails.")
return
}
// Check if thumbnailPaths is nil or empty
if len(thumbnailPaths) == 0 {
log.Error("Thumbnail paths are nil or empty. Nothing to verify or repair.")
return
}
for _, thumbPath := range thumbnailPaths {
// Compute SHA-256 hash of the thumbnail file
file, err := os.Open(thumbPath)
if err != nil {
log.Warnf("Error opening thumbnail %s: %v", thumbPath, err)
continue
}
hasher := sha256.New()
if _, err := io.Copy(hasher, file); err != nil {
log.Warnf("Error hashing thumbnail %s: %v", thumbPath, err)
file.Close()
continue
}
file.Close()
computedHash := hex.EncodeToString(hasher.Sum(nil))
// Get stored hash from Redis
storedHash, err := redisClient.Get(context.Background(), thumbPath).Result()
if err == redis.Nil || storedHash != computedHash {
log.Warnf("Thumbnail %s is corrupted or missing. Regenerating...", thumbPath)
// Assume original image is in originalDir with the same base name
originalPath := filepath.Join(originalDir, filepath.Base(thumbPath))
origImage, err := imaging.Open(originalPath)
if err != nil {
log.Warnf("Error opening original image %s: %v", originalPath, err)
continue
}
// Generate thumbnail (e.g., 200x200 pixels)
thumbnail := imaging.Thumbnail(origImage, 200, 200, imaging.Lanczos)
// Save the regenerated thumbnail
err = imaging.Save(thumbnail, thumbPath)
if err != nil {
log.Warnf("Error saving regenerated thumbnail %s: %v", thumbPath, err)
continue
}
// Compute new hash
file, err := os.Open(thumbPath)
if err != nil {
log.Warnf("Error opening regenerated thumbnail %s: %v", thumbPath, err)
continue
}
hasher.Reset()
if _, err := io.Copy(hasher, file); err != nil {
log.Warnf("Error hashing regenerated thumbnail %s: %v", thumbPath, err)
file.Close()
continue
}
file.Close()
newHash := hex.EncodeToString(hasher.Sum(nil))
// Store new hash in Redis
err = redisClient.Set(context.Background(), thumbPath, newHash, 0).Err()
if err != nil {
log.Warnf("Error storing new hash for thumbnail %s in Redis: %v", thumbPath, err)
continue
}
log.Infof("Successfully regenerated and updated thumbnail %s", thumbPath)
}
}
}

0
cmd/server/uploads/test Normal file
View File

View File

@ -27,17 +27,17 @@ max_age = 30
compress = true
[deduplication]
enabled = false
enabled = true
directory = "./deduplication"
[thumbnails]
enabled = false
enabled = true
directory = "./thumbnails"
size = "200x200"
thumbnailintervalscan = "24h"
[iso]
enabled = false
enabled = true
size = "1GB"
mountpoint = "/mnt/iso"
charset = "utf-8"
@ -52,19 +52,14 @@ idletimeout = "4800s"
secret = "changeme"
[versioning]
enableversioning = false
maxversions = 1
enableversioning = true
maxversions = 5
[uploads]
resumableuploadsenabled = true
chunkeduploadsenabled = true
chunksize = "8192"
allowedextensions = [
".txt", ".pdf", ".png", ".jpg", ".jpeg", ".gif",
".bmp", ".tiff", ".svg", ".webp", ".wav", ".mp4",
".avi", ".mkv", ".mov", ".wmv", ".flv", ".webm",
".mpeg", ".mpg", ".m4v", ".3gp", ".3g2", ".mp3", ".ogg"
]
allowedextensions = ["*"] # Use ["*"] to allow all or specify extensions
[downloads]
resumabledownloadsenabled = true
@ -88,18 +83,9 @@ redishealthcheckinterval = "120s"
[workers]
numworkers = 4
uploadqueuesize = 50
max_concurrent_operations = 10
network_event_buffer = 100
performance_monitor_interval = "5m"
metrics_update_interval = "10s"
[file]
filerevision = 1
[precache]
redisEnabled = true
redisAddr = "localhost:6379"
staticIndexFile = "./static_index.json"
[build]
version = "v1.0.0"
version = "v2.3"

View File

@ -16,7 +16,7 @@ import (
const (
serverURL = "http://[::1]:8080" // Replace with your actual server URL
secret = "changeme" // Replace with your HMAC secret key
secret = "a-orc-and-a-humans-is-drinking-ale" // Replace with your HMAC secret key
uploadPath = "hmac_icon.png" // Test file to upload
protocolType = "v2" // Use v2, v, or token as needed
)