This commit is contained in:
parent
f401127127
commit
011f97a3e6
5 changed files with 52 additions and 4 deletions
|
@ -5,17 +5,21 @@ import (
|
|||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"git.lastassault.de/speatzle/morffix/constants"
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
type LibrariesData struct {
|
||||
Libraries []Library
|
||||
Libraries []Library
|
||||
FfmpegCommands []FfmpegCommand
|
||||
}
|
||||
|
||||
type Library struct {
|
||||
ID string `db:"id"`
|
||||
HealthCommand *int `db:"health_command"`
|
||||
TranscodeCommand *int `db:"transcode_command"`
|
||||
Name string `db:"name"`
|
||||
Path string `db:"path"`
|
||||
Enable bool `db:"enable"`
|
||||
|
@ -40,7 +44,7 @@ func handleLibraries(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
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")
|
||||
rows, err := db.Query(r.Context(), "SELECT * FROM libraries")
|
||||
if err != nil {
|
||||
slog.ErrorContext(r.Context(), "Query Libraries", "err", err)
|
||||
http.Error(w, "Error Query Libraries: "+err.Error(), http.StatusInternalServerError)
|
||||
|
@ -54,6 +58,20 @@ func handleLibraries(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
data.Libraries = libraries
|
||||
|
||||
rows, err = db.Query(r.Context(), "SELECT id, name, data FROM ffmpeg_commands")
|
||||
if err != nil {
|
||||
slog.ErrorContext(r.Context(), "Query Ffmpeg Commands", "err", err)
|
||||
http.Error(w, "Error Ffmpeg Commands: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
ffmpegCommands, err := pgx.CollectRows[FfmpegCommand](rows, pgx.RowToStructByName[FfmpegCommand])
|
||||
if err != nil {
|
||||
slog.ErrorContext(r.Context(), "Collect Ffmpeg Commands", "err", err)
|
||||
http.Error(w, "Error Collect Ffmpeg Commands: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
data.FfmpegCommands = ffmpegCommands
|
||||
|
||||
buf := bytes.Buffer{}
|
||||
err = templates.ExecuteTemplate(&buf, constants.LIBRARIES_TEMPLATE_NAME, data)
|
||||
if err != nil {
|
||||
|
@ -84,9 +102,21 @@ func createLibrary(r *http.Request) error {
|
|||
scan_changed_queue_transcode := r.FormValue("scan_changed_queue_transcode") == "on"
|
||||
health_ok_queue_transcode := r.FormValue("health_ok_queue_transcode") == "on"
|
||||
|
||||
var health_command *int = nil
|
||||
var transcode_command *int = nil
|
||||
|
||||
h, err := strconv.Atoi(r.FormValue("health_command"))
|
||||
if err == nil {
|
||||
health_command = &h
|
||||
}
|
||||
t, err := strconv.Atoi(r.FormValue("transcode_command"))
|
||||
if err == nil {
|
||||
transcode_command = &t
|
||||
}
|
||||
|
||||
slog.Info("Got Library Create", "name", name, "path", path, "enable", 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)
|
||||
_, 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, health_command, transcode_command) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)", 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, health_command, transcode_command)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Inserting Library: %w", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue