add content-disposition filename header to streams (#6119)

* add content-disposition filename header to streams
* Fix filename generation on windows
---------
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
fancydancers 2025-10-09 02:35:11 +00:00 committed by GitHub
parent c5bad48ece
commit 2ed9e5332d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,7 +3,9 @@ package manager
import ( import (
"context" "context"
"errors" "errors"
"mime"
"net/http" "net/http"
"path/filepath"
"github.com/stashapp/stash/internal/manager/config" "github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/internal/static" "github.com/stashapp/stash/internal/static"
@ -46,14 +48,17 @@ func (s *SceneServer) StreamSceneDirect(scene *models.Scene, w http.ResponseWrit
sceneHash := scene.GetHash(config.GetInstance().GetVideoFileNamingAlgorithm()) sceneHash := scene.GetHash(config.GetInstance().GetVideoFileNamingAlgorithm())
filepath := GetInstance().Paths.Scene.GetStreamPath(scene.Path, sceneHash) fp := GetInstance().Paths.Scene.GetStreamPath(scene.Path, sceneHash)
streamRequestCtx := ffmpeg.NewStreamRequestContext(w, r) streamRequestCtx := ffmpeg.NewStreamRequestContext(w, r)
// #2579 - hijacking and closing the connection here causes video playback to fail in Safari // #2579 - hijacking and closing the connection here causes video playback to fail in Safari
// We trust that the request context will be closed, so we don't need to call Cancel on the // We trust that the request context will be closed, so we don't need to call Cancel on the
// returned context here. // returned context here.
_ = GetInstance().ReadLockManager.ReadLock(streamRequestCtx, filepath) _ = GetInstance().ReadLockManager.ReadLock(streamRequestCtx, fp)
http.ServeFile(w, r, filepath) _, filename := filepath.Split(fp)
contentDisposition := mime.FormatMediaType("inline", map[string]string{"filename": filename})
w.Header().Set("Content-Disposition", contentDisposition)
http.ServeFile(w, r, fp)
} }
func (s *SceneServer) ServeScreenshot(scene *models.Scene, w http.ResponseWriter, r *http.Request) { func (s *SceneServer) ServeScreenshot(scene *models.Scene, w http.ResponseWriter, r *http.Request) {