inou/nuke-imaging/main.go

70 lines
1.9 KiB
Go

package main
import (
"fmt"
"os"
"path/filepath"
"inou/lib"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("Usage: nuke-imaging <dossier_id_hex>")
os.Exit(1)
}
dossierID := os.Args[1]
if len(dossierID) != 16 {
fmt.Printf("Invalid dossier ID: %s (must be 16 hex characters)\n", dossierID)
os.Exit(1)
}
if err := lib.Init(); err != nil {
fmt.Printf("Error initializing: %v\n", err)
os.Exit(1)
}
defer lib.DBClose()
// Verify dossier exists
dossierEntries, err := lib.EntryRead("", dossierID, &lib.Filter{Category: 0})
if err != nil || len(dossierEntries) == 0 {
fmt.Printf("Error: dossier %s not found\n", dossierID)
os.Exit(1)
}
fmt.Printf("Dossier: %s\n", dossierEntries[0].Summary)
// Delete imaging entries (Category 1) — EntryDelete removes object files too
imaging, _ := lib.EntryRead("", dossierID, &lib.Filter{Category: lib.CategoryImaging})
if len(imaging) > 0 {
fmt.Printf("Deleting %d imaging entries...\n", len(imaging))
if err := lib.EntryDelete("", dossierID, &lib.Filter{Category: lib.CategoryImaging}); err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
}
// Delete upload entries (Category 5) — EntryDelete removes object files too
uploads, _ := lib.EntryRead("", dossierID, &lib.Filter{Category: lib.CategoryUpload})
if len(uploads) > 0 {
fmt.Printf("Deleting %d upload entries...\n", len(uploads))
if err := lib.EntryDelete("", dossierID, &lib.Filter{Category: lib.CategoryUpload}); err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
}
// Remove upload files on disk
uploadDir := filepath.Join("/tank/inou/uploads", dossierID)
if info, err := os.Stat(uploadDir); err == nil && info.IsDir() {
fmt.Printf("Removing upload files: %s\n", uploadDir)
os.RemoveAll(uploadDir)
}
if len(imaging) == 0 && len(uploads) == 0 {
fmt.Println("No imaging or upload data found.")
} else {
fmt.Println("Done.")
}
}