remove automatic cleanup feature

This commit is contained in:
Simon Rieger 2024-09-02 15:42:54 +02:00
parent 6624c5a989
commit 52928e0507

View file

@ -23,16 +23,7 @@ var (
uploadInterval = 10 * time.Second uploadInterval = 10 * time.Second
) )
const (
uploadDir = "./uploads"
cleanupInterval = 1 * time.Hour
fileLifetime = 48 * time.Hour
)
func main() { func main() {
// Starten Sie den Hintergrundprozess zum Löschen alter Dateien
go startCleanupProcess()
http.HandleFunc("/", homeHandler) http.HandleFunc("/", homeHandler)
http.HandleFunc("/upload", uploadHandler) http.HandleFunc("/upload", uploadHandler)
http.HandleFunc("/image/", imageHandler) http.HandleFunc("/image/", imageHandler)
@ -45,39 +36,6 @@ func main() {
http.ListenAndServe(":8080", nil) http.ListenAndServe(":8080", nil)
} }
func startCleanupProcess() {
ticker := time.NewTicker(cleanupInterval)
defer ticker.Stop()
for {
select {
case <-ticker.C:
cleanupOldFiles()
}
}
}
func cleanupOldFiles() {
now := time.Now()
err := filepath.Walk(uploadDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && now.Sub(info.ModTime()) > fileLifetime {
err := os.Remove(path)
if err != nil {
log.Printf("Fehler beim Löschen der Datei %s: %v", path, err)
} else {
log.Printf("Datei gelöscht: %s", path)
}
}
return nil
})
if err != nil {
log.Printf("Fehler beim Durchsuchen des Verzeichnisses: %v", err)
}
}
func homeHandler(w http.ResponseWriter, r *http.Request) { func homeHandler(w http.ResponseWriter, r *http.Request) {
// Setzen der Content Security Policy // Setzen der Content Security Policy
w.Header().Set("Content-Security-Policy", "default-src 'self'; script-src 'self'; object-src 'none';") w.Header().Set("Content-Security-Policy", "default-src 'self'; script-src 'self'; object-src 'none';")