remove automatic cleanup feature
This commit is contained in:
parent
6624c5a989
commit
52928e0507
1 changed files with 0 additions and 42 deletions
42
go/main.go
42
go/main.go
|
@ -23,16 +23,7 @@ var (
|
|||
uploadInterval = 10 * time.Second
|
||||
)
|
||||
|
||||
const (
|
||||
uploadDir = "./uploads"
|
||||
cleanupInterval = 1 * time.Hour
|
||||
fileLifetime = 48 * time.Hour
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Starten Sie den Hintergrundprozess zum Löschen alter Dateien
|
||||
go startCleanupProcess()
|
||||
|
||||
http.HandleFunc("/", homeHandler)
|
||||
http.HandleFunc("/upload", uploadHandler)
|
||||
http.HandleFunc("/image/", imageHandler)
|
||||
|
@ -45,39 +36,6 @@ func main() {
|
|||
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) {
|
||||
// Setzen der Content Security Policy
|
||||
w.Header().Set("Content-Security-Policy", "default-src 'self'; script-src 'self'; object-src 'none';")
|
||||
|
|
Loading…
Reference in a new issue