Uploaded Media File Delete Update
This commit is contained in:
22
server/db.go
22
server/db.go
@@ -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] {
|
||||
|
||||
Reference in New Issue
Block a user