added a Stream struct with the meta data of a stream
This commit is contained in:
parent
1afed82777
commit
914210f644
1 changed files with 26 additions and 1 deletions
27
main.go
27
main.go
|
@ -20,6 +20,31 @@ type StreamURL struct {
|
||||||
URL string
|
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) {
|
func index(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.FormValue("URL") == "" {
|
if r.FormValue("URL") == "" {
|
||||||
indexTemplate, err := template.ParseFiles(filepath.Join("templates", "index.html"))
|
indexTemplate, err := template.ParseFiles(filepath.Join("templates", "index.html"))
|
||||||
|
@ -145,7 +170,7 @@ func fileExists(path string) bool {
|
||||||
return !os.IsNotExist(err)
|
return !os.IsNotExist(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func URLToBase64(URL string) (hash string) {
|
func URLToBase64(URL string) string {
|
||||||
h := sha256.New()
|
h := sha256.New()
|
||||||
h.Write([]byte(URL))
|
h.Write([]byte(URL))
|
||||||
return base64.URLEncoding.EncodeToString(h.Sum(nil))
|
return base64.URLEncoding.EncodeToString(h.Sum(nil))
|
||||||
|
|
Loading…
Add table
Reference in a new issue