chore: fix a small issue with video modes

This commit is contained in:
DaanSelen
2026-04-21 16:59:37 +02:00
parent c4a4fafb52
commit e1f5308dd3
6 changed files with 28 additions and 18 deletions
+5 -2
View File
@@ -21,14 +21,17 @@ func KickoffDatabase(workDir string) (*gorm.DB, error) {
if err := db.AutoMigrate(&State{}); err != nil {
return nil, err
}
if err := db.AutoMigrate(&Device{}); err != nil {
return nil, err
}
if err := db.AutoMigrate(&File{}); err != nil {
return nil, err
}
// create the first row if it does not exist yet
if err := db.FirstOrCreate(&State{}, State{
ID: 0,
Mode: "unspecified",
ID: 0,
MediaType: "unspecified",
}).Error; err != nil {
return nil, err
}
+8 -8
View File
@@ -6,13 +6,13 @@ import (
"gorm.io/datatypes"
)
type Mode string
type MediaType string
const (
ModeUnspecified Mode = "unspecified"
ModeVideo Mode = "video"
ModePresentation Mode = "presentation"
ModeInternet Mode = "internet"
Unspecified MediaType = "unspecified"
Video MediaType = "video"
Presentation MediaType = "presentation"
Internet MediaType = "internet"
)
type State struct {
@@ -21,7 +21,7 @@ type State struct {
// video
// presentation
// internet URL
Mode Mode `gorm:"type:varchar(20);not null"` // Must specify what kind of file it is
MediaType MediaType `gorm:"type:varchar(20);not null"` // Must specify what kind of file it is
Targets datatypes.JSON
Location string // Must be the location where the file is downloadable on the API
UpdatedAt time.Time
@@ -39,8 +39,8 @@ type Device struct {
}
type File struct {
ID int `gorm:"primaryKey"`
Mode Mode `gorm:"type:varchar(20);not null"`
ID int `gorm:"primaryKey"`
MediaType MediaType `gorm:"type:varchar(20);not null;"`
GivenName string
Filepath string
Checksum string // base64 encoded sha512 checksum
+8 -1
View File
@@ -3,6 +3,7 @@ package database
import (
"log"
"log/slog"
"os"
"gorm.io/gorm"
)
@@ -16,5 +17,11 @@ func watchdog(w string, db *gorm.DB) {
return
}
log.Println(files)
for _, f := range files {
i, err := os.Stat(f.Filepath)
if err != nil {
slog.Error("failed to stat the details for one or more files", "error", err)
}
log.Println(i)
}
}