mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Fix streaming scenes not able to be deleted (#2549)
* Don't navigate away from scene if delete failed * Close connection on cancel
This commit is contained in:
@@ -164,7 +164,8 @@ func (rs sceneRoutes) streamTranscode(w http.ResponseWriter, r *http.Request, st
|
||||
encoder := manager.GetInstance().FFMPEG
|
||||
|
||||
lm := manager.GetInstance().ReadLockManager
|
||||
lockCtx := lm.ReadLock(r.Context(), scene.Path)
|
||||
streamRequestCtx := manager.NewStreamRequestContext(w, r)
|
||||
lockCtx := lm.ReadLock(streamRequestCtx, scene.Path)
|
||||
defer lockCtx.Cancel()
|
||||
|
||||
stream, err := encoder.GetTranscodeStream(lockCtx, options)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package manager
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/stashapp/stash/internal/manager/config"
|
||||
@@ -10,6 +11,31 @@ import (
|
||||
"github.com/stashapp/stash/pkg/utils"
|
||||
)
|
||||
|
||||
type StreamRequestContext struct {
|
||||
context.Context
|
||||
ResponseWriter http.ResponseWriter
|
||||
}
|
||||
|
||||
func NewStreamRequestContext(w http.ResponseWriter, r *http.Request) *StreamRequestContext {
|
||||
return &StreamRequestContext{
|
||||
Context: r.Context(),
|
||||
ResponseWriter: w,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *StreamRequestContext) Cancel() {
|
||||
hj, ok := (c.ResponseWriter).(http.Hijacker)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
// hijack and close the connection
|
||||
conn, _, _ := hj.Hijack()
|
||||
if conn != nil {
|
||||
conn.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func KillRunningStreams(scene *models.Scene, fileNamingAlgo models.HashAlgorithm) {
|
||||
instance.ReadLockManager.Cancel(scene.Path)
|
||||
|
||||
@@ -31,7 +57,8 @@ func (s *SceneServer) StreamSceneDirect(scene *models.Scene, w http.ResponseWrit
|
||||
fileNamingAlgo := config.GetInstance().GetVideoFileNamingAlgorithm()
|
||||
|
||||
filepath := GetInstance().Paths.Scene.GetStreamPath(scene.Path, scene.GetHash(fileNamingAlgo))
|
||||
lockCtx := GetInstance().ReadLockManager.ReadLock(r.Context(), filepath)
|
||||
streamRequestCtx := NewStreamRequestContext(w, r)
|
||||
lockCtx := GetInstance().ReadLockManager.ReadLock(streamRequestCtx, filepath)
|
||||
defer lockCtx.Cancel()
|
||||
http.ServeFile(w, r, filepath)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user