mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-18 07:53:19 +03:00
feat: add X-Content-Duration header to the stream response
This commit is contained in:
parent
8a31e80b7a
commit
a37beac753
@ -31,6 +31,7 @@ type mediaStream interface {
|
|||||||
Name() string
|
Name() string
|
||||||
ModTime() time.Time
|
ModTime() time.Time
|
||||||
Close() error
|
Close() error
|
||||||
|
Duration() int
|
||||||
}
|
}
|
||||||
|
|
||||||
type mediaStreamer struct {
|
type mediaStreamer struct {
|
||||||
@ -108,6 +109,10 @@ func (m *rawMediaStream) ModTime() time.Time {
|
|||||||
return m.mf.UpdatedAt
|
return m.mf.UpdatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *rawMediaStream) Duration() int {
|
||||||
|
return m.mf.Duration
|
||||||
|
}
|
||||||
|
|
||||||
func (m *rawMediaStream) Close() error {
|
func (m *rawMediaStream) Close() error {
|
||||||
log.Trace(m.ctx, "Closing file", "id", m.mf.ID, "path", m.mf.Path)
|
log.Trace(m.ctx, "Closing file", "id", m.mf.ID, "path", m.mf.Path)
|
||||||
return m.file.Close()
|
return m.file.Close()
|
||||||
@ -186,6 +191,10 @@ func (m *transcodedMediaStream) ModTime() time.Time {
|
|||||||
return m.mf.UpdatedAt
|
return m.mf.UpdatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *transcodedMediaStream) Duration() int {
|
||||||
|
return m.mf.Duration
|
||||||
|
}
|
||||||
|
|
||||||
func (m *transcodedMediaStream) Close() error {
|
func (m *transcodedMediaStream) Close() error {
|
||||||
log.Trace(m.ctx, "Closing stream", "id", m.mf.ID, "path", m.mf.Path)
|
log.Trace(m.ctx, "Closing stream", "id", m.mf.ID, "path", m.mf.Path)
|
||||||
err := m.pipe.Close()
|
err := m.pipe.Close()
|
||||||
|
@ -2,6 +2,7 @@ package subsonic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/deluan/navidrome/engine"
|
"github.com/deluan/navidrome/engine"
|
||||||
"github.com/deluan/navidrome/server/subsonic/responses"
|
"github.com/deluan/navidrome/server/subsonic/responses"
|
||||||
@ -31,6 +32,7 @@ func (c *StreamController) Stream(w http.ResponseWriter, r *http.Request) (*resp
|
|||||||
|
|
||||||
// Override Content-Type detected by http.FileServer
|
// Override Content-Type detected by http.FileServer
|
||||||
w.Header().Set("Content-Type", ms.ContentType())
|
w.Header().Set("Content-Type", ms.ContentType())
|
||||||
|
w.Header().Set("X-Content-Duration", strconv.Itoa(ms.Duration()))
|
||||||
http.ServeContent(w, r, ms.Name(), ms.ModTime(), ms)
|
http.ServeContent(w, r, ms.Name(), ms.ModTime(), ms)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user