Add Comand to Library
All checks were successful
/ release (push) Successful in 32s

This commit is contained in:
speatzle 2024-10-08 16:42:25 +02:00
parent f401127127
commit 011f97a3e6
5 changed files with 52 additions and 4 deletions

View file

@ -0,0 +1,3 @@
ALTER TABLE libraries
DROP IF EXISTS transcode_command,
DROP IF EXISTS health_command;

View file

@ -0,0 +1,3 @@
ALTER TABLE libraries
ADD transcode_command bigint REFERENCES ffmpeg_commands(id),
ADD health_command bigint REFERENCES ffmpeg_commands(id);

View file

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"log/slog" "log/slog"
"net/http" "net/http"
"strconv"
"git.lastassault.de/speatzle/morffix/constants" "git.lastassault.de/speatzle/morffix/constants"
"github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5"
@ -12,10 +13,13 @@ import (
type LibrariesData struct { type LibrariesData struct {
Libraries []Library Libraries []Library
FfmpegCommands []FfmpegCommand
} }
type Library struct { type Library struct {
ID string `db:"id"` ID string `db:"id"`
HealthCommand *int `db:"health_command"`
TranscodeCommand *int `db:"transcode_command"`
Name string `db:"name"` Name string `db:"name"`
Path string `db:"path"` Path string `db:"path"`
Enable bool `db:"enable"` 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 { if err != nil {
slog.ErrorContext(r.Context(), "Query Libraries", "err", err) slog.ErrorContext(r.Context(), "Query Libraries", "err", err)
http.Error(w, "Error Query Libraries: "+err.Error(), http.StatusInternalServerError) 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 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{} buf := bytes.Buffer{}
err = templates.ExecuteTemplate(&buf, constants.LIBRARIES_TEMPLATE_NAME, data) err = templates.ExecuteTemplate(&buf, constants.LIBRARIES_TEMPLATE_NAME, data)
if err != nil { if err != nil {
@ -84,9 +102,21 @@ func createLibrary(r *http.Request) error {
scan_changed_queue_transcode := r.FormValue("scan_changed_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" 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) 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 { if err != nil {
return fmt.Errorf("Inserting Library: %w", err) return fmt.Errorf("Inserting Library: %w", err)
} }

View file

@ -6,6 +6,18 @@
<label>Full:</label><br /> <label>Full:</label><br />
<input type="checkbox" name="full"><br /> <input type="checkbox" name="full"><br />
<input value="Scan" type="submit"> <input value="Scan" type="submit">
<label for="health_command">Health Command:</label>
<select id="health_command" name="health_command">
{{range $l := .FfmpegCommands}}
<option value="{{$l.ID}}">{{$l.Name}}</option>
{{end}}
</select>
<label for="transcode_command">Transcode Command:</label>
<select id="transcode_command" name="transcode_command">
{{range $l := .FfmpegCommands}}
<option value="{{$l.ID}}">{{$l.Name}}</option>
{{end}}
</select>
</form> </form>
<div class="file-list"> <div class="file-list">
<table> <table>