mirror of
https://github.com/owncast/owncast.git
synced 2024-10-10 19:16:02 +00:00
Fix base path string parsing
This commit is contained in:
parent
8cd8c7df20
commit
a55e5ccce9
20
s3Storage.go
20
s3Storage.go
@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -65,10 +64,12 @@ func (s *S3Storage) Save(filePath string) string {
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The following is a bit of a hack to take the location URL string of that file
|
||||||
|
// and get just the base URL without the file from it.
|
||||||
pathComponents := strings.Split(url.Path, "/")
|
pathComponents := strings.Split(url.Path, "/")
|
||||||
pathComponents[len(pathComponents)-1] = ""
|
pathComponents[len(pathComponents)-1] = ""
|
||||||
|
pathString := strings.Join(pathComponents, "/")
|
||||||
s.host = fmt.Sprintf("%s://%s/%s", url.Scheme, url.Host, strings.Join(pathComponents, "/"))
|
s.host = fmt.Sprintf("%s://%s%s", url.Scheme, url.Host, pathString)
|
||||||
}
|
}
|
||||||
|
|
||||||
// fmt.Println("Uploaded", filePath, "to", response.Location)
|
// fmt.Println("Uploaded", filePath, "to", response.Location)
|
||||||
@ -77,20 +78,27 @@ func (s *S3Storage) Save(filePath string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *S3Storage) GenerateRemotePlaylist(playlist string, segments map[string]string) string {
|
func (s *S3Storage) GenerateRemotePlaylist(playlist string, segments map[string]string) string {
|
||||||
|
baseHost, err := url.Parse(s.host)
|
||||||
|
baseHostComponents := []string{baseHost.Scheme + "://", baseHost.Host, baseHost.Path}
|
||||||
|
|
||||||
|
verifyError(err)
|
||||||
|
|
||||||
|
// baseHostString := fmt.Sprintf("%s://%s/%s", baseHost.Scheme, baseHost.Hostname, baseHost.Path)
|
||||||
|
|
||||||
var newPlaylist = ""
|
var newPlaylist = ""
|
||||||
|
|
||||||
scanner := bufio.NewScanner(strings.NewReader(playlist))
|
scanner := bufio.NewScanner(strings.NewReader(playlist))
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
if line[0:1] != "#" {
|
if line[0:1] != "#" {
|
||||||
line = path.Join(s.host, line)
|
urlComponents := baseHostComponents
|
||||||
|
urlComponents = append(urlComponents, line)
|
||||||
|
line = strings.Join(urlComponents, "") //path.Join(s.host, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
newPlaylist = newPlaylist + line + "\n"
|
newPlaylist = newPlaylist + line + "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
// fmt.Println(newPlaylist)
|
|
||||||
|
|
||||||
return newPlaylist
|
return newPlaylist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user