Fix: Work around Discord screwing up image URLs

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-11-05 16:22:37 +01:00
parent f3d31a4242
commit 0c01506152
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D

View file

@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"encoding/base64"
"net/url" "net/url"
"strconv" "strconv"
"strings" "strings"
@ -274,7 +275,8 @@ func (m *modLivePosting) sendLivePost(username, displayName, title, game, previe
// @attr preserve_proxy optional string "" URL prefix of a Luzifer/preserve proxy to cache stream preview for longer // @attr preserve_proxy optional string "" URL prefix of a Luzifer/preserve proxy to cache stream preview for longer
if proxy, err := url.Parse(m.attrs.MustString("preserve_proxy", ptrStringEmpty)); err == nil && proxy.String() != "" { if proxy, err := url.Parse(m.attrs.MustString("preserve_proxy", ptrStringEmpty)); err == nil && proxy.String() != "" {
proxy.Path = "/" + previewImageURL.String() // Discord screws up the plain-text URL format, so we need to use the b64-format
proxy.Path = "/b64:" + base64.URLEncoding.EncodeToString([]byte(previewImageURL.String()))
previewImageURL = proxy previewImageURL = proxy
} }