added a Stream struct with the meta data of a stream

This commit is contained in:
BroodjeAap 2020-07-06 20:02:05 +00:00
parent 1afed82777
commit 914210f644

27
main.go
View file

@ -20,6 +20,31 @@ type StreamURL struct {
URL string
}
// Stream Unexported
type Stream struct {
URL string
base64 string
streamDirPath string
previousInstantPath string
currentInstantPath string
nextInstantPath string
}
// NewStream Unexported
func NewStream(URL string) Stream {
base64 := URLToBase64(URL)
streamDirPath := filepath.Join(".", "streams", base64)
return Stream{
URL: URL,
base64: base64,
streamDirPath: streamDirPath,
// Maybe make these three functions ?
previousInstantPath: filepath.Join(streamDirPath, "previous.jpg"),
currentInstantPath: filepath.Join(streamDirPath, "current.jpg"),
nextInstantPath: filepath.Join(streamDirPath, "next.jpg"),
}
}
func index(w http.ResponseWriter, r *http.Request) {
if r.FormValue("URL") == "" {
indexTemplate, err := template.ParseFiles(filepath.Join("templates", "index.html"))
@ -145,7 +170,7 @@ func fileExists(path string) bool {
return !os.IsNotExist(err)
}
func URLToBase64(URL string) (hash string) {
func URLToBase64(URL string) string {
h := sha256.New()
h.Write([]byte(URL))
return base64.URLEncoding.EncodeToString(h.Sum(nil))