|
|
|
@ -106,7 +106,7 @@ outer: |
|
|
|
for { |
|
|
|
for { |
|
|
|
select { |
|
|
|
select { |
|
|
|
case req := <-s.request: |
|
|
|
case req := <-s.request: |
|
|
|
c, ok := s.converters[req.Path] |
|
|
|
c, ok := s.converters[req.Dir] |
|
|
|
if !ok { |
|
|
|
if !ok { |
|
|
|
c = hlsconverter.New( |
|
|
|
c = hlsconverter.New( |
|
|
|
s.ctx, |
|
|
|
s.ctx, |
|
|
|
@ -115,10 +115,10 @@ outer: |
|
|
|
s.readBufferCount, |
|
|
|
s.readBufferCount, |
|
|
|
&s.wg, |
|
|
|
&s.wg, |
|
|
|
s.stats, |
|
|
|
s.stats, |
|
|
|
req.Path, |
|
|
|
req.Dir, |
|
|
|
s.pathMan, |
|
|
|
s.pathMan, |
|
|
|
s) |
|
|
|
s) |
|
|
|
s.converters[req.Path] = c |
|
|
|
s.converters[req.Dir] = c |
|
|
|
} |
|
|
|
} |
|
|
|
c.OnRequest(req) |
|
|
|
c.OnRequest(req) |
|
|
|
|
|
|
|
|
|
|
|
@ -164,28 +164,28 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pa, fname := func() (string, string) { |
|
|
|
dir, fname := func() (string, string) { |
|
|
|
if strings.HasSuffix(pa, ".ts") || strings.HasSuffix(pa, ".m3u8") { |
|
|
|
if strings.HasSuffix(pa, ".ts") || strings.HasSuffix(pa, ".m3u8") { |
|
|
|
return path.Dir(pa), path.Base(pa) |
|
|
|
return path.Dir(pa), path.Base(pa) |
|
|
|
} |
|
|
|
} |
|
|
|
return pa, "" |
|
|
|
return pa, "" |
|
|
|
}() |
|
|
|
}() |
|
|
|
|
|
|
|
|
|
|
|
if fname == "" && !strings.HasSuffix(pa, "/") { |
|
|
|
if fname == "" && !strings.HasSuffix(dir, "/") { |
|
|
|
w.Header().Add("Location", "/"+pa+"/") |
|
|
|
w.Header().Add("Location", "/"+dir+"/") |
|
|
|
w.WriteHeader(http.StatusMovedPermanently) |
|
|
|
w.WriteHeader(http.StatusMovedPermanently) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pa = strings.TrimSuffix(pa, "/") |
|
|
|
dir = strings.TrimSuffix(dir, "/") |
|
|
|
|
|
|
|
|
|
|
|
cres := make(chan io.Reader) |
|
|
|
cres := make(chan io.Reader) |
|
|
|
hreq := hlsconverter.Request{ |
|
|
|
hreq := hlsconverter.Request{ |
|
|
|
Path: pa, |
|
|
|
Dir: dir, |
|
|
|
FileName: fname, |
|
|
|
File: fname, |
|
|
|
Req: r, |
|
|
|
Req: r, |
|
|
|
W: w, |
|
|
|
W: w, |
|
|
|
Res: cres, |
|
|
|
Res: cres, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
select { |
|
|
|
select { |
|
|
|
|