Uploaded Media File Delete Update

This commit is contained in:
2026-02-22 13:04:04 -05:00
parent 3d936d8a6f
commit 3b4d5e4080
16 changed files with 701 additions and 451 deletions

View File

@@ -6,21 +6,11 @@ import (
"os"
"path/filepath"
"strings"
"sim-link-server/routes"
_ "github.com/mattn/go-sqlite3"
)
type Simulation struct {
ID int `json:"id"`
Name string `json:"name"`
Resources []string `json:"resources"`
CreatedAt string `json:"created_at"`
Config *string `json:"config"`
SearchTime *float64 `json:"search_time"`
TotalTime *float64 `json:"total_time"`
TotalSizeBytes int64 `json:"total_size_bytes"`
}
var db *sql.DB
func initDBConnection() {
@@ -41,9 +31,9 @@ func initDBConnection() {
log.Fatal(err)
}
db.Exec("ALTER TABLE simulations ADD COLUMN config TEXT") // Ignore error if exists
db.Exec("ALTER TABLE simulations ADD COLUMN search_time REAL") // Ignore error if exists
db.Exec("ALTER TABLE simulations ADD COLUMN total_time REAL") // Ignore error if exists
db.Exec("ALTER TABLE simulations ADD COLUMN config TEXT")
db.Exec("ALTER TABLE simulations ADD COLUMN search_time REAL")
db.Exec("ALTER TABLE simulations ADD COLUMN total_time REAL")
createResourcesTableSQL := `CREATE TABLE IF NOT EXISTS resources (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
@@ -78,17 +68,15 @@ func syncResults() {
// Read subfiles
subFiles, err := os.ReadDir(filepath.Join(resultsDir, simName))
if err == nil {
// Clear old resources for this simulation
db.Exec("DELETE FROM resources WHERE simulation_id = ?", simID)
// Check for already inserted to avoid dupes if both exist
seen := make(map[string]bool)
for _, sf := range subFiles {
if !sf.IsDir() {
finalName := sf.Name()
if strings.ToLower(filepath.Ext(finalName)) == ".avi" {
finalName = transcodeIfNeeded(filepath.Join(resultsDir, simName), finalName)
finalName = routes.TranscodeIfNeeded(filepath.Join(resultsDir, simName), finalName)
}
if !seen[finalName] {