From 249a415cee8fcc534c3519851657e22dd0d8ca8e Mon Sep 17 00:00:00 2001 From: Samuel Lorch Date: Sat, 22 Jun 2024 21:01:20 +0200 Subject: [PATCH] Add Library and Transcode Options --- constants/constants.go | 27 ++++++++++ ...00005_alter_task_table_updated_at.down.sql | 2 +- ...00010_alter_files_table_transcode.down.sql | 2 + .../000010_alter_files_table_transcode.up.sql | 2 + ..._alter_libraries_table_options.up.down.sql | 8 +++ ...00011_alter_libraries_table_options.up.sql | 8 +++ server/libraries.go | 27 +++++++--- server/library.go | 19 ++++--- server/task.go | 2 +- tmpl/libraries.tmpl | 50 +++++++++++++++++-- tmpl/library.tmpl | 6 +++ tmpl/tasks.tmpl | 1 + 12 files changed, 134 insertions(+), 20 deletions(-) create mode 100644 migrations/000010_alter_files_table_transcode.down.sql create mode 100644 migrations/000010_alter_files_table_transcode.up.sql create mode 100644 migrations/000011_alter_libraries_table_options.up.down.sql create mode 100644 migrations/000011_alter_libraries_table_options.up.sql diff --git a/constants/constants.go b/constants/constants.go index 4376da2..52ead95 100644 --- a/constants/constants.go +++ b/constants/constants.go @@ -64,6 +64,7 @@ const ( FILE_STATUS_UNKNOWN FileStatus = iota FILE_STATUS_MISSING FILE_STATUS_EXISTS + FILE_STATUS_CHANGED ) func (s FileStatus) String() string { @@ -74,6 +75,8 @@ func (s FileStatus) String() string { return "Missing" case FILE_STATUS_EXISTS: return "Exists" + case FILE_STATUS_CHANGED: + return "Changed" default: return fmt.Sprintf("%d", int(s)) } @@ -99,3 +102,27 @@ func (s FileHealth) String() string { return fmt.Sprintf("%d", int(s)) } } + +type FileTranscode int + +const ( + FILE_TRANSCODE_UNKNOWN FileTranscode = iota + FILE_TRANSCODE_NONE + FILE_TRANSCODE_FAILED + FILE_TRANSCODE_SUCCESS +) + +func (s FileTranscode) String() string { + switch s { + case FILE_TRANSCODE_UNKNOWN: + return "Unknown" + case FILE_TRANSCODE_NONE: + return "None" + case FILE_TRANSCODE_FAILED: + return "Failed" + case FILE_TRANSCODE_SUCCESS: + return "Success" + default: + return fmt.Sprintf("%d", int(s)) + } +} diff --git a/migrations/000005_alter_task_table_updated_at.down.sql b/migrations/000005_alter_task_table_updated_at.down.sql index c2a5250..b6460e9 100644 --- a/migrations/000005_alter_task_table_updated_at.down.sql +++ b/migrations/000005_alter_task_table_updated_at.down.sql @@ -1,2 +1,2 @@ ALTER TABLE tasks -DROP updated_at; \ No newline at end of file +DROP IF EXISTS updated_at; \ No newline at end of file diff --git a/migrations/000010_alter_files_table_transcode.down.sql b/migrations/000010_alter_files_table_transcode.down.sql new file mode 100644 index 0000000..b64a692 --- /dev/null +++ b/migrations/000010_alter_files_table_transcode.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE files +DROP IF EXISTS transcode; \ No newline at end of file diff --git a/migrations/000010_alter_files_table_transcode.up.sql b/migrations/000010_alter_files_table_transcode.up.sql new file mode 100644 index 0000000..6fac4b8 --- /dev/null +++ b/migrations/000010_alter_files_table_transcode.up.sql @@ -0,0 +1,2 @@ +ALTER TABLE files +ADD transcode smallint NOT NULL DEFAULT 1; \ No newline at end of file diff --git a/migrations/000011_alter_libraries_table_options.up.down.sql b/migrations/000011_alter_libraries_table_options.up.down.sql new file mode 100644 index 0000000..a020658 --- /dev/null +++ b/migrations/000011_alter_libraries_table_options.up.down.sql @@ -0,0 +1,8 @@ +ALTER TABLE libraries +DROP IF EXISTS scan_new_queue_health, +DROP IF EXISTS scan_changed_queue_health, +DROP IF EXISTS scan_new_queue_transcode, +DROP IF EXISTS scan_changed_queue_transcode, +DROP IF EXISTS health_ok_queue_transcode, +DROP IF EXISTS transcode_replace, +DROP IF EXISTS transcode_path; diff --git a/migrations/000011_alter_libraries_table_options.up.sql b/migrations/000011_alter_libraries_table_options.up.sql new file mode 100644 index 0000000..3c785f0 --- /dev/null +++ b/migrations/000011_alter_libraries_table_options.up.sql @@ -0,0 +1,8 @@ +ALTER TABLE libraries +ADD scan_new_queue_health boolean NOT NULL DEFAULT false, +ADD scan_changed_queue_health boolean NOT NULL DEFAULT false, +ADD scan_new_queue_transcode boolean NOT NULL DEFAULT false, +ADD scan_changed_queue_transcode boolean NOT NULL DEFAULT false, +ADD health_ok_queue_transcode boolean NOT NULL DEFAULT false, +ADD transcode_replace boolean NOT NULL DEFAULT false, +ADD transcode_path VARCHAR (500) NOT NULL DEFAULT ''; diff --git a/server/libraries.go b/server/libraries.go index b5d0f64..1daf58f 100644 --- a/server/libraries.go +++ b/server/libraries.go @@ -15,10 +15,17 @@ type LibrariesData struct { } type Library struct { - ID string `db:"id"` - Name string `db:"name"` - Path string `db:"path"` - Enable bool `db:"enable"` + ID string `db:"id"` + Name string `db:"name"` + Path string `db:"path"` + Enable bool `db:"enable"` + TranscodeReplace bool `db:"transcode_replace"` + TranscodePath string `db:"transcode_path"` + ScanNewQueueHealth bool `db:"scan_new_queue_health"` + ScanChangedQueueHealth bool `db:"scan_changed_queue_health"` + ScanNewQueueTranscode bool `db:"scan_new_queue_transcode"` + ScanChangedQueueTranscode bool `db:"scan_changed_queue_transcode"` + HealthOkQueueTranscode bool `db:"health_ok_queue_transcode"` } func handleLibraries(w http.ResponseWriter, r *http.Request) { @@ -33,7 +40,7 @@ func handleLibraries(w http.ResponseWriter, r *http.Request) { } } - rows, err := db.Query(r.Context(), "SELECT id, name, path, enable FROM libraries") + rows, err := db.Query(r.Context(), "SELECT id, name, path, enable, scan_new_queue_health, scan_changed_queue_health, scan_new_queue_transcode, scan_changed_queue_transcode, health_ok_queue_transcode, transcode_replace, transcode_path FROM libraries") if err != nil { slog.ErrorContext(r.Context(), "Query Libraries", "err", err) http.Error(w, "Error Query Libraries: "+err.Error(), http.StatusInternalServerError) @@ -69,9 +76,17 @@ func createLibrary(r *http.Request) error { name := r.FormValue("name") path := r.FormValue("path") enable := r.FormValue("enable") == "on" + transcode_replace := r.FormValue("transcode_replace") == "on" + transcode_path := r.FormValue("transcode_path") + scan_new_queue_health := r.FormValue("scan_new_queue_health") == "on" + scan_changed_queue_health := r.FormValue("scan_changed_queue_health") == "on" + scan_new_queue_transcode := r.FormValue("scan_new_queue_transcode") == "on" + scan_changed_queue_transcode := r.FormValue("scan_changed_queue_transcode") == "on" + health_ok_queue_transcode := r.FormValue("health_ok_queue_transcode") == "on" + slog.Info("Got Library Create", "name", name, "path", path, "enable", enable) - _, err = db.Exec(r.Context(), "INSERT INTO Libraries (name, path, enable) VALUES ($1,$2,$3)", name, path, enable) + _, err = db.Exec(r.Context(), "INSERT INTO Libraries (name, path, enable, scan_new_queue_health, scan_changed_queue_health, scan_new_queue_transcode, scan_changed_queue_transcode, health_ok_queue_transcode, transcode_replace, transcode_path) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)", name, path, enable, scan_new_queue_health, scan_changed_queue_health, scan_new_queue_transcode, scan_changed_queue_transcode, health_ok_queue_transcode, transcode_replace, transcode_path) if err != nil { return fmt.Errorf("Inserting Library: %w", err) } diff --git a/server/library.go b/server/library.go index dca25ad..8e43f62 100644 --- a/server/library.go +++ b/server/library.go @@ -17,13 +17,14 @@ type LibraryData struct { } type File struct { - ID int `db:"id"` - Path string `db:"path"` - Size int64 `db:"size"` - Status constants.FileStatus `db:"status"` - Health constants.FileHealth `db:"health"` - MD5 []byte `db:"md5"` - UpdatedAt time.Time `db:"updated_at"` + ID int `db:"id"` + Path string `db:"path"` + Size int64 `db:"size"` + Status constants.FileStatus `db:"status"` + Health constants.FileHealth `db:"health"` + Transcode constants.FileTranscode `db:"transcode"` + MD5 []byte `db:"md5"` + UpdatedAt time.Time `db:"updated_at"` } type FileDisplay struct { @@ -32,6 +33,7 @@ type FileDisplay struct { Size int64 Status string Health string + Transcode string MD5 string UpdatedAt string `db:"updated_at"` } @@ -65,7 +67,7 @@ func handleLibrary(w http.ResponseWriter, r *http.Request) { // TODO } - rows, err := db.Query(r.Context(), "SELECT id, path, size, status, health, md5, updated_at FROM files where library_id = $1", id) + rows, err := db.Query(r.Context(), "SELECT id, path, size, status, health, transcode, md5, updated_at FROM files where library_id = $1", id) if err != nil { slog.ErrorContext(r.Context(), "Query Files", "err", err) http.Error(w, "Error Query Files: "+err.Error(), http.StatusInternalServerError) @@ -85,6 +87,7 @@ func handleLibrary(w http.ResponseWriter, r *http.Request) { Size: files[i].Size, Status: files[i].Status.String(), Health: files[i].Health.String(), + Transcode: files[i].Transcode.String(), MD5: fmt.Sprintf("%x", files[i].MD5), UpdatedAt: files[i].UpdatedAt.Format(time.DateTime), }) diff --git a/server/task.go b/server/task.go index d74d525..526bcb7 100644 --- a/server/task.go +++ b/server/task.go @@ -82,7 +82,7 @@ func handleTasks(w http.ResponseWriter, r *http.Request) { return } - rows, err := db.Query(r.Context(), "SELECT id, name, path, enable FROM libraries WHERE enable = $1", true) + rows, err := db.Query(r.Context(), "SELECT id, name, path, enable, scan_new_queue_health, scan_changed_queue_health, scan_new_queue_transcode, scan_changed_queue_transcode, health_ok_queue_transcode, transcode_replace, transcode_path FROM libraries WHERE enable = $1", true) if err != nil { slog.ErrorContext(r.Context(), "Query Libraries", "err", err) http.Error(w, "Error Query Libraries: "+err.Error(), http.StatusInternalServerError) diff --git a/tmpl/libraries.tmpl b/tmpl/libraries.tmpl index 3baf9b7..74faf04 100644 --- a/tmpl/libraries.tmpl +++ b/tmpl/libraries.tmpl @@ -3,15 +3,25 @@ + - + + + + + + + {{range $l := .Libraries}} + @@ -19,7 +29,25 @@ {{ $l.Path }} + + + + + + {{end}} @@ -27,12 +55,26 @@

New Library

+ + - - + + + + + + + + + + + + + + {{template "tail"}} \ No newline at end of file diff --git a/tmpl/library.tmpl b/tmpl/library.tmpl index e216ff4..1ae79a0 100644 --- a/tmpl/library.tmpl +++ b/tmpl/library.tmpl @@ -3,6 +3,8 @@

{{if .Library.Enable}}Enabled{{else}}Disabled{{end}}

Files

+
+
@@ -13,6 +15,7 @@
+ @@ -33,6 +36,9 @@ + diff --git a/tmpl/tasks.tmpl b/tmpl/tasks.tmpl index 4ae8423..ac7ff75 100644 --- a/tmpl/tasks.tmpl +++ b/tmpl/tasks.tmpl @@ -17,6 +17,7 @@
IDEnabled Name PathEnabledTranscodeReplaceTranscodePathScanNewQueueHealthScanChangedQueueHealthScanNewQueueTranscodeScanChangedQueueTranscodeHealthOkQueueTranscode
{{ $l.ID }} + {{ $l.Enable }} + {{ $l.Name }} - {{ $l.Enable }} + {{ $l.TranscodeReplace }} + + {{ $l.TranscodePath }} + + {{ $l.ScanNewQueueHealth }} + + {{ $l.ScanChangedQueueHealth }} + + {{ $l.ScanNewQueueTranscode }} + + {{ $l.ScanChangedQueueTranscode }} + + {{ $l.HealthOkQueueTranscode }}
Size Status HealthTranscode MD5 Updated At
{{ $f.Health }} + {{ $f.Transcode }} + {{ $f.MD5 }}