Add Library and Transcode Options

This commit is contained in:
Samuel Lorch 2024-06-22 21:01:20 +02:00
parent cdc94d551d
commit 249a415cee
12 changed files with 134 additions and 20 deletions

View file

@ -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)
}

View file

@ -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),
})

View file

@ -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)