This commit is contained in:
parent
f401127127
commit
011f97a3e6
5 changed files with 52 additions and 4 deletions
3
migrations/000019_alter_libraries_table_command.down.sql
Normal file
3
migrations/000019_alter_libraries_table_command.down.sql
Normal file
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE libraries
|
||||
DROP IF EXISTS transcode_command,
|
||||
DROP IF EXISTS health_command;
|
3
migrations/000019_alter_libraries_table_command.up.sql
Normal file
3
migrations/000019_alter_libraries_table_command.up.sql
Normal file
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE libraries
|
||||
ADD transcode_command bigint REFERENCES ffmpeg_commands(id),
|
||||
ADD health_command bigint REFERENCES ffmpeg_commands(id);
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -6,6 +6,18 @@
|
|||
<label>Full:</label><br />
|
||||
<input type="checkbox" name="full"><br />
|
||||
<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>
|
||||
<div class="file-list">
|
||||
<table>
|
||||
|
@ -49,4 +61,4 @@
|
|||
{{end}}
|
||||
</table>
|
||||
</div>
|
||||
{{template "tail"}}
|
||||
{{template "tail"}}
|
||||
|
|
Loading…
Add table
Reference in a new issue