Item-shaped results now omit empty fields and drop low-value metadata (overview, lyrics, file_path, creation_date, premiere_date, bitrate); absent numeric fields drop the key instead of emitting "". Player sessions report hh:mm:ss times only; playlists drop overview/date_created. The lyrics_or_description search parameter is removed, along with the unused DTO fields, and upstream Fields requests are slimmed to match. Module path renamed to git.i3omb.com/gronod/emby-mcp.
45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package mcphttp
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"net/http"
|
|
|
|
"git.i3omb.com/gronod/emby-mcp/internal/applog"
|
|
)
|
|
|
|
func bodyLogger(layer string, next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
var reqBody []byte
|
|
if r.Body != nil {
|
|
reqBody, _ = io.ReadAll(io.LimitReader(r.Body, 1<<20))
|
|
r.Body = io.NopCloser(bytes.NewReader(reqBody))
|
|
}
|
|
buf := &bytes.Buffer{}
|
|
cw := &captureWriter{ResponseWriter: w, buf: buf}
|
|
next.ServeHTTP(cw, r)
|
|
switch layer {
|
|
case "rest":
|
|
applog.REST("%s %s req=%s resp=%s", r.Method, r.URL.Path, applog.Body(reqBody), applog.Body(buf.Bytes()))
|
|
default:
|
|
applog.MCP("%s %s req=%s resp=%s", r.Method, r.URL.Path, applog.Body(reqBody), applog.Body(buf.Bytes()))
|
|
}
|
|
})
|
|
}
|
|
|
|
type captureWriter struct {
|
|
http.ResponseWriter
|
|
buf *bytes.Buffer
|
|
code int
|
|
}
|
|
|
|
func (w *captureWriter) Write(p []byte) (int, error) {
|
|
_, _ = w.buf.Write(p)
|
|
return w.ResponseWriter.Write(p)
|
|
}
|
|
|
|
func (w *captureWriter) WriteHeader(code int) {
|
|
w.code = code
|
|
w.ResponseWriter.WriteHeader(code)
|
|
}
|