Add apikey to streams (#2981)

This commit is contained in:
WithoutPants
2022-10-10 10:11:51 +11:00
committed by GitHub
parent 351dcb708b
commit 6c04f9199f
3 changed files with 36 additions and 15 deletions

View File

@@ -2,6 +2,7 @@ package urlbuilders
import (
"fmt"
"net/url"
"strconv"
"time"
)
@@ -19,12 +20,19 @@ func NewSceneURLBuilder(baseURL string, sceneID int) SceneURLBuilder {
}
}
func (b SceneURLBuilder) GetStreamURL() string {
var apiKeyParam string
if b.APIKey != "" {
apiKeyParam = fmt.Sprintf("?apikey=%s", b.APIKey)
func (b SceneURLBuilder) GetStreamURL() *url.URL {
u, err := url.Parse(fmt.Sprintf("%s/scene/%s/stream", b.BaseURL, b.SceneID))
if err != nil {
// shouldn't happen
panic(err)
}
return fmt.Sprintf("%s/scene/%s/stream%s", b.BaseURL, b.SceneID, apiKeyParam)
if b.APIKey != "" {
v := u.Query()
v.Set("apikey", b.APIKey)
u.RawQuery = v.Encode()
}
return u
}
func (b SceneURLBuilder) GetStreamPreviewURL() string {