change wait info torrent

This commit is contained in:
YouROK
2020-12-16 17:00:28 +03:00
parent 1a7cd21917
commit 706c1c6bdf

View File

@@ -2,15 +2,20 @@ package torr
import (
"errors"
"fmt"
"log"
"net/http"
"time"
"github.com/anacrolix/missinggo/httptoo"
sets "server/settings"
)
func (t *Torrent) Stream(fileIndex int, req *http.Request, resp http.ResponseWriter) error {
t.WaitInfo()
if !t.GotInfo() {
http.NotFound(resp, req)
return errors.New("torrent don't get info")
}
files := t.Files()
if fileIndex < 1 || fileIndex > len(files) {
return errors.New("file index out of range")
@@ -22,9 +27,8 @@ func (t *Torrent) Stream(fileIndex int, req *http.Request, resp http.ResponseWri
sets.SetViewed(&sets.Viewed{t.Hash().HexString(), fileIndex})
//TODO проверить почему плеер постоянно переподключается
resp.Header().Set("Connection", "close")
//resp.Header().Set("ETag", httptoo.EncodeQuotedString(fmt.Sprintf("%s/%s", t.Hash().HexString(), file.Path())))
resp.Header().Set("ETag", httptoo.EncodeQuotedString(fmt.Sprintf("%s/%s", t.Hash().HexString(), file.Path())))
http.ServeContent(resp, req, file.Path(), time.Unix(t.Timestamp, 0), reader)