chore: fix a small issue with video modes
This commit is contained in:
+1
-1
@@ -30,8 +30,8 @@ func main() {
|
|||||||
db, err := database.KickoffDatabase(env.DataDirectory)
|
db, err := database.KickoffDatabase(env.DataDirectory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("failed to initiate a database connection")
|
slog.Error("failed to initiate a database connection")
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
slog.Info("kicking off database watchdog", "watch_interval", env.WatchInterval)
|
slog.Info("kicking off database watchdog", "watch_interval", env.WatchInterval)
|
||||||
database.KickoffDatabaseWatchdog(env, db)
|
database.KickoffDatabaseWatchdog(env, db)
|
||||||
|
|
||||||
|
|||||||
@@ -13,14 +13,14 @@ import (
|
|||||||
// 1: video
|
// 1: video
|
||||||
// 2: presentation
|
// 2: presentation
|
||||||
// 3: internet URL
|
// 3: internet URL
|
||||||
func categorizeFilemode(ext string) database.Mode {
|
func categorizeFilemode(ext string) database.MediaType {
|
||||||
switch ext {
|
switch ext {
|
||||||
case ".mp4", ".mov", ".avi", ".mkv", ".webm", ".m4a":
|
case ".mp4", ".mov", ".avi", ".mkv", ".webm", ".m4a":
|
||||||
return database.ModeVideo
|
return database.Video
|
||||||
case ".pptx", ".ppt", ".key", ".odp":
|
case ".pptx", ".ppt", ".key", ".odp":
|
||||||
return database.ModePresentation
|
return database.Presentation
|
||||||
default:
|
default:
|
||||||
return database.ModeUnspecified
|
return database.Unspecified
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func spawnFileRoutes(file *gin.RouterGroup, env runtime.Environment, db *gorm.DB
|
|||||||
|
|
||||||
e := filepath.Ext(f.Filename)
|
e := filepath.Ext(f.Filename)
|
||||||
m := categorizeFilemode(e)
|
m := categorizeFilemode(e)
|
||||||
if m == database.ModeUnspecified {
|
if m == database.Unspecified {
|
||||||
slog.Warn("discarding file since its filetype is unsupported")
|
slog.Warn("discarding file since its filetype is unsupported")
|
||||||
c.JSON(http.StatusUnsupportedMediaType, RespObj{
|
c.JSON(http.StatusUnsupportedMediaType, RespObj{
|
||||||
Msg: "unsupported filetype",
|
Msg: "unsupported filetype",
|
||||||
@@ -66,7 +66,7 @@ func spawnFileRoutes(file *gin.RouterGroup, env runtime.Environment, db *gorm.DB
|
|||||||
log.Println(cSum)
|
log.Println(cSum)
|
||||||
|
|
||||||
fData := database.File{
|
fData := database.File{
|
||||||
Mode: m,
|
MediaType: m,
|
||||||
GivenName: f.Filename,
|
GivenName: f.Filename,
|
||||||
Filepath: destPath,
|
Filepath: destPath,
|
||||||
Checksum: cSum,
|
Checksum: cSum,
|
||||||
|
|||||||
@@ -21,14 +21,17 @@ func KickoffDatabase(workDir string) (*gorm.DB, error) {
|
|||||||
if err := db.AutoMigrate(&State{}); err != nil {
|
if err := db.AutoMigrate(&State{}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if err := db.AutoMigrate(&Device{}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if err := db.AutoMigrate(&File{}); err != nil {
|
if err := db.AutoMigrate(&File{}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the first row if it does not exist yet
|
// create the first row if it does not exist yet
|
||||||
if err := db.FirstOrCreate(&State{}, State{
|
if err := db.FirstOrCreate(&State{}, State{
|
||||||
ID: 0,
|
ID: 0,
|
||||||
Mode: "unspecified",
|
MediaType: "unspecified",
|
||||||
}).Error; err != nil {
|
}).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ import (
|
|||||||
"gorm.io/datatypes"
|
"gorm.io/datatypes"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Mode string
|
type MediaType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ModeUnspecified Mode = "unspecified"
|
Unspecified MediaType = "unspecified"
|
||||||
ModeVideo Mode = "video"
|
Video MediaType = "video"
|
||||||
ModePresentation Mode = "presentation"
|
Presentation MediaType = "presentation"
|
||||||
ModeInternet Mode = "internet"
|
Internet MediaType = "internet"
|
||||||
)
|
)
|
||||||
|
|
||||||
type State struct {
|
type State struct {
|
||||||
@@ -21,7 +21,7 @@ type State struct {
|
|||||||
// video
|
// video
|
||||||
// presentation
|
// presentation
|
||||||
// internet URL
|
// 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
|
Targets datatypes.JSON
|
||||||
Location string // Must be the location where the file is downloadable on the API
|
Location string // Must be the location where the file is downloadable on the API
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
@@ -39,8 +39,8 @@ type Device struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
ID int `gorm:"primaryKey"`
|
ID int `gorm:"primaryKey"`
|
||||||
Mode Mode `gorm:"type:varchar(20);not null"`
|
MediaType MediaType `gorm:"type:varchar(20);not null;"`
|
||||||
GivenName string
|
GivenName string
|
||||||
Filepath string
|
Filepath string
|
||||||
Checksum string // base64 encoded sha512 checksum
|
Checksum string // base64 encoded sha512 checksum
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package database
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
"os"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@@ -16,5 +17,11 @@ func watchdog(w string, db *gorm.DB) {
|
|||||||
return
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user