|
|
@ -483,7 +483,7 @@ func BulkRemoveDocumentsHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
|
|
|
|
// Get age filter (optional)
|
|
|
// Get age filter (optional)
|
|
|
var ageFilterDays int |
|
|
var ageFilterDays int |
|
|
if ageStr := r.FormValue("ageFilter"); ageStr != "" { |
|
|
if ageStr := r.FormValue("age-filter"); ageStr != "" { |
|
|
if days, err := strconv.Atoi(ageStr); err == nil && days > 0 { |
|
|
if days, err := strconv.Atoi(ageStr); err == nil && days > 0 { |
|
|
ageFilterDays = days |
|
|
ageFilterDays = days |
|
|
log.Printf("Using age filter: older than %d days", ageFilterDays) |
|
|
log.Printf("Using age filter: older than %d days", ageFilterDays) |
|
|
@ -494,6 +494,7 @@ func BulkRemoveDocumentsHandler(w http.ResponseWriter, r *http.Request) { |
|
|
var cutoffDate time.Time |
|
|
var cutoffDate time.Time |
|
|
if ageFilterDays > 0 { |
|
|
if ageFilterDays > 0 { |
|
|
cutoffDate = time.Now().AddDate(0, 0, -ageFilterDays) |
|
|
cutoffDate = time.Now().AddDate(0, 0, -ageFilterDays) |
|
|
|
|
|
log.Printf("Cutoff date for age filter: %s", cutoffDate.Format("2006-01-02")) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Structure to track results
|
|
|
// Structure to track results
|
|
|
@ -1349,9 +1350,47 @@ func BulkRemoveDocumentsHandler(w http.ResponseWriter, r *http.Request) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Comment out problematic log line
|
|
|
// Check filename pattern
|
|
|
// log.Printf("Attachment %s (type: %v, created: %s) matches all criteria - queued for deletion",
|
|
|
if len(filenamePatterns) > 0 && !matchesAnyPattern(filename, filenamePatterns) { |
|
|
// filename, purposeId, attachment["createdOn"])
|
|
|
log.Printf("Skipping attachment %s - filename '%s' doesn't match patterns: %v", |
|
|
|
|
|
attachmentIDStr, filename, filenamePatterns) |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Check age filter if applicable
|
|
|
|
|
|
if ageFilterDays > 0 { |
|
|
|
|
|
// Get creation time
|
|
|
|
|
|
var createdAt time.Time |
|
|
|
|
|
var createdOn string |
|
|
|
|
|
var hasDate bool |
|
|
|
|
|
|
|
|
|
|
|
// Try to get the creation date
|
|
|
|
|
|
if created, ok := attachment["createdOn"].(string); ok { |
|
|
|
|
|
createdOn = created |
|
|
|
|
|
hasDate = true |
|
|
|
|
|
} else if created, ok := attachment["created"].(string); ok { |
|
|
|
|
|
createdOn = created |
|
|
|
|
|
hasDate = true |
|
|
|
|
|
} else if lastModified, ok := attachment["lastModified"].(string); ok { |
|
|
|
|
|
createdOn = lastModified |
|
|
|
|
|
hasDate = true |
|
|
|
|
|
} else if createdVal, ok := attachment["created"].(float64); ok { |
|
|
|
|
|
createdAt = time.Unix(int64(createdVal), 0) |
|
|
|
|
|
createdOn = createdAt.Format(time.RFC3339) |
|
|
|
|
|
hasDate = true |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if hasDate { |
|
|
|
|
|
if parsedTime, err := time.Parse(time.RFC3339, createdOn); err == nil { |
|
|
|
|
|
createdAt = parsedTime |
|
|
|
|
|
if createdAt.After(cutoffDate) { |
|
|
|
|
|
log.Printf("Skipping attachment %s - created on %s is newer than cutoff %s", |
|
|
|
|
|
filename, createdAt.Format("2006-01-02"), cutoffDate.Format("2006-01-02")) |
|
|
|
|
|
continue // Skip if not old enough
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Log that we found an attachment to delete
|
|
|
// Log that we found an attachment to delete
|
|
|
log.Printf("Attachment %s matches criteria - will be deleted", filename) |
|
|
log.Printf("Attachment %s matches criteria - will be deleted", filename) |
|
|
@ -1564,10 +1603,23 @@ func stringInSlice(s string, slice []string) bool { |
|
|
|
|
|
|
|
|
// Helper function to check if a string matches any pattern in a slice
|
|
|
// Helper function to check if a string matches any pattern in a slice
|
|
|
func matchesAnyPattern(s string, patterns []string) bool { |
|
|
func matchesAnyPattern(s string, patterns []string) bool { |
|
|
|
|
|
// Convert the string to lowercase for case-insensitive comparison
|
|
|
|
|
|
sLower := strings.ToLower(s) |
|
|
|
|
|
|
|
|
for _, pattern := range patterns { |
|
|
for _, pattern := range patterns { |
|
|
match, _ := regexp.MatchString("(?i)"+pattern, s) |
|
|
// Check if the pattern is a wildcard pattern (contains *)
|
|
|
if match { |
|
|
if strings.Contains(pattern, "*") { |
|
|
return true |
|
|
// Convert wildcard pattern to regex
|
|
|
|
|
|
regexPattern := strings.ReplaceAll(pattern, "*", ".*") |
|
|
|
|
|
match, _ := regexp.MatchString("(?i)^"+regexPattern+"$", s) |
|
|
|
|
|
if match { |
|
|
|
|
|
return true |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
// For non-wildcard patterns, check for exact match (case-insensitive)
|
|
|
|
|
|
if sLower == strings.ToLower(pattern) { |
|
|
|
|
|
return true |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return false |
|
|
return false |
|
|
|