From 914210f6448e36cdab5588ad41f93f3919b0e767 Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Mon, 6 Jul 2020 20:02:05 +0000 Subject: [PATCH] added a Stream struct with the meta data of a stream --- main.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index e5bdad5..fb93028 100755 --- a/main.go +++ b/main.go @@ -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))