Use database status and health, calculate md5
This commit is contained in:
parent
806f6e7e61
commit
78d818b8d1
7 changed files with 112 additions and 37 deletions
|
@ -2,6 +2,7 @@ package server
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
|
@ -11,14 +12,25 @@ import (
|
|||
|
||||
type LibraryData struct {
|
||||
Library Library
|
||||
Files []File
|
||||
Files []FileDisplay
|
||||
}
|
||||
|
||||
type File struct {
|
||||
ID int `db:"id"`
|
||||
Path string `db:"path"`
|
||||
Size int64 `db:"size"`
|
||||
Missing bool `db:"missing"`
|
||||
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"`
|
||||
}
|
||||
|
||||
type FileDisplay struct {
|
||||
ID int
|
||||
Path string
|
||||
Size int64
|
||||
Status string
|
||||
Health string
|
||||
MD5 string
|
||||
}
|
||||
|
||||
func handleLibrary(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -50,7 +62,7 @@ func handleLibrary(w http.ResponseWriter, r *http.Request) {
|
|||
// TODO
|
||||
}
|
||||
|
||||
rows, err := db.Query(r.Context(), "SELECT id, path, size, missing FROM files where library_id = $1", id)
|
||||
rows, err := db.Query(r.Context(), "SELECT id, path, size, status, health, md5 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)
|
||||
|
@ -62,7 +74,17 @@ func handleLibrary(w http.ResponseWriter, r *http.Request) {
|
|||
http.Error(w, "Error Query Files: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
data.Files = files
|
||||
|
||||
for i := range files {
|
||||
data.Files = append(data.Files, FileDisplay{
|
||||
ID: files[i].ID,
|
||||
Path: files[i].Path,
|
||||
Size: files[i].Size,
|
||||
Status: files[i].Status.String(),
|
||||
Health: files[i].Health.String(),
|
||||
MD5: fmt.Sprintf("%x", files[i].MD5),
|
||||
})
|
||||
}
|
||||
|
||||
buf := bytes.Buffer{}
|
||||
err = templates.ExecuteTemplate(&buf, constants.LIBRARY_TEMPLATE_NAME, data)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue